PLearn 0.1
Public Member Functions | Public Attributes
PLearn::MinusRandomVariable Class Reference

#include <RandomVar.h>

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

List of all members.

Public Member Functions

 MinusRandomVariable (RandomVar input1, RandomVar input2)
 RandomVariable Minus.
virtual char * classname ()
void setValueFromParentsValue ()
 set the field value from the values of the parents
bool invertible (const Var &obs, RVInstanceArray &unobserved_parents, Var **JacobianCorrection)
 functions specific to FunctionalRandomVariable's
void EMBprop (const Vec obs, real post)
void EMTrainingInitialize (const RVArray &parameters_to_learn)
 Initialization of EM training (before all the iterations start).
void EMEpochInitialize ()
 Initialization of an individual EMEpoch.
void EMUpdate ()
const RandomVarX0 ()
 convenience inline's
const RandomVarX1 ()
bool learn_X0 ()
 stuff for EM
bool learn_X1 ()

Public Attributes

bool learn_something
RandomVar parent_to_learn
 the one of X0 or X1 that is to learn
RandomVar other_parent
 the other one
Vec numerator
Vec difference
real denom

Detailed Description

Y = X0 - X1

if both X0 and X1 are observed, and one of them is learnable, then it can be learned by EM.

Definition at line 1329 of file RandomVar.h.


Constructor & Destructor Documentation

PLearn::MinusRandomVariable::MinusRandomVariable ( RandomVar  input1,
RandomVar  input2 
)

RandomVariable Minus.

Definition at line 1419 of file RandomVar.cc.

References PLERROR.

    : FunctionalRandomVariable(input1 & input2, 
                               MAX(input1->length(),input2->length())),
      parent_to_learn(parents[0]), other_parent(parents[0]),
      numerator(value->length()), difference(value->length())
{
    if(input1->length() != input2->length() &&
       input1->length() !=1 && input2->length()!=1)
        PLERROR("MinusRandomVariable(RandomVariable* in1, RandomVariable* in2) in1 and"
                "in2 must have the same length or one of them must be of length 1");
}

Member Function Documentation

virtual char* PLearn::MinusRandomVariable::classname ( ) [inline, virtual]

Implements PLearn::RandomVariable.

Definition at line 1334 of file RandomVar.h.

{ return "MinusRandomVariable"; }
void PLearn::MinusRandomVariable::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 1484 of file RandomVar.cc.

References PLearn::add(), denom, difference, PLearn::RandomVariable::isConstant(), learn_something, learn_X0(), PLearn::multiplyAcc(), numerator, other_parent, parent_to_learn, PLearn::substract(), PLearn::RandomVariable::value, X0(), and X1().

{
    if (learn_something)
    {
        if (learn_X0())
            // numerator += posterior * (obs + other_parent->value->value);
            add(obs,other_parent->value->value,difference);
        else
            // numerator += posterior * (other_parent->value->value - obs);
            substract(other_parent->value->value,obs,difference);

        multiplyAcc(numerator, difference,posterior);
        denom += posterior;
        if (!other_parent->isConstant())
        {
            // propagate to other parent
            if (learn_X0())
                add(obs,parent_to_learn->value->value,difference);
            else
                substract(parent_to_learn->value->value,obs,difference);
            other_parent->EMBprop(difference,posterior);
        }
    }
    else
    {
        if (!X1()->isConstant())
        {
            substract(X0()->value->value,obs,difference);
            X1()->EMBprop(difference,posterior);
        }
        if (!X0()->isConstant())
        {
            add(obs,X1()->value->value,difference);
            X0()->EMBprop(difference,posterior);
        }
    }
}

Here is the call graph for this function:

void PLearn::MinusRandomVariable::EMEpochInitialize ( ) [virtual]

Initialization of an individual EMEpoch.

the default just propagates to the unmarked parents

Reimplemented from PLearn::RandomVariable.

Definition at line 1473 of file RandomVar.cc.

References PLearn::TVec< T >::clear(), denom, PLearn::RandomVariable::EMmark, learn_something, and numerator.

{
    if (EMmark) return;
    RandomVariable::EMEpochInitialize();
    if (learn_something)
    {
        numerator.clear();
        denom = 0.0;
    }
}

Here is the call graph for this function:

void PLearn::MinusRandomVariable::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 from PLearn::RandomVariable.

Definition at line 1452 of file RandomVar.cc.

References learn_something, learn_X0(), learn_X1(), other_parent, parent_to_learn, PLERROR, X0(), and X1().

{
    RandomVariable::EMTrainingInitialize(parameters_to_learn);
    if (learn_X0() && learn_X1())
        PLERROR("MinusRandomVariable: can't learn both X0 and X1");
    if (learn_X0() || learn_X1())
    {
        learn_something=true;
        if (learn_X0())
        {
            parent_to_learn = X0();
            other_parent = X1();
        }
        else
        {
            parent_to_learn = X1();
            other_parent = X0();
        }
    }
}

Here is the call graph for this function:

void PLearn::MinusRandomVariable::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 from PLearn::RandomVariable.

Definition at line 1522 of file RandomVar.cc.

References denom, PLearn::RandomVariable::EMmark, PLearn::RandomVariable::isConstant(), learn_something, learn_X0(), learn_X1(), PLearn::multiply(), numerator, parent_to_learn, X0(), and X1().

{
    if (EMmark) return;
    EMmark=true;
    if (learn_something && denom>0)
        // new value = numerator / denom
        multiply(numerator,real(1.0/denom),parent_to_learn->value->value);
    if (!learn_X0() && !X0()->isConstant())
        X0()->EMUpdate();
    if (!learn_X1() && !X1()->isConstant())
        X1()->EMUpdate();
}

Here is the call graph for this function:

bool PLearn::MinusRandomVariable::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 from PLearn::FunctionalRandomVariable.

Definition at line 1437 of file RandomVar.cc.

References PLearn::TVec< T >::size(), X0(), and X1().

{
    if (unobserved_parents.size()==2)
        return false; // can't invert if two parents are unobserved
    if (unobserved_parents[0].V == X0())
        unobserved_parents[0].v = obs + X1()->value;
    else
        unobserved_parents[0].v = X0()->value - obs;
    return true;
    
}

Here is the call graph for this function:

bool PLearn::MinusRandomVariable::learn_X0 ( ) [inline]

stuff for EM

Definition at line 1349 of file RandomVar.h.

Referenced by EMBprop(), EMTrainingInitialize(), and EMUpdate().

{ return learn_the_parameters[0]; }

Here is the caller graph for this function:

bool PLearn::MinusRandomVariable::learn_X1 ( ) [inline]

Definition at line 1350 of file RandomVar.h.

Referenced by EMTrainingInitialize(), and EMUpdate().

{ return learn_the_parameters[1]; }

Here is the caller graph for this function:

void PLearn::MinusRandomVariable::setValueFromParentsValue ( ) [virtual]

set the field value from the values of the parents

Implements PLearn::FunctionalRandomVariable.

Definition at line 1431 of file RandomVar.cc.

References PLearn::RandomVariable::marked, PLearn::RandomVariable::value, X0(), and X1().

{
    if (marked) return;
    value = X0()->value - X1()->value;
}

Here is the call graph for this function:

const RandomVar& PLearn::MinusRandomVariable::X0 ( ) [inline]

convenience inline's

Definition at line 1345 of file RandomVar.h.

Referenced by EMBprop(), EMTrainingInitialize(), EMUpdate(), invertible(), and setValueFromParentsValue().

{ return parents[0]; }

Here is the caller graph for this function:

const RandomVar& PLearn::MinusRandomVariable::X1 ( ) [inline]

Definition at line 1346 of file RandomVar.h.

Referenced by EMBprop(), EMTrainingInitialize(), EMUpdate(), invertible(), and setValueFromParentsValue().

{ return parents[1]; }

Here is the caller graph for this function:


Member Data Documentation

Definition at line 1356 of file RandomVar.h.

Referenced by EMBprop(), EMEpochInitialize(), and EMUpdate().

Definition at line 1355 of file RandomVar.h.

Referenced by EMBprop().

Definition at line 1351 of file RandomVar.h.

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

Definition at line 1354 of file RandomVar.h.

Referenced by EMBprop(), EMEpochInitialize(), and EMUpdate().

the other one

Definition at line 1353 of file RandomVar.h.

Referenced by EMBprop(), and EMTrainingInitialize().

the one of X0 or X1 that is to learn

Definition at line 1352 of file RandomVar.h.

Referenced by EMBprop(), EMTrainingInitialize(), and EMUpdate().


The documentation for this class was generated from the following files:
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines