libDAI
|
EMAlg performs Expectation Maximization to learn factor parameters. More...
#include <dai/emalg.h>
Public Member Functions | |
EMAlg (const Evidence &evidence, InfAlg &estep, std::vector< MaximizationStep > &msteps, const PropertySet &termconditions) | |
Construct an EMAlg from several objects. More... | |
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. More... | |
void | setTermConditions (const PropertySet &p) |
Change the conditions for termination. More... | |
bool | hasSatisfiedTermConditions () const |
Determine if the termination conditions have been met. More... | |
Real | logZ () const |
Return the last calculated log likelihood. More... | |
size_t | Iterations () const |
Returns number of iterations done so far. More... | |
const InfAlg & | eStep () const |
Get the E-step method used. More... | |
Real | iterate () |
Iterate once over all maximization steps. More... | |
Real | iterate (MaximizationStep &mstep) |
Iterate over a single MaximizationStep. More... | |
void | run () |
Iterate until termination conditions are satisfied. More... | |
Static Public Attributes | |
static const std::string | MAX_ITERS_KEY |
Key for setting maximum iterations. More... | |
static const size_t | MAX_ITERS_DEFAULT = 30 |
Default maximum iterations. More... | |
static const std::string | LOG_Z_TOL_KEY |
Key for setting likelihood termination condition. More... | |
static const Real | LOG_Z_TOL_DEFAULT = 0.01 |
Default likelihood tolerance. More... | |
Private Attributes | |
const Evidence & | _evidence |
All the data samples used during learning. More... | |
InfAlg & | _estep |
How to do the expectation step. More... | |
std::vector< MaximizationStep > | _msteps |
The maximization steps to take. More... | |
size_t | _iters |
Number of iterations done. More... | |
std::vector< Real > | _lastLogZ |
History of likelihoods. More... | |
size_t | _max_iters |
Maximum number of iterations. More... | |
Real | _log_z_tol |
Convergence tolerance. More... | |
Iterator interface | |
typedef std::vector< MaximizationStep >::iterator | s_iterator |
Iterator over the maximization steps. More... | |
typedef std::vector< MaximizationStep >::const_iterator | const_s_iterator |
Constant iterator over the maximization steps. More... | |
s_iterator | s_begin () |
Returns iterator that points to the first maximization step. More... | |
const_s_iterator | s_begin () const |
Returns constant iterator that points to the first maximization step. More... | |
s_iterator | s_end () |
Returns iterator that points beyond the last maximization step. More... | |
const_s_iterator | s_end () const |
Returns constant iterator that points beyond the last maximization step. More... | |
EMAlg performs Expectation Maximization to learn factor parameters.
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.
|
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:
|
inline |
Return the last calculated log likelihood.
|
inline |
Returns number of iterations done so far.
|
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.
|
inline |
Returns iterator that points to the first maximization step.
|
inline |
Returns constant iterator that points to the first maximization step.
|
inline |
Returns iterator that points beyond the last maximization step.
|
inline |
Returns constant iterator that points beyond the last maximization step.
|
private |
All the data samples used during learning.
|
private |
How to do the expectation step.
|
private |
The maximization steps to take.
|
private |
Number of iterations done.
|
private |
History of likelihoods.
|
private |
Maximum number of iterations.
|
private |
Convergence tolerance.
|
static |
Key for setting maximum iterations.
|
static |
Default maximum iterations.
|
static |
Key for setting likelihood termination condition.
|
static |
Default likelihood tolerance.