PLearn 0.1
|
#include <RandomVar.h>
Public Member Functions | |
FunctionalRandomVariable (int length) | |
FunctionalRandomVariable. | |
FunctionalRandomVariable (int length, int width) | |
FunctionalRandomVariable (const Vec &the_value) | |
FunctionalRandomVariable (const Mat &the_value) | |
FunctionalRandomVariable (const Var &the_value) | |
FunctionalRandomVariable (const RVArray &parents, int length) | |
FunctionalRandomVariable (const RVArray &parents, int length, int width) | |
virtual Var | logP (const Var &obs, const RVInstanceArray &RHS, RVInstanceArray *parameters_to_learn) |
redefine RandomVariable functions | |
bool | isNonRandom () |
a Functional RV may be non-random if all its ancestors are non-random | |
virtual bool | isDiscrete () |
default is that the RV is discrete if all its parents are discrete | |
virtual bool | invertible (const Var &obs, RVInstanceArray &unobserved_parents, Var **JacobianCorrection) |
functions specific to FunctionalRandomVariable's | |
virtual void | setValueFromParentsValue ()=0 |
set the field value from the values of the parents |
A FunctionalRandomVariable represents a RV that is a deterministic function of other RVs, e.g., the sum, mixture, product, exponential, etc... of parent RVs.
Definition at line 1006 of file RandomVar.h.
PLearn::FunctionalRandomVariable::FunctionalRandomVariable | ( | int | length | ) |
Definition at line 976 of file RandomVar.cc.
:RandomVariable(thelength) {}
Definition at line 978 of file RandomVar.cc.
:RandomVariable(thelength,thewidth) {}
PLearn::FunctionalRandomVariable::FunctionalRandomVariable | ( | const Vec & | the_value | ) |
Definition at line 980 of file RandomVar.cc.
:RandomVariable(the_value) {}
PLearn::FunctionalRandomVariable::FunctionalRandomVariable | ( | const Mat & | the_value | ) |
Definition at line 982 of file RandomVar.cc.
:RandomVariable(the_value) {}
PLearn::FunctionalRandomVariable::FunctionalRandomVariable | ( | const Var & | the_value | ) |
Definition at line 984 of file RandomVar.cc.
:RandomVariable(the_value) {}
Definition at line 988 of file RandomVar.cc.
:RandomVariable(the_parents,length) {}
PLearn::FunctionalRandomVariable::FunctionalRandomVariable | ( | const RVArray & | parents, |
int | length, | ||
int | width | ||
) |
Definition at line 992 of file RandomVar.cc.
:RandomVariable(the_parents,length,width) {}
bool PLearn::FunctionalRandomVariable::invertible | ( | const Var & | obs, |
RVInstanceArray & | unobserved_parents, | ||
Var ** | JacobianCorrection | ||
) | [virtual] |
functions specific to FunctionalRandomVariable's
!< SUBCLASS WRITERS: IMPLEMENT FUNCTIONS BELOW //!<
check whether it is possible to invert the function which maps the given unobserved parents to the observed value of the RV (obs). If invertible, do the inversion, and set the value fields of the RVInstances to Var's which are functionally dependent on obs. If the absolute value of the Jacobian of the map from the unobserved parents to this R.V.'s value is different from 1, then JacobianCorrection should point to a Var that is the logarithm of the determinant of this Jacobian (first derivatives) matrix. If the function is not invertible but it is possible to write P(Y==obs | unobserved_parents) in terms of the unobserved_parents logP functions, then the sub-class writer should instead redefine the logP function appropriately.
Reimplemented in PLearn::NonRandomVariable, PLearn::JointRandomVariable, PLearn::RandomElementOfRandomVariable, PLearn::NegRandomVariable, PLearn::ExpRandomVariable, PLearn::LogRandomVariable, PLearn::PlusRandomVariable, PLearn::MinusRandomVariable, PLearn::ElementWiseDivisionRandomVariable, PLearn::ProductRandomVariable, PLearn::SubVecRandomVariable, PLearn::ExtendedRandomVariable, and PLearn::ConcatColumnsRandomVariable.
Definition at line 1051 of file RandomVar.cc.
References PLERROR.
Referenced by logP().
{ PLERROR("FunctionalRandomVariable::invertible() should not be called\n" "Either the sub-class should re-implement logP() or re-define\n" "invertible() appropriately."); return false; }
bool PLearn::FunctionalRandomVariable::isDiscrete | ( | ) | [virtual] |
default is that the RV is discrete if all its parents are discrete
Implements PLearn::RandomVariable.
Definition at line 1074 of file RandomVar.cc.
References PLearn::RandomVariable::parents, and PLearn::TVec< T >::size().
Referenced by logP().
{ bool all_discrete = true; for (int i=0;i<parents.size() && all_discrete;i++) all_discrete = parents[i]->isDiscrete(); return all_discrete; }
bool PLearn::FunctionalRandomVariable::isNonRandom | ( | ) | [virtual] |
a Functional RV may be non-random if all its ancestors are non-random
Implements PLearn::RandomVariable.
Definition at line 1066 of file RandomVar.cc.
References PLearn::RandomVariable::parents, and PLearn::TVec< T >::size().
Referenced by PLearn::ProductRandomVariable::EMBprop(), PLearn::ProductRandomVariable::EMTrainingInitialize(), PLearn::RVArrayRandomElementRandomVariable::logP(), and logP().
{ bool non_random=true; for (int i=0;i<parents.size() && non_random;i++) non_random = parents[i]->isNonRandom(); return non_random; }
Var PLearn::FunctionalRandomVariable::logP | ( | const Var & | obs, |
const RVInstanceArray & | RHS, | ||
RVInstanceArray * | parameters_to_learn | ||
) | [virtual] |
redefine RandomVariable functions
Implements PLearn::RandomVariable.
Reimplemented in PLearn::RVArrayRandomElementRandomVariable.
Definition at line 996 of file RandomVar.cc.
References i, invertible(), isDiscrete(), PLearn::isequal(), PLearn::RandomVariable::isMarked(), isNonRandom(), PLearn::RandomVariable::length(), PLearn::marginalize(), PLearn::RandomVariable::parents, PLearn::RVInstanceArray::random_variables(), PLearn::TVec< T >::size(), PLearn::RVInstanceArray::sort(), and PLearn::RandomVariable::value.
{ // gather the unobserved parents int np=parents.size(); RVInstanceArray unobserved_parents(0,np); for (int i=0;i<np;i++) if (!(parents[i]->isMarked() || parents[i]->isNonRandom())) unobserved_parents &= RVInstance(parents[i],Var(parents[i]->length())); // simplest case first int nup = unobserved_parents.size(); if (nup==0) { if (isDiscrete()) return isequal(value,obs); // else return isequal(value,obs)*FLT_MAX; } // else Var *JacobianCorrection=0; if (invertible(obs,unobserved_parents,&JacobianCorrection)) { Var logp(1); // sort the unobserved parents in topological order of graph unobserved_parents.sort(); bool first = true; RVInstanceArray RHS(0,RHS.size()+unobserved_parents.size()); RVInstanceArray xRHS(RHS); for (int i=0;i<nup;i++) { // note these are still symbolic computations to build Var logp if (first) logp = unobserved_parents[i].V->logP(unobserved_parents[i].v,xRHS, parameters_to_learn); else logp = logp + unobserved_parents[i].V->logP(unobserved_parents[i].v,xRHS, parameters_to_learn); first = false; // add the visited parents to the RHS, e.g. to compute // P(P1=p1,P2=p2,P3=p3) = P(P1=p1)*P(P2=p2|P1=p1)*P(P3=p3|P2=p2,P1=p1) // xRHS &= unobserved_parents[i]; } if (JacobianCorrection) return logp + *JacobianCorrection; return logp; } // else return PLearn::logP(ConditionalExpression (RVInstance(marginalize(this, unobserved_parents.random_variables()), obs), RHS),true,parameters_to_learn); }
virtual void PLearn::FunctionalRandomVariable::setValueFromParentsValue | ( | ) | [pure virtual] |
set the field value from the values of the parents
Implements PLearn::RandomVariable.
Implemented in PLearn::NonRandomVariable, PLearn::JointRandomVariable, PLearn::RandomElementOfRandomVariable, PLearn::RVArrayRandomElementRandomVariable, PLearn::NegRandomVariable, PLearn::ExpRandomVariable, PLearn::LogRandomVariable, PLearn::PlusRandomVariable, PLearn::MinusRandomVariable, PLearn::ElementWiseDivisionRandomVariable, PLearn::ProductRandomVariable, PLearn::SubVecRandomVariable, PLearn::ExtendedRandomVariable, and PLearn::ConcatColumnsRandomVariable.