PLearn 0.1
Public Member Functions | Static Public Member Functions | Public Attributes | Static Public Attributes | Protected Member Functions | Protected Attributes | Private Types
PLearn::PotentialsVariable Class Reference

#include <PotentialsVariable.h>

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

List of all members.

Public Member Functions

 PotentialsVariable ()
 protected default constructor for persistence
 PotentialsVariable (Var the_input, Var the_comp_input, Var the_dp_target, Var the_target_dist_rep, Var output, VarArray params, VMat the_distr)
virtual string classname () const
virtual OptionListgetOptionList () const
virtual OptionMapgetOptionMap () const
virtual RemoteMethodMapgetRemoteMethodMap () const
virtual PotentialsVariabledeepCopy (CopiesMap &copies) const
virtual void build ()
 Post-constructor.
virtual void recomputeSize (int &l, int &w) const
 Recomputes the length l and width w that this variable should have, according to its parent variables.
virtual void makeDeepCopyFromShallowCopy (CopiesMap &copies)
 Does the necessary operations to transform a shallow copy (this) into a deep copy by deep-copying all the members that need to be.
virtual void fprop ()
 compute output given input
virtual void bprop ()
virtual void symbolicBprop ()
 compute a piece of new Var graph that represents the symbolic derivative of this Var
virtual void rfprop ()

Static Public Member Functions

static string _classname_ ()
 PotentialsVariable.
static OptionList_getOptionList_ ()
static RemoteMethodMap_getRemoteMethodMap_ ()
static Object_new_instance_for_typemap_ ()
static bool _isa_ (const Object *o)
static void _static_initialize_ ()
static const PPathdeclaringFile ()
static void declareOptions (OptionList &ol)
 Default constructor for persistence.

Public Attributes

VMat distr
Var input
Var output
Var comp_input
Var dp_target
Var target_dist_reps
VarArray params

Static Public Attributes

static StaticInitializer _static_initializer_

Protected Member Functions

void build_ ()
 Object-specific post-constructor.

Protected Attributes

TVec< VarArraytemp_comps
 Temporary computations.
VarArray proppath
Vec values

Private Types

typedef NaryVariable inherited

Detailed Description

Definition at line 52 of file PotentialsVariable.h.


Member Typedef Documentation

Reimplemented from PLearn::NaryVariable.

Definition at line 54 of file PotentialsVariable.h.


Constructor & Destructor Documentation

PLearn::PotentialsVariable::PotentialsVariable ( ) [inline]

protected default constructor for persistence

Definition at line 76 of file PotentialsVariable.h.

{}
PLearn::PotentialsVariable::PotentialsVariable ( Var  the_input,
Var  the_comp_input,
Var  the_dp_target,
Var  the_target_dist_rep,
Var  output,
VarArray  params,
VMat  the_distr 
)

Definition at line 57 of file PotentialsVariable.cc.

References build_().

: inherited(the_input & the_comp_input & the_dp_target & the_params & the_target_dist_reps, 
                2, // Temporary value
                1 // idem
        ),
    distr(the_distr), 
    input(the_input),
    output(the_output),
    comp_input(the_comp_input),
    dp_target(the_dp_target),
    target_dist_reps(the_target_dist_reps),
    params(the_params)
{
    build_();
}

Here is the call graph for this function:


Member Function Documentation

string PLearn::PotentialsVariable::_classname_ ( ) [static]

PotentialsVariable.

Reimplemented from PLearn::NaryVariable.

Definition at line 55 of file PotentialsVariable.cc.

OptionList & PLearn::PotentialsVariable::_getOptionList_ ( ) [static]

Reimplemented from PLearn::NaryVariable.

Definition at line 55 of file PotentialsVariable.cc.

RemoteMethodMap & PLearn::PotentialsVariable::_getRemoteMethodMap_ ( ) [static]

Reimplemented from PLearn::NaryVariable.

Definition at line 55 of file PotentialsVariable.cc.

bool PLearn::PotentialsVariable::_isa_ ( const Object o) [static]

Reimplemented from PLearn::NaryVariable.

Definition at line 55 of file PotentialsVariable.cc.

Object * PLearn::PotentialsVariable::_new_instance_for_typemap_ ( ) [static]

Reimplemented from PLearn::Object.

Definition at line 55 of file PotentialsVariable.cc.

StaticInitializer PotentialsVariable::_static_initializer_ & PLearn::PotentialsVariable::_static_initialize_ ( ) [static]

Reimplemented from PLearn::NaryVariable.

Definition at line 55 of file PotentialsVariable.cc.

void PLearn::PotentialsVariable::bprop ( ) [virtual]

Implements PLearn::Variable.

Definition at line 182 of file PotentialsVariable.cc.

References PLearn::VarArray::bprop(), PLearn::VarArray::clearGradient(), PLearn::TVec< T >::data(), dp_target, PLearn::Variable::gradient, i, j, PLearn::Variable::length(), output, proppath, PLearn::TVec< T >::size(), target_dist_reps, temp_comps, and values.

{  
    for(int i=0; i<length(); i++)
    {
        
        // Point to temp_comps for values and gradients of proppath
        for(int j=0; j<proppath.size(); j++)
        {
            proppath[j]->matValue = temp_comps[i][j]->matValue;
            proppath[j]->value = proppath[j]->matValue.toVec();
            proppath[j]->valuedata = proppath[j]->value.data();

            proppath[j]->matGradient = temp_comps[i][j]->matGradient;
            proppath[j]->gradient = proppath[j]->matGradient.toVec();
            proppath[j]->gradientdata = proppath[j]->gradient.data();
        }
        
        //proppath << temp_comps(i);
        dp_target->value << target_dist_reps->matValue((int)values[i]);
        proppath.clearGradient();
        dp_target->clearGradient();
        output->gradient[0] = gradient[i];
        proppath.bprop();
        target_dist_reps->matGradient((int)values[i]) += dp_target->gradient;
        target_dist_reps->updateRow((int)values[i]);
    }
}

Here is the call graph for this function:

void PLearn::PotentialsVariable::build ( ) [virtual]

Post-constructor.

The normal implementation should call simply inherited::build(), then this class's build_(). This method should be callable again at later times, after modifying some option fields to change the "architecture" of the object.

Reimplemented from PLearn::NaryVariable.

Definition at line 74 of file PotentialsVariable.cc.

References PLearn::NaryVariable::build(), and build_().

Here is the call graph for this function:

void PLearn::PotentialsVariable::build_ ( ) [protected]

Object-specific post-constructor.

This method should be redefined in subclasses and do the actual building of the object according to previously set option fields. Constructors can just set option fields, and then call build_. This method is NOT virtual, and will typically be called only from three places: a constructor, the public virtual build() method, and possibly the public virtual read method (which calls its parent's read). build_() can assume that its parent's build_() has already been called.

Reimplemented from PLearn::NaryVariable.

Definition at line 81 of file PotentialsVariable.cc.

References comp_input, dp_target, i, input, PLearn::Variable::length(), output, params, PLERROR, PLearn::propagationPath(), proppath, PLearn::TVec< T >::resize(), PLearn::TVec< T >::size(), temp_comps, and PLearn::Variable::Var.

Referenced by build(), and PotentialsVariable().

{
    if ( input && output && comp_input && dp_target && params.size() != 0) 
    {
        if(output->size() != 1) PLERROR("In PotentialsVariable::build_(): to_output function has output size different from 1");
        proppath = propagationPath(comp_input & dp_target & params, output);

        // Initialize temp_comps
        
        temp_comps.resize(1);
        temp_comps[0].resize(proppath.size());
        for(int i=0; i<proppath.size(); i++)
            temp_comps[0][i] = Var(proppath[i]->length(), proppath[i]->width());
        
    }
}

Here is the call graph for this function:

Here is the caller graph for this function:

string PLearn::PotentialsVariable::classname ( ) const [virtual]

Reimplemented from PLearn::Object.

Definition at line 55 of file PotentialsVariable.cc.

void PLearn::PotentialsVariable::declareOptions ( OptionList ol) [static]
static const PPath& PLearn::PotentialsVariable::declaringFile ( ) [inline, static]

Reimplemented from PLearn::NaryVariable.

Definition at line 79 of file PotentialsVariable.h.

:
    void build_();
PotentialsVariable * PLearn::PotentialsVariable::deepCopy ( CopiesMap copies) const [virtual]

Reimplemented from PLearn::NaryVariable.

Definition at line 55 of file PotentialsVariable.cc.

void PLearn::PotentialsVariable::fprop ( ) [virtual]

compute output given input

Implements PLearn::Variable.

Definition at line 141 of file PotentialsVariable.cc.

References PLearn::TVec< T >::data(), distr, dp_target, PLearn::VarArray::fprop(), i, input, j, PLearn::TVec< T >::length(), PLearn::Variable::length(), output, proppath, PLearn::TVec< T >::resize(), PLearn::TVec< T >::size(), target_dist_reps, temp_comps, PLearn::Variable::value, values, and PLearn::Variable::Var.

{
    //temp_comps.resize(length(),proppath.nelems());
    distr->getValues(input->value,distr->inputsize(),values);
    
    for(int i=0; i<length(); i++)
    {        
        
        // Add some elements in temp_comps if necessary
        if(temp_comps.length() < length())
        {
            int last_size = temp_comps.length();
            temp_comps.resize(length());
            for(int j=last_size; j<temp_comps.length(); j++)
            {
                temp_comps[j].resize(proppath.size());
                for(int k=0; k<proppath.size(); k++)
                    temp_comps[j][k] = Var(proppath[k]->length(), proppath[k]->width());
            }
        }
        
        // Point to temp_comps for values and gradients of proppath
        for(int j=0; j<proppath.size(); j++)
        {
            proppath[j]->matValue = temp_comps[i][j]->matValue;
            proppath[j]->value = proppath[j]->matValue.toVec();
            proppath[j]->valuedata = proppath[j]->value.data();

            proppath[j]->matGradient = temp_comps[i][j]->matGradient;
            proppath[j]->gradient = proppath[j]->matGradient.toVec();
            proppath[j]->gradientdata = proppath[j]->gradient.data();
        }
        
        dp_target->value << target_dist_reps->matValue((int)values[i]);
        proppath.fprop();
        //proppath >> temp_comps(i);
        value[i] = output->value[0];
    }
}

Here is the call graph for this function:

OptionList & PLearn::PotentialsVariable::getOptionList ( ) const [virtual]

Reimplemented from PLearn::Object.

Definition at line 55 of file PotentialsVariable.cc.

OptionMap & PLearn::PotentialsVariable::getOptionMap ( ) const [virtual]

Reimplemented from PLearn::Object.

Definition at line 55 of file PotentialsVariable.cc.

RemoteMethodMap & PLearn::PotentialsVariable::getRemoteMethodMap ( ) const [virtual]

Reimplemented from PLearn::Object.

Definition at line 55 of file PotentialsVariable.cc.

void PLearn::PotentialsVariable::makeDeepCopyFromShallowCopy ( CopiesMap copies) [virtual]

Does the necessary operations to transform a shallow copy (this) into a deep copy by deep-copying all the members that need to be.

This needs to be overridden by every class that adds "complex" data members to the class, such as Vec, Mat, PP<Something>, etc. Typical implementation:

  void CLASS_OF_THIS::makeDeepCopyFromShallowCopy(CopiesMap& copies)
  {
      inherited::makeDeepCopyFromShallowCopy(copies);
      deepCopyField(complex_data_member1, copies);
      deepCopyField(complex_data_member2, copies);
      ...
  }
Parameters:
copiesA map used by the deep-copy mechanism to keep track of already-copied objects.

Reimplemented from PLearn::NaryVariable.

Definition at line 123 of file PotentialsVariable.cc.

References comp_input, PLearn::deepCopyField(), distr, dp_target, input, PLearn::NaryVariable::makeDeepCopyFromShallowCopy(), output, params, proppath, target_dist_reps, temp_comps, values, and PLearn::varDeepCopyField().

Here is the call graph for this function:

void PLearn::PotentialsVariable::recomputeSize ( int l,
int w 
) const [virtual]

Recomputes the length l and width w that this variable should have, according to its parent variables.

This is used for ex. by sizeprop() The default version stupidly returns the current dimensions, so make sure to overload it in subclasses if this is not appropriate.

Reimplemented from PLearn::Variable.

Definition at line 112 of file PotentialsVariable.cc.

References distr, input, PLearn::TVec< T >::length(), and values.

{
    if (distr) {
        distr->getValues(input->value,distr->inputsize(),values);
        l = values.length();
        w = 1;
    } else
        l = w = 0;
}

Here is the call graph for this function:

void PLearn::PotentialsVariable::rfprop ( ) [virtual]

Reimplemented from PLearn::Variable.

Definition at line 218 of file PotentialsVariable.cc.

References PLERROR.

{
    PLERROR("In PotentialsVariable::rfprop(): not implemented");
}
void PLearn::PotentialsVariable::symbolicBprop ( ) [virtual]

compute a piece of new Var graph that represents the symbolic derivative of this Var

Reimplemented from PLearn::Variable.

Definition at line 212 of file PotentialsVariable.cc.

References PLERROR.

{
    PLERROR("In PotentialsVariable::symbolicBprop(): not implemented");
}

Member Data Documentation

Reimplemented from PLearn::NaryVariable.

Definition at line 79 of file PotentialsVariable.h.

Definition at line 70 of file PotentialsVariable.h.

Referenced by build_(), declareOptions(), and makeDeepCopyFromShallowCopy().

Definition at line 73 of file PotentialsVariable.h.

Referenced by build_(), declareOptions(), and makeDeepCopyFromShallowCopy().

Definition at line 61 of file PotentialsVariable.h.

Referenced by bprop(), build_(), fprop(), and makeDeepCopyFromShallowCopy().

Definition at line 72 of file PotentialsVariable.h.

Referenced by bprop(), declareOptions(), fprop(), and makeDeepCopyFromShallowCopy().

Temporary computations.

Definition at line 60 of file PotentialsVariable.h.

Referenced by bprop(), build_(), fprop(), and makeDeepCopyFromShallowCopy().

Definition at line 63 of file PotentialsVariable.h.

Referenced by bprop(), fprop(), makeDeepCopyFromShallowCopy(), and recomputeSize().


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