PLearn 0.1
|
#include <RandomVar.h>
Public Member Functions | |
RVArrayRandomElementRandomVariable (const RVArray &table, const RandomVar &index) | |
RVArrayRandomElementRandomVariable. | |
virtual char * | classname () |
void | setValueFromParentsValue () |
set the field value from the values of the parents | |
virtual Var | logP (const Var &obs, const RVInstanceArray &RHS, RVInstanceArray *parameters_to_learn=0) |
redefine RandomVariable functions | |
void | EMBprop (const Vec obs, real post) |
const RandomVar & | index () |
convenience inlines |
RandomVariable that is the i-th element of its parent vector, where i is the value of the last parent. i.e. parents[0..N-1] is the table over which we select parents[N] is the index that makes the selection
Definition at line 1148 of file RandomVar.h.
PLearn::RVArrayRandomElementRandomVariable::RVArrayRandomElementRandomVariable | ( | const RVArray & | table, |
const RandomVar & | index | ||
) |
RVArrayRandomElementRandomVariable.
Definition at line 1177 of file RandomVar.cc.
References PLearn::RandomVariable::length(), PLearn::RVArray::length(), PLERROR, and PLearn::TVec< T >::size().
:FunctionalRandomVariable((RVArray)(table&index),table[0]->length()) { int l=table[0]->length(); for (int i=1;i<table.size();i++) if (table[i]->length()!=l) PLERROR("RVArrayRandomElementRandomVariables expect all the elements of table\n" " to have the same length (%-th has length %d while 0-th has length %d", i,table[i]->length(),l); if (index->length()!=1) PLERROR("RVArrayRandomElementRandomVariables expect an index RandomVar of length 1"); }
virtual char* PLearn::RVArrayRandomElementRandomVariable::classname | ( | ) | [inline, virtual] |
Implements PLearn::RandomVariable.
Definition at line 1153 of file RandomVar.h.
{ return "RVArrayRandomElementRandomVariable"; }
void PLearn::RVArrayRandomElementRandomVariable::EMBprop | ( | const Vec | obs, |
real | posterior | ||
) | [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".
Implements PLearn::RandomVariable.
Definition at line 1227 of file RandomVar.cc.
{ }
const RandomVar& PLearn::RVArrayRandomElementRandomVariable::index | ( | ) | [inline] |
convenience inlines
Definition at line 1161 of file RandomVar.h.
Referenced by logP(), and setValueFromParentsValue().
Var PLearn::RVArrayRandomElementRandomVariable::logP | ( | const Var & | obs, |
const RVInstanceArray & | RHS, | ||
RVInstanceArray * | parameters_to_learn = 0 |
||
) | [virtual] |
redefine RandomVariable functions
Reimplemented from PLearn::FunctionalRandomVariable.
Definition at line 1201 of file RandomVar.cc.
References i, index(), PLearn::RandomVariable::isMarked(), PLearn::FunctionalRandomVariable::isNonRandom(), PLearn::mixture(), n, PLearn::RandomVariable::parents, PLearn::RandomVariable::RandomVar, PLearn::TVec< T >::size(), and PLearn::vconcat().
{ int n = parents.size()-1; if (index()->isMarked() || index()->isNonRandom()) // special case where index is observed, just pass to selected parent { VarArray parents_logp(n); for (int i=0;i<n;i++) parents_logp[i]=parents[i]->logP(obs,RHS,parameters_to_learn); return parents_logp[index()->value]; } // otherwise, build a Mixture, with log_weights = logP(index()==i) VarArray log_weights(n); RVArray components(n); for (int i=0;i<n;i++) { Var indx(1); indx = (real)i; log_weights[i] = index()->logP(indx,RHS,parameters_to_learn); components[i] = parents[i]; } RandomVar mixt = mixture(components,RandomVar(vconcat(log_weights))); return mixt->logP(obs,RHS,parameters_to_learn); }
void PLearn::RVArrayRandomElementRandomVariable::setValueFromParentsValue | ( | ) | [virtual] |
set the field value from the values of the parents
Implements PLearn::FunctionalRandomVariable.
Definition at line 1190 of file RandomVar.cc.
References index(), PLearn::RandomVariable::marked, n, PLearn::RandomVariable::parents, PLearn::TVec< T >::size(), and PLearn::RandomVariable::value.
{ if (marked) return; int n = parents.size()-1; VarArray parents_values(n); for (int i=0;i<n;i++) parents_values[i]=parents[i]->value; value = parents_values[index()->value]; }