libDAI
|
Represents a single factor or set of factors whose parameters should be estimated. More...
#include <dai/emalg.h>
Public Types | |
typedef size_t | FactorIndex |
Convenience label for an index of a factor in a FactorGraph. More... | |
typedef std::map< FactorIndex, std::vector< Var > > | FactorOrientations |
Convenience label for a grouping of factor orientations. More... | |
Public Member Functions | |
SharedParameters (const FactorOrientations &varorders, ParameterEstimation *estimation, bool ownPE=false) | |
Constructor. More... | |
SharedParameters (std::istream &is, const FactorGraph &fg) | |
Construct a SharedParameters object from an input stream is and a factor graph fg. More... | |
SharedParameters (const SharedParameters &sp) | |
Copy constructor. More... | |
~SharedParameters () | |
Destructor. More... | |
void | collectExpectations (InfAlg &alg) |
Collect the expected values (beliefs) according to alg. More... | |
const Prob & | currentExpectations () const |
Return the current accumulated expectations. More... | |
ParameterEstimation & | getPEst () const |
void | setParameters (FactorGraph &fg) |
Estimate and set the shared parameters. More... | |
const FactorOrientations & | getFactorOrientations () const |
Return a reference to the vector of factor orientations. More... | |
void | clear () |
Reset the current expectations. More... | |
Private Member Functions | |
void | setPermsAndVarSetsFromVarOrders () |
Initializes _varsets and _perms from _varorders and checks whether their state spaces correspond with _estimation.probSize() More... | |
Static Private Member Functions | |
static Permute | calculatePermutation (const std::vector< Var > &varOrder, VarSet &outVS) |
Calculates the permutation that permutes the canonical ordering into the desired ordering. More... | |
Private Attributes | |
std::map< FactorIndex, VarSet > | _varsets |
Maps factor indices to the corresponding VarSets. More... | |
std::map< FactorIndex, Permute > | _perms |
Maps factor indices to the corresponding Permute objects that permute the canonical ordering into the desired ordering. More... | |
FactorOrientations | _varorders |
Maps factor indices to the corresponding desired variable orderings. More... | |
ParameterEstimation * | _estimation |
Parameter estimation method to be used. More... | |
bool | _ownEstimation |
Indicates whether *this gets ownership of _estimation. More... | |
Prob * | _expectations |
The accumulated expectations. More... | |
Represents a single factor or set of factors whose parameters should be estimated.
To ensure that parameters can be shared between different factors during EM learning, each factor's values are reordered to match a desired variable ordering. The ordering of the variables in a factor may therefore differ from the canonical ordering used in libDAI. The SharedParameters class combines one or more factors (together with the specified orderings of the variables) with a ParameterEstimation object, taking care of the necessary permutations of the factor entries / parameters.
typedef size_t dai::SharedParameters::FactorIndex |
Convenience label for an index of a factor in a FactorGraph.
typedef std::map<FactorIndex, std::vector<Var> > dai::SharedParameters::FactorOrientations |
Convenience label for a grouping of factor orientations.
dai::SharedParameters::SharedParameters | ( | const FactorOrientations & | varorders, |
ParameterEstimation * | estimation, | ||
bool | ownPE = false |
||
) |
Constructor.
varorders | all the factor orientations for this parameter |
estimation | a pointer to the parameter estimation method |
ownPE | whether the constructed object gets ownership of estimation |
dai::SharedParameters::SharedParameters | ( | std::istream & | is, |
const FactorGraph & | fg | ||
) |
Construct a SharedParameters object from an input stream is and a factor graph fg.
INVALID_EMALG_FILE | if the input stream is not valid |
|
inline |
Copy constructor.
|
inline |
Destructor.
|
staticprivate |
Calculates the permutation that permutes the canonical ordering into the desired ordering.
varOrder | Desired ordering of variables |
outVS | Contains variables in varOrder represented as a VarSet |
|
private |
Initializes _varsets and _perms from _varorders and checks whether their state spaces correspond with _estimation.probSize()
void dai::SharedParameters::collectExpectations | ( | InfAlg & | alg | ) |
Collect the expected values (beliefs) according to alg.
For each of the relevant factors (that shares the parameters we are interested in), the corresponding belief according to alg is obtained and its entries are permuted such that their ordering corresponds with the shared parameters that we are estimating.
|
inline |
Return the current accumulated expectations.
void dai::SharedParameters::setParameters | ( | FactorGraph & | fg | ) |
Estimate and set the shared parameters.
Based on the expectation statistics collected so far, the shared parameters are estimated using the parameter estimation subclass method estimate(). Then, each of the relevant factors in fg (that shares the parameters we are interested in) is set according to those parameters (permuting the parameters accordingly).
|
inline |
Return a reference to the vector of factor orientations.
This is necessary for determing which variables were used to estimate parameters, and analysis of expectations after an Estimation step has been performed.
|
inline |
Reset the current expectations.
|
private |
Maps factor indices to the corresponding VarSets.
|
private |
Maps factor indices to the corresponding Permute objects that permute the canonical ordering into the desired ordering.
|
private |
Maps factor indices to the corresponding desired variable orderings.
|
private |
Parameter estimation method to be used.
|
private |
Indicates whether *this
gets ownership of _estimation.
|
private |
The accumulated expectations.