Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | File List | Namespace Members | Class Members | File Members

PLearn::RandomVariable Class Reference

#include <RandomVar.h>

Inheritance diagram for PLearn::RandomVariable:

Inheritance graph
[legend]
Collaboration diagram for PLearn::RandomVariable:

Collaboration graph
[legend]
List of all members.

Public Member Functions

 RandomVariable (int thelength, int thewidth=1)
 All these constructors give rise to a RV with no parents.

 RandomVariable (const Vec &the_value)
 RandomVariable (const Mat &the_value)
 RandomVariable (const Var &the_value)
 RandomVariable (const RVArray &parents, int thelength)
 these constructors give rise to a RV with parents

 RandomVariable (const RVArray &parents, int thelength, int thewidth)
virtual char * classname ()=0
virtual int length ()
virtual int width ()
int nelems ()
bool isScalar ()
bool isVec ()
bool isColumnVec ()
bool isRowVec ()
virtual bool isNonRandom ()=0
bool isConstant ()
 non-random is not the same thing as constant: (a Var is constant if it does not depend on other vars)

virtual bool isDiscrete ()=0
 true if a discrete random variable, false otherwise.

RandomVar subVec (int start, int length)
virtual void setValueFromParentsValue ()=0
void markRHSandSetKnownValues (const RVInstanceArray &RHS)
virtual void EMBprop (const Vec obs, real posterior)=0
virtual void EMUpdate ()
virtual bool canStopEM ()
virtual void EMTrainingInitialize (const RVArray &parameters_to_learn)
 Initialization of EM training (before all the iterations start).

virtual void EMEpochInitialize ()
 Initialization of an individual EMEpoch.

virtual void mark (Var v)
 !< ALL BELOW THIS IS NOT NECESSARY FOR ORDINARY USERS OR SUBCLASS WRITERS //!<

virtual void mark ()
virtual void unmark ()
virtual void clearEMmarks ()
virtual void unmarkAncestors ()
 clear not only the marked field but also that of parents

virtual bool isMarked ()
virtual void setKnownValues ()
virtual Var logP (const Var &obs, const RVInstanceArray &RHS, RVInstanceArray *parameters_to_learn=0)=0
virtual Var P (const Var &obs, const RVInstanceArray &RHS)
virtual Var ElogP (const Var &obs, RVArray &parameters_to_learn, const RVInstanceArray &RHS)
virtual real EM (const RVArray &parameters_to_learn, VarArray &prop_path, VarArray &observedVars, VMat distr, int n_samples, int max_n_iterations, real relative_improvement_threshold, bool accept_worsening_likelihood=false)
virtual real epoch (VarArray &prop_path, VarArray &observed_vars, const VMat &distr, int n_samples, bool do_EM_learning=true)
virtual ~RandomVariable ()

Public Attributes

const RVArray parents
 other random variables, whose value give rise

Var value
 used either when marked, non-random, or to assess P(This=value)


Protected Attributes

const int rv_number
 takes the value rv_counter upon construction

bool marked
bool EMmark
 mark used by EM to avoid repeated calls to EMBprop/EMUpdate

bool pmark
 yet another mark

boollearn_the_parameters
 learn_the_parameters[i] says if parent[i] should be learned in the current call to EM (as a parameter of the distribution).


Static Private Attributes

int rv_counter = 0
 RandomVariable *.


Constructor & Destructor Documentation

PLearn::RandomVariable::RandomVariable int  thelength,
int  thewidth = 1
 

All these constructors give rise to a RV with no parents.

Definition at line 184 of file RandomVar.cc.

PLearn::RandomVariable::RandomVariable const Vec the_value  ) 
 

Definition at line 190 of file RandomVar.cc.

References PLearn::Vec.

PLearn::RandomVariable::RandomVariable const Mat the_value  ) 
 

Definition at line 196 of file RandomVar.cc.

References PLearn::Mat.

PLearn::RandomVariable::RandomVariable const Var the_value  ) 
 

Definition at line 202 of file RandomVar.cc.

PLearn::RandomVariable::RandomVariable const RVArray parents,
int  thelength
 

these constructors give rise to a RV with parents

Definition at line 208 of file RandomVar.cc.

PLearn::RandomVariable::RandomVariable const RVArray parents,
int  thelength,
int  thewidth
 

Definition at line 215 of file RandomVar.cc.

PLearn::RandomVariable::~RandomVariable  )  [virtual]
 

Definition at line 396 of file RandomVar.cc.

References learn_the_parameters.


Member Function Documentation

bool PLearn::RandomVariable::canStopEM  )  [virtual]
 

Has the distribution seen enough EM iterations to meaningfully stop EM iterative training? This is a way for a RandomVariable sub-class to force continuation of the EM iterations beyond the criteria given by the caller of EM. the default just propagates to the unmarked parents.

Reimplemented in PLearn::MixtureRandomVariable.

Definition at line 348 of file RandomVar.cc.

References parents, and PLearn::TVec< RandomVar >::size().

Referenced by EM().

virtual char* PLearn::RandomVariable::classname  )  [pure virtual]
 

Implemented in PLearn::NonRandomVariable, PLearn::JointRandomVariable, PLearn::RandomElementOfRandomVariable, PLearn::RVArrayRandomElementRandomVariable, PLearn::NegRandomVariable, PLearn::ExpRandomVariable, PLearn::LogRandomVariable, PLearn::DiagonalNormalRandomVariable, PLearn::MixtureRandomVariable, PLearn::PlusRandomVariable, PLearn::MinusRandomVariable, PLearn::ElementWiseDivisionRandomVariable, PLearn::ProductRandomVariable, PLearn::SubVecRandomVariable, PLearn::MultinomialRandomVariable, PLearn::ExtendedRandomVariable, and PLearn::ConcatColumnsRandomVariable.

Referenced by ElogP().

void PLearn::RandomVariable::clearEMmarks  )  [virtual]
 

Reimplemented in PLearn::MixtureRandomVariable.

Definition at line 313 of file RandomVar.cc.

References EMmark, parents, and PLearn::TVec< RandomVar >::size().

Referenced by EM(), and epoch().

Var PLearn::RandomVariable::ElogP const Var obs,
RVArray parameters_to_learn,
const RVInstanceArray RHS
[virtual]
 

the latter is like logP but it represents the expected log-probability of obs given the RHS, where the expectation is over the "hidden" random variables of EM in mixtures, as a function of the values of the parameters_to_learn.

Definition at line 399 of file RandomVar.cc.

References classname(), and PLERROR.

real PLearn::RandomVariable::EM const RVArray parameters_to_learn,
VarArray prop_path,
VarArray observedVars,
VMat  distr,
int  n_samples,
int  max_n_iterations,
real  relative_improvement_threshold,
bool  accept_worsening_likelihood = false
[virtual]
 

NOTE NOTE NOTE:

THE ORDER OF THE VALUES IN THE DISTRIBUTION MUST BE: (1) conditioning variables (RHS), (2) output variables

Definition at line 229 of file RandomVar.cc.

References canStopEM(), clearEMmarks(), EMTrainingInitialize(), PLearn::endl(), and epoch().

virtual void PLearn::RandomVariable::EMBprop const Vec  obs,
real  posterior
[pure virtual]
 

************ EM STUFF ********** propagate posterior information to parents in order to perform an EMupdate at the end of an EMEpoch. In the case of mixture-like RVs and their components, the posterior is the probability of the component "this" given the observation "obs".

Implemented in PLearn::NonRandomVariable, PLearn::JointRandomVariable, PLearn::RandomElementOfRandomVariable, PLearn::RVArrayRandomElementRandomVariable, PLearn::NegRandomVariable, PLearn::ExpRandomVariable, PLearn::LogRandomVariable, PLearn::DiagonalNormalRandomVariable, PLearn::MixtureRandomVariable, PLearn::PlusRandomVariable, PLearn::MinusRandomVariable, PLearn::ElementWiseDivisionRandomVariable, PLearn::ProductRandomVariable, PLearn::SubVecRandomVariable, PLearn::MultinomialRandomVariable, PLearn::ExtendedRandomVariable, and PLearn::ConcatColumnsRandomVariable.

Referenced by epoch().

void PLearn::RandomVariable::EMEpochInitialize  )  [virtual]
 

Initialization of an individual EMEpoch.

the default just propagates to the unmarked parents

Reimplemented in PLearn::DiagonalNormalRandomVariable, PLearn::MixtureRandomVariable, PLearn::PlusRandomVariable, PLearn::MinusRandomVariable, PLearn::ElementWiseDivisionRandomVariable, PLearn::ProductRandomVariable, and PLearn::MultinomialRandomVariable.

Definition at line 384 of file RandomVar.cc.

References EMmark, parents, and PLearn::TVec< RandomVar >::size().

Referenced by epoch().

void PLearn::RandomVariable::EMTrainingInitialize const RVArray parameters_to_learn  )  [virtual]
 

Initialization of EM training (before all the iterations start).

the default just propagates to the unmarked parents

Reimplemented in PLearn::MixtureRandomVariable, PLearn::PlusRandomVariable, PLearn::MinusRandomVariable, PLearn::ElementWiseDivisionRandomVariable, and PLearn::ProductRandomVariable.

Definition at line 358 of file RandomVar.cc.

References PLearn::TVec< RandomVar >::contains(), EMmark, learn_the_parameters, parents, PLERROR, and PLearn::TVec< RandomVar >::size().

Referenced by EM().

void PLearn::RandomVariable::EMUpdate  )  [virtual]
 

update the fixed (non-random) parameters using internal learning mechanism, at end of an EMEpoch. the default just propagates to the unmarked parents.

Reimplemented in PLearn::DiagonalNormalRandomVariable, PLearn::MixtureRandomVariable, PLearn::PlusRandomVariable, PLearn::MinusRandomVariable, PLearn::ElementWiseDivisionRandomVariable, PLearn::ProductRandomVariable, and PLearn::MultinomialRandomVariable.

Definition at line 340 of file RandomVar.cc.

References EMmark, parents, and PLearn::TVec< RandomVar >::size().

Referenced by epoch().

real PLearn::RandomVariable::epoch VarArray prop_path,
VarArray observed_vars,
const VMat distr,
int  n_samples,
bool  do_EM_learning = true
[virtual]
 

Do one iteration of EM or compute the likelihood of the given data. This method should not be redefined for most types of random variables, but it may be necessary for things like sequential data. This method can be used for doing one epoch of EM (do_EM_learning=true) or simply for computing the likelihood, if do_EM_learning=false.

Definition at line 260 of file RandomVar.cc.

References clearEMmarks(), EMBprop(), EMEpochInitialize(), EMUpdate(), PLearn::endl(), PLearn::VarArray::fprop(), PLearn::TVec< Var >::last(), PLearn::VarArray::printInfo(), and PLearn::VMat::width().

Referenced by EM().

bool PLearn::RandomVariable::isColumnVec  )  [inline]
 

Definition at line 600 of file RandomVar.h.

References width().

bool PLearn::RandomVariable::isConstant  )  [inline]
 

non-random is not the same thing as constant: (a Var is constant if it does not depend on other vars)

Definition at line 612 of file RandomVar.h.

References isNonRandom(), and value.

virtual bool PLearn::RandomVariable::isDiscrete  )  [pure virtual]
 

true if a discrete random variable, false otherwise.

Most of the RVs of interest here are continuous, so this is the default.

Implemented in PLearn::StochasticRandomVariable, PLearn::FunctionalRandomVariable, PLearn::MixtureRandomVariable, and PLearn::MultinomialRandomVariable.

virtual bool PLearn::RandomVariable::isMarked  )  [inline, virtual]
 

Definition at line 690 of file RandomVar.h.

References marked.

virtual bool PLearn::RandomVariable::isNonRandom  )  [pure virtual]
 

Random means that its value cannot be known deterministically. Note that StochasticRandomVariable's are never non-random, but a FunctionalRandomVariable is non-random if it has no parents (i.e. it is a NonRandomVariable) or if all its parents are non-random.

Implemented in PLearn::StochasticRandomVariable, and PLearn::FunctionalRandomVariable.

Referenced by isConstant().

bool PLearn::RandomVariable::isRowVec  )  [inline]
 

Definition at line 601 of file RandomVar.h.

References length().

bool PLearn::RandomVariable::isScalar  )  [inline]
 

Definition at line 598 of file RandomVar.h.

References length(), and width().

bool PLearn::RandomVariable::isVec  )  [inline]
 

Definition at line 599 of file RandomVar.h.

References length(), and width().

virtual int PLearn::RandomVariable::length  )  [inline, virtual]
 

Definition at line 595 of file RandomVar.h.

References PLearn::Var::length(), and value.

Referenced by PLearn::SubVecRandomVariable::EMBprop(), PLearn::DiagonalNormalRandomVariable::EMBprop(), PLearn::SubVecRandomVariable::invertible(), isRowVec(), isScalar(), isVec(), PLearn::FunctionalRandomVariable::logP(), and PLearn::RVArrayRandomElementRandomVariable::RVArrayRandomElementRandomVariable().

virtual Var PLearn::RandomVariable::logP const Var obs,
const RVInstanceArray RHS,
RVInstanceArray parameters_to_learn = 0
[pure virtual]
 

Construct a Var that computes logP(This = obs | RHS ). This function SHOULD NOT be used directly, but is called by the global function logP (same argument), which does proper massaging of the network before and after this call.

Implemented in PLearn::FunctionalRandomVariable, PLearn::RVArrayRandomElementRandomVariable, PLearn::DiagonalNormalRandomVariable, PLearn::MixtureRandomVariable, and PLearn::MultinomialRandomVariable.

virtual void PLearn::RandomVariable::mark  )  [inline, virtual]
 

Definition at line 683 of file RandomVar.h.

References marked.

virtual void PLearn::RandomVariable::mark Var  v  )  [inline, virtual]
 

!< ALL BELOW THIS IS NOT NECESSARY FOR ORDINARY USERS OR SUBCLASS WRITERS //!<

Definition at line 682 of file RandomVar.h.

References marked, and value.

void PLearn::RandomVariable::markRHSandSetKnownValues const RVInstanceArray RHS  )  [inline]
 

Definition at line 640 of file RandomVar.h.

References markRHSandSetKnownValues(), setKnownValues(), and PLearn::TVec< RVInstance >::size().

Referenced by markRHSandSetKnownValues().

int PLearn::RandomVariable::nelems  )  [inline]
 

Definition at line 597 of file RandomVar.h.

References value.

Var PLearn::RandomVariable::P const Var obs,
const RVInstanceArray RHS
[virtual]
 

Definition at line 392 of file RandomVar.cc.

References PLearn::exp(), and PLearn::logP().

void PLearn::RandomVariable::setKnownValues  )  [virtual]
 

traverse the graph of ancestors of this node and mark nodes which are deterministic descendents of marked nodes while setting their "value" field as a function of their parents.

Reimplemented in PLearn::StochasticRandomVariable, and PLearn::MixtureRandomVariable.

Definition at line 323 of file RandomVar.cc.

References marked, parents, pmark, setValueFromParentsValue(), and PLearn::TVec< RandomVar >::size().

Referenced by markRHSandSetKnownValues().

virtual void PLearn::RandomVariable::setValueFromParentsValue  )  [pure virtual]
 

define the formula that gives a value to this RV given its parent's value (sets the value field). If the RV is stochastic, the formula may also be "stochastic" (using SampleVariable's to define the Var).

Implemented in PLearn::FunctionalRandomVariable, PLearn::NonRandomVariable, PLearn::JointRandomVariable, PLearn::RandomElementOfRandomVariable, PLearn::RVArrayRandomElementRandomVariable, PLearn::NegRandomVariable, PLearn::ExpRandomVariable, PLearn::LogRandomVariable, PLearn::DiagonalNormalRandomVariable, PLearn::MixtureRandomVariable, PLearn::PlusRandomVariable, PLearn::MinusRandomVariable, PLearn::ElementWiseDivisionRandomVariable, PLearn::ProductRandomVariable, PLearn::SubVecRandomVariable, PLearn::MultinomialRandomVariable, PLearn::ExtendedRandomVariable, and PLearn::ConcatColumnsRandomVariable.

Referenced by PLearn::StochasticRandomVariable::setKnownValues(), and setKnownValues().

RandomVar PLearn::RandomVariable::subVec int  start,
int  length
 

Return a new RandomVar which is obtained by extracting a sub-vector of length "length" from the value of this, starting at position "start".

Definition at line 225 of file RandomVar.cc.

virtual void PLearn::RandomVariable::unmark  )  [inline, virtual]
 

Definition at line 684 of file RandomVar.h.

References marked.

void PLearn::RandomVariable::unmarkAncestors  )  [virtual]
 

clear not only the marked field but also that of parents

Reimplemented in PLearn::MixtureRandomVariable.

Definition at line 302 of file RandomVar.cc.

References marked, parents, pmark, and PLearn::TVec< RandomVar >::size().

virtual int PLearn::RandomVariable::width  )  [inline, virtual]
 

Definition at line 596 of file RandomVar.h.

References value, and PLearn::Var::width().

Referenced by isColumnVec(), isScalar(), and isVec().


Member Data Documentation

bool PLearn::RandomVariable::EMmark [protected]
 

mark used by EM to avoid repeated calls to EMBprop/EMUpdate

Definition at line 576 of file RandomVar.h.

Referenced by clearEMmarks(), EMEpochInitialize(), EMTrainingInitialize(), and EMUpdate().

bool* PLearn::RandomVariable::learn_the_parameters [protected]
 

learn_the_parameters[i] says if parent[i] should be learned in the current call to EM (as a parameter of the distribution).

Definition at line 581 of file RandomVar.h.

Referenced by EMTrainingInitialize(), and ~RandomVariable().

bool PLearn::RandomVariable::marked [protected]
 

temporary used in various procedures that traverse the graphical model. For example, for logP it means "conditionally non-random".

Definition at line 574 of file RandomVar.h.

Referenced by isMarked(), mark(), setKnownValues(), unmark(), and unmarkAncestors().

const RVArray PLearn::RandomVariable::parents
 

other random variables, whose value give rise

Definition at line 561 of file RandomVar.h.

Referenced by canStopEM(), clearEMmarks(), EMEpochInitialize(), EMTrainingInitialize(), EMUpdate(), setKnownValues(), and unmarkAncestors().

bool PLearn::RandomVariable::pmark [protected]
 

yet another mark

Definition at line 577 of file RandomVar.h.

Referenced by setKnownValues(), and unmarkAncestors().

int PLearn::RandomVariable::rv_counter = 0 [static, private]
 

RandomVariable *.

Definition at line 182 of file RandomVar.cc.

const int PLearn::RandomVariable::rv_number [protected]
 

takes the value rv_counter upon construction

Definition at line 558 of file RandomVar.h.

Var PLearn::RandomVariable::value
 

used either when marked, non-random, or to assess P(This=value)

stochastically or deterministically to this value. This field basically defines the NETWORK of the model. Note that this oriented graphical model must not have cycles.

Definition at line 567 of file RandomVar.h.

Referenced by isConstant(), length(), mark(), nelems(), and width().


The documentation for this class was generated from the following files:
Generated on Tue Aug 17 16:24:19 2004 for PLearn by doxygen 1.3.7