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

#include <MatrixSumOfVariable.h>

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

List of all members.

Public Member Functions

 MatrixSumOfVariable ()
 protected default constructor for persistence
 MatrixSumOfVariable (VMat the_distr, Func the_f, int the_nsamples=-1, int the_input_size=-1)
 $ Sum_{inputs \in distr} f(inputs)$
virtual string classname () const
virtual OptionListgetOptionList () const
virtual OptionMapgetOptionMap () const
virtual RemoteMethodMapgetRemoteMethodMap () const
virtual MatrixSumOfVariabledeepCopy (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 fbprop ()
 do both fprop and bprop
virtual void symbolicBprop ()
 compute a piece of new Var graph that represents the symbolic derivative of this Var
virtual void rfprop ()
void printInfo (bool print_gradient)

Static Public Member Functions

static string _classname_ ()
 MatrixSumOfVariable.
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
Func f
int nsamples
int input_size
int curpos
 current pos in VMat
Vec input_value
Vec input_gradient
Vec output_value

Static Public Attributes

static StaticInitializer _static_initializer_

Protected Member Functions

void build_ ()
 Object-specific post-constructor.

Private Types

typedef NaryVariable inherited

Detailed Description

Definition at line 53 of file MatrixSumOfVariable.h.


Member Typedef Documentation

Reimplemented from PLearn::NaryVariable.

Definition at line 55 of file MatrixSumOfVariable.h.


Constructor & Destructor Documentation

PLearn::MatrixSumOfVariable::MatrixSumOfVariable ( ) [inline]

protected default constructor for persistence

Definition at line 71 of file MatrixSumOfVariable.h.

: distr(), f(), nsamples(), input_size(), curpos() {}
PLearn::MatrixSumOfVariable::MatrixSumOfVariable ( VMat  the_distr,
Func  the_f,
int  the_nsamples = -1,
int  the_input_size = -1 
)

$ Sum_{inputs \in distr} f(inputs)$

Definition at line 55 of file MatrixSumOfVariable.cc.

References build_().

    : inherited(nonInputParentsOfPath(the_f->inputs,the_f->outputs), the_f->outputs[0]->length(), the_f->outputs[0]->width()),
      distr(the_distr), f(the_f), nsamples(the_nsamples), input_size(the_input_size)
    //, curpos(0), input_value(the_distr->width()*nsamples), input_gradient(the_distr->width()*nsamples), output_value(the_f->outputs[0]->size())
{
    build_();
}

Here is the call graph for this function:


Member Function Documentation

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

MatrixSumOfVariable.

Reimplemented from PLearn::NaryVariable.

Definition at line 53 of file MatrixSumOfVariable.cc.

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

Reimplemented from PLearn::NaryVariable.

Definition at line 53 of file MatrixSumOfVariable.cc.

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

Reimplemented from PLearn::NaryVariable.

Definition at line 53 of file MatrixSumOfVariable.cc.

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

Reimplemented from PLearn::NaryVariable.

Definition at line 53 of file MatrixSumOfVariable.cc.

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

Reimplemented from PLearn::Object.

Definition at line 53 of file MatrixSumOfVariable.cc.

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

Reimplemented from PLearn::NaryVariable.

Definition at line 53 of file MatrixSumOfVariable.cc.

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

Implements PLearn::Variable.

Definition at line 137 of file MatrixSumOfVariable.cc.

References fbprop().

{ fbprop(); }

Here is the call graph for this function:

void PLearn::MatrixSumOfVariable::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 64 of file MatrixSumOfVariable.cc.

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

Here is the call graph for this function:

void PLearn::MatrixSumOfVariable::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 71 of file MatrixSumOfVariable.cc.

References curpos, distr, f, input_gradient, input_value, PLearn::VMat::length(), nsamples, output_value, PLERROR, PLearn::TVec< T >::resize(), and PLearn::VMat::width().

Referenced by build(), and MatrixSumOfVariable().

{
    curpos = 0;
    if (f && distr) {
        if(f->outputs.size()!=1)
            PLERROR("In MatrixSumOfVariable: function must have a single variable output (maybe you can vconcat the vars into a single one prior to calling sumOf, if this is really what you want)");

        input_value.resize(distr->width() * nsamples);
        input_gradient.resize(distr->width() * nsamples);
        output_value.resize(f->outputs[0]->size());

        if(nsamples == -1)
            nsamples = distr->length();
        f->inputs.setDontBpropHere(true);
    }
}

Here is the call graph for this function:

Here is the caller graph for this function:

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

Reimplemented from PLearn::Object.

Definition at line 53 of file MatrixSumOfVariable.cc.

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

Reimplemented from PLearn::NaryVariable.

Definition at line 75 of file MatrixSumOfVariable.h.

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

Reimplemented from PLearn::NaryVariable.

Definition at line 53 of file MatrixSumOfVariable.cc.

void PLearn::MatrixSumOfVariable::fbprop ( ) [virtual]

do both fprop and bprop

Reimplemented from PLearn::Variable.

Definition at line 141 of file MatrixSumOfVariable.cc.

References curpos, distr, f, PLearn::Variable::gradient, i, input_gradient, input_size, input_value, j, PLearn::VMat::length(), nsamples, PLearn::Variable::value, and PLearn::VMat::width().

Referenced by bprop().

{
    Vec oneInput_value(distr->width());
    f->recomputeParents();
  
    int inputpos=0;
    int targetpos=nsamples*input_size;
    for (int i=0; i<nsamples; i++)
    {
        distr->getRow(curpos, oneInput_value);
        for (int j=0; j<input_size; j++,inputpos++)
            input_value[inputpos]=oneInput_value[j];
        for (int j=input_size; j<distr.width(); j++,targetpos++)
            input_value[targetpos] = oneInput_value[j];
        if(++curpos==distr.length())
            curpos=0;
    }
    f->fbprop(input_value, value, input_gradient, gradient);
}

Here is the call graph for this function:

Here is the caller graph for this function:

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

compute output given input

Implements PLearn::Variable.

Definition at line 116 of file MatrixSumOfVariable.cc.

References curpos, distr, f, i, input_size, input_value, j, PLearn::VMat::length(), nsamples, PLearn::Variable::value, and PLearn::VMat::width().

{
    Vec oneInput_value(distr->width());
    f->recomputeParents();

    int inputpos=0;
    int targetpos=nsamples*input_size;
    for (int i=0; i<nsamples; i++)
    {
        distr->getRow(curpos, oneInput_value);
        for (int j=0; j<input_size; j++,inputpos++)
            input_value[inputpos]=oneInput_value[j];
        for (int j=input_size; j<distr.width(); j++,targetpos++)
            input_value[targetpos] = oneInput_value[j];
        if(++curpos==distr.length())
            curpos=0;
    }
    f->fprop(input_value, value);
}

Here is the call graph for this function:

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

Reimplemented from PLearn::Object.

Definition at line 53 of file MatrixSumOfVariable.cc.

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

Reimplemented from PLearn::Object.

Definition at line 53 of file MatrixSumOfVariable.cc.

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

Reimplemented from PLearn::Object.

Definition at line 53 of file MatrixSumOfVariable.cc.

void PLearn::MatrixSumOfVariable::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 108 of file MatrixSumOfVariable.cc.

References PLearn::deepCopyField(), distr, f, and PLearn::NaryVariable::makeDeepCopyFromShallowCopy().

Here is the call graph for this function:

void PLearn::MatrixSumOfVariable::printInfo ( bool  print_gradient) [virtual]

Reimplemented from PLearn::NaryVariable.

Definition at line 174 of file MatrixSumOfVariable.cc.

References PLearn::TVec< T >::clear(), curpos, distr, PLearn::endl(), f, PLearn::Variable::getName(), PLearn::Variable::gradient, i, PLearn::Object::info(), input_gradient, input_value, PLearn::VMat::length(), PLearn::Variable::nelems(), nsamples, output_value, PLERROR, PLearn::Variable::value, and PLearn::VMat::width().

{
    PLERROR("MatrixSumOfVariable::printInfo not implemented.");
    Vec input_value(distr->width());
    Vec input_gradient(distr->width());
    Vec output_value(nelems());

    f->recomputeParents();
    value.clear();

    for(int i=0; i<nsamples; i++)
    {
        distr->getRow(curpos++,input_value);
        if (print_gradient)
            f->fbprop(input_value, output_value, input_gradient, gradient);
        else
            f->fprop(input_value, output_value);
        value += output_value;
        if(++curpos>=distr->length())
            curpos = 0;
        f->fproppath.printInfo(print_gradient);
    }
    cout << info() << " : " << getName() << " = " << value;
    if (print_gradient) cout << " gradient=" << gradient;
    cout << endl; 
}

Here is the call graph for this function:

void PLearn::MatrixSumOfVariable::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 98 of file MatrixSumOfVariable.cc.

References f.

{
    if (f) {
        l = f->outputs[0]->length();
        w = f->outputs[0]->width();
    } else
        l = w = 0;
}
void PLearn::MatrixSumOfVariable::rfprop ( ) [virtual]

Reimplemented from PLearn::Variable.

Definition at line 168 of file MatrixSumOfVariable.cc.

References PLERROR.

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

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

Reimplemented from PLearn::Variable.

Definition at line 162 of file MatrixSumOfVariable.cc.

References PLERROR.

{
    PLERROR("MatrixSumOfVariable::symbolicBprop not implemented.");
}

Member Data Documentation

Reimplemented from PLearn::NaryVariable.

Definition at line 75 of file MatrixSumOfVariable.h.

current pos in VMat

Definition at line 63 of file MatrixSumOfVariable.h.

Referenced by build_(), fbprop(), fprop(), and printInfo().

Definition at line 66 of file MatrixSumOfVariable.h.

Referenced by build_(), fbprop(), and printInfo().

Definition at line 62 of file MatrixSumOfVariable.h.

Referenced by declareOptions(), fbprop(), and fprop().

Definition at line 65 of file MatrixSumOfVariable.h.

Referenced by build_(), fbprop(), fprop(), and printInfo().

Definition at line 61 of file MatrixSumOfVariable.h.

Referenced by build_(), declareOptions(), fbprop(), fprop(), and printInfo().

Definition at line 67 of file MatrixSumOfVariable.h.

Referenced by build_(), and printInfo().


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