libDAI
Public Types | Public Member Functions | Private Member Functions | Static Private Member Functions | Private Attributes | List of all members
dai::SharedParameters Class Reference

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 ProbcurrentExpectations () const
 Return the current accumulated expectations. More...
 
ParameterEstimationgetPEst () const
 
void setParameters (FactorGraph &fg)
 Estimate and set the shared parameters. More...
 
const FactorOrientationsgetFactorOrientations () 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...
 

Detailed Description

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.

Author
Charles Vaske

Member Typedef Documentation

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.

Constructor & Destructor Documentation

dai::SharedParameters::SharedParameters ( const FactorOrientations varorders,
ParameterEstimation estimation,
bool  ownPE = false 
)

Constructor.

Parameters
varordersall the factor orientations for this parameter
estimationa pointer to the parameter estimation method
ownPEwhether 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.

See also
Shared parameters block format
Exceptions
INVALID_EMALG_FILEif the input stream is not valid
dai::SharedParameters::SharedParameters ( const SharedParameters sp)
inline

Copy constructor.

dai::SharedParameters::~SharedParameters ( )
inline

Destructor.

Member Function Documentation

Permute dai::SharedParameters::calculatePermutation ( const std::vector< Var > &  varOrder,
VarSet outVS 
)
staticprivate

Calculates the permutation that permutes the canonical ordering into the desired ordering.

Parameters
varOrderDesired ordering of variables
outVSContains variables in varOrder represented as a VarSet
Returns
Permute object for permuting variables in varOrder from the canonical libDAI ordering into the desired ordering
void dai::SharedParameters::setPermsAndVarSetsFromVarOrders ( )
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.

const Prob& dai::SharedParameters::currentExpectations ( ) const
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).

const FactorOrientations& dai::SharedParameters::getFactorOrientations ( ) const
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.

void dai::SharedParameters::clear ( )
inline

Reset the current expectations.

Member Data Documentation

std::map<FactorIndex, VarSet> dai::SharedParameters::_varsets
private

Maps factor indices to the corresponding VarSets.

std::map<FactorIndex, Permute> dai::SharedParameters::_perms
private

Maps factor indices to the corresponding Permute objects that permute the canonical ordering into the desired ordering.

FactorOrientations dai::SharedParameters::_varorders
private

Maps factor indices to the corresponding desired variable orderings.

ParameterEstimation* dai::SharedParameters::_estimation
private

Parameter estimation method to be used.

bool dai::SharedParameters::_ownEstimation
private

Indicates whether *this gets ownership of _estimation.

Prob* dai::SharedParameters::_expectations
private

The accumulated expectations.


The documentation for this class was generated from the following files: