#include <dai/emalg.h>
Iterator interface | |
typedef std::vector < MaximizationStep >::iterator | s_iterator |
Iterator over the maximization steps. | |
typedef std::vector < MaximizationStep > ::const_iterator | const_s_iterator |
Constant iterator over the maximization steps. | |
s_iterator | s_begin () |
Returns iterator that points to the first maximization step. | |
const_s_iterator | s_begin () const |
Returns constant iterator that points to the first maximization step. | |
s_iterator | s_end () |
Returns iterator that points beyond the last maximization step. | |
const_s_iterator | s_end () const |
Returns constant iterator that points beyond the last maximization step. | |
Public Member Functions | |
EMAlg (const Evidence &evidence, InfAlg &estep, std::vector< MaximizationStep > &msteps, const PropertySet &termconditions) | |
Construct an EMAlg from several objects. | |
EMAlg (const Evidence &evidence, InfAlg &estep, std::istream &mstep_file) | |
Construct an EMAlg from Evidence evidence, an InfAlg estep, and an input stream mstep_file. | |
void | setTermConditions (const PropertySet &p) |
Change the conditions for termination. | |
bool | hasSatisfiedTermConditions () const |
Determine if the termination conditions have been met. | |
Real | logZ () const |
Return the last calculated log likelihood. | |
size_t | Iterations () const |
Returns number of iterations done so far. | |
const InfAlg & | eStep () const |
Get the E-step method used. | |
Real | iterate () |
Iterate once over all maximization steps. | |
Real | iterate (MaximizationStep &mstep) |
Iterate over a single MaximizationStep. | |
void | run () |
Iterate until termination conditions are satisfied. | |
Static Public Attributes | |
static const std::string | MAX_ITERS_KEY |
Key for setting maximum iterations. | |
static const size_t | MAX_ITERS_DEFAULT = 30 |
Default maximum iterations. | |
static const std::string | LOG_Z_TOL_KEY |
Key for setting likelihood termination condition. | |
static const Real | LOG_Z_TOL_DEFAULT = 0.01 |
Default likelihood tolerance. | |
Private Attributes | |
const Evidence & | _evidence |
All the data samples used during learning. | |
InfAlg & | _estep |
How to do the expectation step. | |
std::vector< MaximizationStep > | _msteps |
The maximization steps to take. | |
size_t | _iters |
Number of iterations done. | |
std::vector< Real > | _lastLogZ |
History of likelihoods. | |
size_t | _max_iters |
Maximum number of iterations. | |
Real | _log_z_tol |
Convergence tolerance. |
This requires specifying:
This implementation can perform incremental EM by using multiple MaximizationSteps. An expectation step is performed between execution of each MaximizationStep. A call to iterate() will cycle through all MaximizationStep 's. A call to run() will call iterate() until the termination criteria have been met.
Having multiple and separate maximization steps allows for maximizing some parameters, performing another E-step, and then maximizing separate parameters, which may result in faster convergence in some cases.
typedef std::vector<MaximizationStep>::iterator dai::EMAlg::s_iterator |
Iterator over the maximization steps.
typedef std::vector<MaximizationStep>::const_iterator dai::EMAlg::const_s_iterator |
Constant iterator over the maximization steps.
dai::EMAlg::EMAlg | ( | const Evidence & | evidence, | |
InfAlg & | estep, | |||
std::vector< MaximizationStep > & | msteps, | |||
const PropertySet & | termconditions | |||
) | [inline] |
Construct an EMAlg from several objects.
evidence | Specifies the observed evidence | |
estep | Inference algorithm to be used for the E-step | |
msteps | Vector of maximization steps, each of which is a group of parameter estimation tasks | |
termconditions | Termination conditions |
void dai::EMAlg::setTermConditions | ( | const PropertySet & | p | ) |
Change the conditions for termination.
There are two possible parameters in the PropertySet p:
bool dai::EMAlg::hasSatisfiedTermConditions | ( | ) | const |
Determine if the termination conditions have been met.
There are two sufficient termination conditions:
Real dai::EMAlg::logZ | ( | ) | const [inline] |
Return the last calculated log likelihood.
size_t dai::EMAlg::Iterations | ( | ) | const [inline] |
const InfAlg& dai::EMAlg::eStep | ( | ) | const [inline] |
Get the E-step method used.
Real dai::EMAlg::iterate | ( | ) |
Iterate once over all maximization steps.
Real dai::EMAlg::iterate | ( | MaximizationStep & | mstep | ) |
Iterate over a single MaximizationStep.
void dai::EMAlg::run | ( | ) |
Iterate until termination conditions are satisfied.
s_iterator dai::EMAlg::s_begin | ( | ) | [inline] |
Returns iterator that points to the first maximization step.
const_s_iterator dai::EMAlg::s_begin | ( | ) | const [inline] |
Returns constant iterator that points to the first maximization step.
s_iterator dai::EMAlg::s_end | ( | ) | [inline] |
Returns iterator that points beyond the last maximization step.
const_s_iterator dai::EMAlg::s_end | ( | ) | const [inline] |
Returns constant iterator that points beyond the last maximization step.
const Evidence& dai::EMAlg::_evidence [private] |
All the data samples used during learning.
InfAlg& dai::EMAlg::_estep [private] |
How to do the expectation step.
std::vector<MaximizationStep> dai::EMAlg::_msteps [private] |
The maximization steps to take.
size_t dai::EMAlg::_iters [private] |
Number of iterations done.
std::vector<Real> dai::EMAlg::_lastLogZ [private] |
History of likelihoods.
size_t dai::EMAlg::_max_iters [private] |
Maximum number of iterations.
Real dai::EMAlg::_log_z_tol [private] |
Convergence tolerance.
const std::string dai::EMAlg::MAX_ITERS_KEY [static] |
Key for setting maximum iterations.
const size_t dai::EMAlg::MAX_ITERS_DEFAULT = 30 [static] |
Default maximum iterations.
const std::string dai::EMAlg::LOG_Z_TOL_KEY [static] |
Key for setting likelihood termination condition.
const Real dai::EMAlg::LOG_Z_TOL_DEFAULT = 0.01 [static] |
Default likelihood tolerance.