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

#include <UnfoldedSumOfVariable.h>

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

List of all members.

Public Member Functions

 UnfoldedSumOfVariable ()
 protected default constructor for persistence
 UnfoldedSumOfVariable (Var inputmatrix, Var bagsize, Func the_f, int maxbagsize)
 Sum_{i=0 to bag_size} f(i-th row of input_matrix)
virtual string classname () const
virtual OptionListgetOptionList () const
virtual OptionMapgetOptionMap () const
virtual RemoteMethodMapgetRemoteMethodMap () const
virtual UnfoldedSumOfVariabledeepCopy (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 ()
void printInfo (bool print_gradient)

Static Public Member Functions

static string _classname_ ()
 UnfoldedSumOfVariable.
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

Var input_matrix
Var bag_size
Func f
int max_bag_size
TVec< VarArrayinputs
VarArray outputs
TVec< VarArrayf_paths

Static Public Attributes

static StaticInitializer _static_initializer_

Private Types

typedef NaryVariable inherited

Private Member Functions

void build_ ()
 Object-specific post-constructor.

Detailed Description

Definition at line 52 of file UnfoldedSumOfVariable.h.


Member Typedef Documentation

Reimplemented from PLearn::NaryVariable.

Definition at line 54 of file UnfoldedSumOfVariable.h.


Constructor & Destructor Documentation

PLearn::UnfoldedSumOfVariable::UnfoldedSumOfVariable ( ) [inline]

protected default constructor for persistence

Definition at line 69 of file UnfoldedSumOfVariable.h.

: max_bag_size(0) {}
PLearn::UnfoldedSumOfVariable::UnfoldedSumOfVariable ( Var  inputmatrix,
Var  bagsize,
Func  the_f,
int  maxbagsize 
)

Sum_{i=0 to bag_size} f(i-th row of input_matrix)

Definition at line 57 of file UnfoldedSumOfVariable.cc.

References build().

    : inherited(nonInputParentsOfPath(the_f->inputs,the_f->outputs) & inputmatrix & bagsize, 
                the_f->outputs[0]->length(), 
                the_f->outputs[0]->width()),
      input_matrix(inputmatrix), bag_size(bagsize),
      f(the_f), max_bag_size(max_bagsize)
{
    build();
}

Here is the call graph for this function:


Member Function Documentation

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

UnfoldedSumOfVariable.

Reimplemented from PLearn::NaryVariable.

Definition at line 55 of file UnfoldedSumOfVariable.cc.

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

Reimplemented from PLearn::NaryVariable.

Definition at line 55 of file UnfoldedSumOfVariable.cc.

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

Reimplemented from PLearn::NaryVariable.

Definition at line 55 of file UnfoldedSumOfVariable.cc.

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

Reimplemented from PLearn::NaryVariable.

Definition at line 55 of file UnfoldedSumOfVariable.cc.

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

Reimplemented from PLearn::Object.

Definition at line 55 of file UnfoldedSumOfVariable.cc.

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

Reimplemented from PLearn::NaryVariable.

Definition at line 55 of file UnfoldedSumOfVariable.cc.

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

Implements PLearn::Variable.

Definition at line 159 of file UnfoldedSumOfVariable.cc.

References bag_size, f_paths, for(), PLearn::Variable::gradient, i, and outputs.

{ 
    int bagsize = (int)bag_size->valuedata[0];
    for (int i=0;i<bagsize;i++)
    {
        f_paths[i].clearGradient();
        outputs[i]->gradient << gradient;
        f_paths[i].bprop();
    }
}

Here is the call graph for this function:

void PLearn::UnfoldedSumOfVariable::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 67 of file UnfoldedSumOfVariable.cc.

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

Referenced by UnfoldedSumOfVariable().

Here is the call graph for this function:

Here is the caller graph for this function:

void PLearn::UnfoldedSumOfVariable::build_ ( ) [private]

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 73 of file UnfoldedSumOfVariable.cc.

References f, f_paths, i, inputs, j, max_bag_size, outputs, PLERROR, PLearn::propagationPath(), PLearn::TVec< T >::resize(), and PLearn::Variable::Var.

Referenced by build().

{
    if (f) {
        if(f->outputs.size()!=1)
            PLERROR("In UnfoldedSumOfVariable: 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)");
        f->inputs.setDontBpropHere(true);
        inputs.resize(max_bag_size);
        outputs.resize(max_bag_size);
        f_paths.resize(max_bag_size);
        for (int i=0;i<max_bag_size;i++)
        {
            inputs[i].resize(f->inputs.size());
            for (int j = 0; j < f->inputs.size(); j++) {
                inputs[i][j] = Var(f->inputs[j]->length(), f->inputs[j]->width());
            }
            outputs[i] = f(inputs[i])[0];
            f_paths[i] = propagationPath(inputs[i],outputs[i]);
        }
    }
}

Here is the call graph for this function:

Here is the caller graph for this function:

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

Reimplemented from PLearn::Object.

Definition at line 55 of file UnfoldedSumOfVariable.cc.

void PLearn::UnfoldedSumOfVariable::declareOptions ( OptionList ol) [static]

Default constructor for persistence.

Reimplemented from PLearn::NaryVariable.

Definition at line 94 of file UnfoldedSumOfVariable.cc.

References bag_size, PLearn::OptionBase::buildoption, PLearn::declareOption(), PLearn::NaryVariable::declareOptions(), f, input_matrix, and max_bag_size.

{
    declareOption(ol, "f", &UnfoldedSumOfVariable::f, OptionBase::buildoption, 
                  "    Func that is replicated for each element of the 'bag' taken from the VMat.");

    declareOption(ol, "input_matrix", &UnfoldedSumOfVariable::input_matrix, OptionBase::buildoption, 
                  "    Var that contains the data, with multiple consecutive rows forming one bag.\n"
                  "    The last row of a bag has a non-missing target value.\n");

    declareOption(ol, "bag_size", &UnfoldedSumOfVariable::bag_size, OptionBase::buildoption, 
                  "    Var that gives the size of the bag (number of rows of input_matrix to consider).\n");

    declareOption(ol, "max_bag_size", &UnfoldedSumOfVariable::max_bag_size, OptionBase::buildoption, 
                  "    maximum number of examples in a bag (more than that in input_matrix will trigger a run-time error).\n");

    inherited::declareOptions(ol);
}

Here is the call graph for this function:

static const PPath& PLearn::UnfoldedSumOfVariable::declaringFile ( ) [inline, static]

Reimplemented from PLearn::NaryVariable.

Definition at line 73 of file UnfoldedSumOfVariable.h.

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

Reimplemented from PLearn::NaryVariable.

Definition at line 55 of file UnfoldedSumOfVariable.cc.

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

compute output given input

Implements PLearn::Variable.

Definition at line 143 of file UnfoldedSumOfVariable.cc.

References bag_size, PLearn::TVec< T >::clear(), f_paths, i, if(), input_matrix, inputs, max_bag_size, outputs, PLERROR, and PLearn::Variable::value.

{
    value.clear();
    int bagsize = (int)bag_size->valuedata[0];
    if (bagsize>max_bag_size)
        PLERROR("UnfoldedSumOfVariable: bag size=%d > expected max. bag size(%d)",
                bagsize,max_bag_size);
    for (int i=0;i<bagsize;i++)
    {
        inputs[i] << input_matrix->matValue(i);
        f_paths[i].fprop();
        value += outputs[i]->value;
    }
}

Here is the call graph for this function:

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

Reimplemented from PLearn::Object.

Definition at line 55 of file UnfoldedSumOfVariable.cc.

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

Reimplemented from PLearn::Object.

Definition at line 55 of file UnfoldedSumOfVariable.cc.

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

Reimplemented from PLearn::Object.

Definition at line 55 of file UnfoldedSumOfVariable.cc.

void PLearn::UnfoldedSumOfVariable::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 131 of file UnfoldedSumOfVariable.cc.

References bag_size, PLearn::deepCopyField(), f, f_paths, input_matrix, inputs, PLearn::NaryVariable::makeDeepCopyFromShallowCopy(), outputs, and PLearn::varDeepCopyField().

Here is the call graph for this function:

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

Reimplemented from PLearn::NaryVariable.

Definition at line 171 of file UnfoldedSumOfVariable.cc.

References bag_size, PLearn::endl(), f_paths, PLearn::Variable::getName(), PLearn::Variable::gradient, i, PLearn::Object::info(), input_matrix, max_bag_size, outputs, and PLearn::Variable::value.

{
    for (int i=0;i<max_bag_size;i++)
        f_paths[i].printInfo(print_gradient);
    cout << info() << " : " << getName() << "[" << (void*)this << "]" 
         << "(input_matrix=" << (void*)input_matrix << ", bag_size=" 
         << (void*)bag_size << ", ";
    for(int i=0; i<max_bag_size; i++) cout << (void*)outputs[i] << " ";
    cout << ") = " << value;
    if (print_gradient) cout << " gradient=" << gradient;
    cout << endl; 
}

Here is the call graph for this function:

void PLearn::UnfoldedSumOfVariable::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 UnfoldedSumOfVariable.cc.

References f.

{
    if (f && f->outputs.size()) {
        l = f->outputs[0]->length();
        w = f->outputs[0]->width();
    } else
        l = w = 0;
}

Member Data Documentation

Reimplemented from PLearn::NaryVariable.

Definition at line 73 of file UnfoldedSumOfVariable.h.

Definition at line 65 of file UnfoldedSumOfVariable.h.

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

Definition at line 63 of file UnfoldedSumOfVariable.h.

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

Definition at line 61 of file UnfoldedSumOfVariable.h.

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

Definition at line 64 of file UnfoldedSumOfVariable.h.

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


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