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

#include <Max2Variable.h>

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

List of all members.

Public Member Functions

 Max2Variable ()
 Default constructor for persistence.
 Max2Variable (Variable *input, Variable *power)
virtual string classname () const
virtual OptionListgetOptionList () const
virtual OptionMapgetOptionMap () const
virtual RemoteMethodMapgetRemoteMethodMap () const
virtual Max2VariabledeepCopy (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 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

Static Public Member Functions

static string _classname_ ()
 Max2Variable.
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 Public Attributes

static StaticInitializer _static_initializer_

Protected Member Functions

void build_ ()
 This does the actual building.

Private Types

typedef BinaryVariable inherited

Detailed Description

elementwise max over 2 elements: max(v1,v2)[i] = max(v1[i],v2[i]) with same dimensions as the input vectors (both must have same length())

Definition at line 56 of file Max2Variable.h.


Member Typedef Documentation

Reimplemented from PLearn::BinaryVariable.

Definition at line 58 of file Max2Variable.h.


Constructor & Destructor Documentation

PLearn::Max2Variable::Max2Variable ( ) [inline]

Default constructor for persistence.

Definition at line 62 of file Max2Variable.h.

{}
PLearn::Max2Variable::Max2Variable ( Variable input,
Variable power 
)

Definition at line 64 of file Max2Variable.cc.

References build_(), and PLASSERT.

    : inherited(input1, input2, input1->length(), input1->width())
{
    PLASSERT( input1 && input2 );
    build_();
}

Here is the call graph for this function:


Member Function Documentation

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

Max2Variable.

Reimplemented from PLearn::BinaryVariable.

Definition at line 62 of file Max2Variable.cc.

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

Reimplemented from PLearn::BinaryVariable.

Definition at line 62 of file Max2Variable.cc.

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

Reimplemented from PLearn::BinaryVariable.

Definition at line 62 of file Max2Variable.cc.

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

Reimplemented from PLearn::BinaryVariable.

Definition at line 62 of file Max2Variable.cc.

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

Reimplemented from PLearn::Object.

Definition at line 62 of file Max2Variable.cc.

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

Reimplemented from PLearn::BinaryVariable.

Definition at line 62 of file Max2Variable.cc.

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

Implements PLearn::Variable.

Definition at line 109 of file Max2Variable.cc.

References PLearn::TVec< T >::data(), grad, PLearn::Variable::gradient, i, PLearn::BinaryVariable::input1, PLearn::BinaryVariable::input2, PLearn::Var::length(), n, and PLASSERT.

{
    PLASSERT( input1 && input2 );
    int n=input1->value.length();
    real* v1=input1->value.data();
    real* v2=input2->value.data();
    real* grad1=input1->gradient.data();
    real* grad2=input2->gradient.data();
    real* grad=gradient.data();
    for (int i=0;i<n;i++)
    {
        if (v2[i]<v1[i])
            grad1[i] += grad[i];
        if (v1[i]<v2[i])
            grad2[i] += grad[i];
    }
}

Here is the call graph for this function:

void PLearn::Max2Variable::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::BinaryVariable.

Definition at line 72 of file Max2Variable.cc.

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

Here is the call graph for this function:

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

This does the actual building.

Reimplemented from PLearn::BinaryVariable.

Definition at line 79 of file Max2Variable.cc.

References PLearn::BinaryVariable::input1, PLearn::BinaryVariable::input2, PLearn::Var::length(), PLERROR, and PLearn::Var::width().

Referenced by build(), and Max2Variable().

{
    if (input1 && input2) {
        if (input1->length() != input2->length()  ||  input1->width() != input2->width())
            PLERROR("IN Max2Variable input1 and input2 must have the same size");
    }
}

Here is the call graph for this function:

Here is the caller graph for this function:

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

Reimplemented from PLearn::Object.

Definition at line 62 of file Max2Variable.cc.

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

Reimplemented from PLearn::BinaryVariable.

Definition at line 65 of file Max2Variable.h.

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

Reimplemented from PLearn::BinaryVariable.

Definition at line 62 of file Max2Variable.cc.

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

compute output given input

Implements PLearn::Variable.

Definition at line 97 of file Max2Variable.cc.

References PLearn::TVec< T >::data(), i, PLearn::BinaryVariable::input1, PLearn::BinaryVariable::input2, PLearn::Var::length(), max, n, PLASSERT, and PLearn::Variable::value.

{
    PLASSERT( input1 && input2 );
    int n=input1->value.length();
    real* v1=input1->value.data();
    real* v2=input2->value.data();
    real* v=value.data();
    for (int i=0;i<n;i++)
        v[i] = std::max(v1[i],v2[i]);
}

Here is the call graph for this function:

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

Reimplemented from PLearn::Object.

Definition at line 62 of file Max2Variable.cc.

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

Reimplemented from PLearn::Object.

Definition at line 62 of file Max2Variable.cc.

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

Reimplemented from PLearn::Object.

Definition at line 62 of file Max2Variable.cc.

void PLearn::Max2Variable::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 88 of file Max2Variable.cc.

References PLearn::BinaryVariable::input1, PLearn::Var::length(), and PLearn::Var::width().

{
    if (input1) {
        l = input1->length();
        w = input1->width();
    } else
        l = w = 0;
}

Here is the call graph for this function:

void PLearn::Max2Variable::symbolicBprop ( ) [virtual]

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

Reimplemented from PLearn::Variable.

Definition at line 128 of file Max2Variable.cc.

References PLearn::Variable::g, PLearn::BinaryVariable::input1, PLearn::BinaryVariable::input2, and PLASSERT.

{
    PLASSERT( input1 && input2 );
    input1->accg((input2<input1)*g);
    input2->accg((input1<input2)*g);
}

Member Data Documentation

Reimplemented from PLearn::BinaryVariable.

Definition at line 65 of file Max2Variable.h.


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