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

#include <HardSlopeVariable.h>

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

List of all members.

Public Member Functions

 HardSlopeVariable ()
 Default constructor for persistence.
 HardSlopeVariable (Variable *x, Variable *left, Variable *right)
virtual string classname () const
virtual OptionListgetOptionList () const
virtual OptionMapgetOptionMap () const
virtual RemoteMethodMapgetRemoteMethodMap () const
virtual HardSlopeVariabledeepCopy (CopiesMap &copies) const
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_ ()
 HardSlopeVariable.
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_

Private Types

typedef NaryVariable inherited

Detailed Description

Definition at line 56 of file HardSlopeVariable.h.


Member Typedef Documentation

Reimplemented from PLearn::NaryVariable.

Definition at line 58 of file HardSlopeVariable.h.


Constructor & Destructor Documentation

PLearn::HardSlopeVariable::HardSlopeVariable ( ) [inline]

Default constructor for persistence.

Definition at line 62 of file HardSlopeVariable.h.

{}
PLearn::HardSlopeVariable::HardSlopeVariable ( Variable x,
Variable left,
Variable right 
)

Definition at line 58 of file HardSlopeVariable.cc.

    : inherited(VarArray(x,left) & Var(right), 
                x->length()<left->length()?left->length():x->length(), 
                x->width()<left->width()?left->width():x->width()) 
{}

Member Function Documentation

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

HardSlopeVariable.

Reimplemented from PLearn::NaryVariable.

Definition at line 56 of file HardSlopeVariable.cc.

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

Reimplemented from PLearn::NaryVariable.

Definition at line 56 of file HardSlopeVariable.cc.

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

Reimplemented from PLearn::NaryVariable.

Definition at line 56 of file HardSlopeVariable.cc.

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

Reimplemented from PLearn::NaryVariable.

Definition at line 56 of file HardSlopeVariable.cc.

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

Reimplemented from PLearn::Object.

Definition at line 56 of file HardSlopeVariable.cc.

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

Reimplemented from PLearn::NaryVariable.

Definition at line 56 of file HardSlopeVariable.cc.

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

Implements PLearn::Variable.

Definition at line 112 of file HardSlopeVariable.cc.

References PLearn::Variable::gradientdata, i, PLearn::left(), n, PLearn::VarArray::nelems(), PLearn::Variable::nelems(), PLearn::right(), PLearn::NaryVariable::varray, and x.

{
    int n=nelems();
    int n1=varray[0]->nelems();
    int n2=varray[1]->nelems();
    int n3=varray[2]->nelems();
    int m1= n1==1?0:1;
    int m2= n2==1?0:1;
    int m3= n3==1?0:1;
    real* x = varray[0]->valuedata;
    real* left = varray[1]->valuedata;
    real* right = varray[2]->valuedata;
    real* dx = varray[0]->gradientdata;
    real* dleft = varray[1]->gradientdata;
    real* dright = varray[2]->gradientdata;
    for(int i=0; i<n; i++,x+=m1,left+=m2,right+=m3,dx+=m1,dleft+=m2,dright+=m3)
    {
        real tleft = *x - *left;
        real tright = *x - *right;
        if (tright<=0 && tleft>=0)
        {
            real inv_delta=1.0/(*right - *left);
            real dll = tright*inv_delta;
            real drr = -tleft*inv_delta;
            real dxx = inv_delta;
            *dx += gradientdata[i] * dxx;
            *dleft += gradientdata[i] * dll;
            *dright += gradientdata[i] * drr;
        }
    }
}

Here is the call graph for this function:

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

Reimplemented from PLearn::Object.

Definition at line 56 of file HardSlopeVariable.cc.

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

Reimplemented from PLearn::NaryVariable.

Definition at line 65 of file HardSlopeVariable.h.

{ return new HardSlopeVariable(x,left,right); }
HardSlopeVariable * PLearn::HardSlopeVariable::deepCopy ( CopiesMap copies) const [virtual]

Reimplemented from PLearn::NaryVariable.

Definition at line 56 of file HardSlopeVariable.cc.

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

compute output given input

Implements PLearn::Variable.

Definition at line 85 of file HardSlopeVariable.cc.

References PLearn::hard_slope(), i, PLearn::left(), n, PLearn::VarArray::nelems(), PLearn::Variable::nelems(), PLearn::right(), PLearn::Variable::valuedata, PLearn::NaryVariable::varray, and x.

{
    int n=nelems();
    int n1=varray[0]->nelems();
    int n2=varray[1]->nelems();
    int n3=varray[2]->nelems();
    real* x = varray[0]->valuedata;
    real* left = varray[1]->valuedata;
    real* right = varray[2]->valuedata;

    if (n1==n && n2==n && n3==n)
        for(int i=0; i<n; i++)
            valuedata[i] = hard_slope(x[i], left[i], right[i]);
    else if (n1==1 && n2==n && n3==n)
        for(int i=0; i<n; i++)
            valuedata[i] = hard_slope(*x, left[i], right[i]);
    else
    {
        int m1= n1==1?0:1;
        int m2= n2==1?0:1;
        int m3= n3==1?0:1;
        for(int i=0; i<n; i++,x+=m1,left+=m2,right+=m3)
            valuedata[i] = hard_slope(*x, *left, *right);
    }
}

Here is the call graph for this function:

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

Reimplemented from PLearn::Object.

Definition at line 56 of file HardSlopeVariable.cc.

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

Reimplemented from PLearn::Object.

Definition at line 56 of file HardSlopeVariable.cc.

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

Reimplemented from PLearn::Object.

Definition at line 56 of file HardSlopeVariable.cc.

void PLearn::HardSlopeVariable::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 65 of file HardSlopeVariable.cc.

References i, PLearn::Variable::length(), PLERROR, PLearn::TVec< T >::size(), PLearn::NaryVariable::varray, w, and PLearn::Variable::width().

{ 
    l = w = 0;
    if (varray.size() >= 3) {
        for (int i = 0;i < 3; i++) {
            if (varray[i]->length()>l)
                l = varray[i]->length();
            if (varray[i]->width() > w)
                w = varray[i]->width();
        }
        for (int i = 0;i < 3; i++) {
            if (varray[i]->length() != l || varray[i]->width() != w) {
                if (varray[i]->length() != 1 || varray[i]->width() != 1)
                    PLERROR("Each argument of HardSlopeVariable should either have the same length/width as the others or length 1");
            }
        }
    }
}

Here is the call graph for this function:

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

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

Reimplemented from PLearn::Variable.

Definition at line 144 of file HardSlopeVariable.cc.

References PLERROR.

{
    PLERROR("HardSlopeVariable::symbolicBprop() not implemented");
}

Member Data Documentation

Reimplemented from PLearn::NaryVariable.

Definition at line 65 of file HardSlopeVariable.h.


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