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

#include <PowVariableVariable.h>

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

List of all members.

Public Member Functions

 PowVariableVariable ()
 Default constructor for persistence.
 PowVariableVariable (Variable *input, Variable *power)
virtual string classname () const
virtual OptionListgetOptionList () const
virtual OptionMapgetOptionMap () const
virtual RemoteMethodMapgetRemoteMethodMap () const
virtual PowVariableVariabledeepCopy (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_ ()
 PowVariableVariable.
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 pow: power may be a scalar or a var with same dimensions as the input (returns 0 wherever input is negative)

Definition at line 66 of file PowVariableVariable.h.


Member Typedef Documentation

Reimplemented from PLearn::BinaryVariable.

Definition at line 68 of file PowVariableVariable.h.


Constructor & Destructor Documentation

PLearn::PowVariableVariable::PowVariableVariable ( ) [inline]

Default constructor for persistence.

Definition at line 72 of file PowVariableVariable.h.

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

Definition at line 64 of file PowVariableVariable.cc.

References build_().

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

Here is the call graph for this function:


Member Function Documentation

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

PowVariableVariable.

Reimplemented from PLearn::BinaryVariable.

Definition at line 62 of file PowVariableVariable.cc.

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

Reimplemented from PLearn::BinaryVariable.

Definition at line 62 of file PowVariableVariable.cc.

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

Reimplemented from PLearn::BinaryVariable.

Definition at line 62 of file PowVariableVariable.cc.

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

Reimplemented from PLearn::BinaryVariable.

Definition at line 62 of file PowVariableVariable.cc.

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

Reimplemented from PLearn::Object.

Definition at line 62 of file PowVariableVariable.cc.

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

Reimplemented from PLearn::BinaryVariable.

Definition at line 62 of file PowVariableVariable.cc.

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

Implements PLearn::Variable.

Definition at line 116 of file PowVariableVariable.cc.

References PLearn::Variable::gradientdata, i, PLearn::BinaryVariable::input1, PLearn::BinaryVariable::input2, PLearn::Variable::nelems(), PLearn::safeflog(), and PLearn::Variable::valuedata.

{
    if (input2->isScalar())
    {
        real p = input2->valuedata[0];
        real& dp = input2->gradientdata[0];
        for(int i=0; i<nelems(); i++)
        {
            if (input1->valuedata[i]>0)
            {
                input1->gradientdata[i] += 
                    gradientdata[i] * valuedata[i] * p / input1->valuedata[i];
                dp += gradientdata[i] * valuedata[i] * safeflog(input1->valuedata[i]);
            }
        }
    }
    else
    {
        for(int i=0; i<nelems(); i++)
        {
            if (input1->valuedata[i]>0)
            {
                input1->gradientdata[i] += 
                    gradientdata[i] * valuedata[i] * input2->valuedata[i] 
                    / input1->valuedata[i];
                input2->gradientdata[i] += 
                    gradientdata[i] * valuedata[i] * safeflog(input1->valuedata[i]);
            }
        }
    }
}

Here is the call graph for this function:

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

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

Here is the call graph for this function:

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

This does the actual building.

Reimplemented from PLearn::BinaryVariable.

Definition at line 78 of file PowVariableVariable.cc.

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

Referenced by build(), and PowVariableVariable().

{
    if (input1 && input2) {
        if(!input2->isScalar() && (input1->length()!=input2->length() || input1->width()!=input2->width()))
            PLERROR("IN FunctionPowVariableVariable(Variable* input1, Variable* input2) input1 and input2 must have the same size or input2 must be scalar");
    }
}

Here is the call graph for this function:

Here is the caller graph for this function:

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

Reimplemented from PLearn::Object.

Definition at line 62 of file PowVariableVariable.cc.

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

Reimplemented from PLearn::BinaryVariable.

Definition at line 75 of file PowVariableVariable.h.

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

Reimplemented from PLearn::BinaryVariable.

Definition at line 62 of file PowVariableVariable.cc.

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

compute output given input

Implements PLearn::Variable.

Definition at line 96 of file PowVariableVariable.cc.

References i, PLearn::BinaryVariable::input1, PLearn::BinaryVariable::input2, PLearn::Variable::nelems(), PLearn::pow(), and PLearn::Variable::valuedata.

{
    if (input2->isScalar())
    {
        real p = input2->valuedata[0];
        for(int i=0; i<nelems(); i++)
            if (input1->valuedata[i]>0)
                valuedata[i] = pow(input1->valuedata[i],p);
            else
                valuedata[i] = 0;
    }
    else
        for(int i=0; i<nelems(); i++)
            if (input1->valuedata[i]>0)
                valuedata[i] = pow(input1->valuedata[i],input2->valuedata[i]);
            else
                valuedata[i] = 0;
}

Here is the call graph for this function:

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

Reimplemented from PLearn::Object.

Definition at line 62 of file PowVariableVariable.cc.

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

Reimplemented from PLearn::Object.

Definition at line 62 of file PowVariableVariable.cc.

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

Reimplemented from PLearn::Object.

Definition at line 62 of file PowVariableVariable.cc.

void PLearn::PowVariableVariable::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 86 of file PowVariableVariable.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::PowVariableVariable::symbolicBprop ( ) [virtual]

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

Reimplemented from PLearn::Variable.

Definition at line 149 of file PowVariableVariable.cc.

References PLearn::dot(), PLearn::Variable::g, PLearn::ifThenElse(), PLearn::BinaryVariable::input1, PLearn::BinaryVariable::input2, PLearn::Variable::length(), PLearn::log(), PLearn::Variable::Var, PLearn::Variable::width(), and zero.

{
    Var gv = g * Var(this);
    Var input1zero = (input1<=0.0);
    Var zero(length(), width());
    input1->accg(ifThenElse(input1zero, zero, gv * input2 / input1));
    if (input2->isScalar())
        input2->accg(dot(gv,ifThenElse(input1zero, zero, log(input1))));
    else
        input2->accg(ifThenElse(input1zero, zero, gv * log(input1)));
}

Here is the call graph for this function:


Member Data Documentation

Reimplemented from PLearn::BinaryVariable.

Definition at line 75 of file PowVariableVariable.h.


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