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

#include <SoftSlopeVariable.h>

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

List of all members.

Public Member Functions

 SoftSlopeVariable ()
 Default constructor for persistence.
 SoftSlopeVariable (Variable *x, Variable *smoothness, Variable *left, Variable *right, bool tabulated=true)
virtual string classname () const
virtual OptionListgetOptionList () const
virtual OptionMapgetOptionMap () const
virtual RemoteMethodMapgetRemoteMethodMap () const
virtual SoftSlopeVariabledeepCopy (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_ ()
 SoftSlopeVariable.
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.

Static Public Attributes

static StaticInitializer _static_initializer_

Protected Attributes

bool tabulated

Private Types

typedef NaryVariable inherited

Detailed Description

Definition at line 58 of file SoftSlopeVariable.h.


Member Typedef Documentation

Reimplemented from PLearn::NaryVariable.

Definition at line 60 of file SoftSlopeVariable.h.


Constructor & Destructor Documentation

PLearn::SoftSlopeVariable::SoftSlopeVariable ( ) [inline]

Default constructor for persistence.

Definition at line 67 of file SoftSlopeVariable.h.

{}
PLearn::SoftSlopeVariable::SoftSlopeVariable ( Variable x,
Variable smoothness,
Variable left,
Variable right,
bool  tabulated = true 
)

Definition at line 61 of file SoftSlopeVariable.cc.

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

Member Function Documentation

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

SoftSlopeVariable.

Reimplemented from PLearn::NaryVariable.

Definition at line 59 of file SoftSlopeVariable.cc.

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

Reimplemented from PLearn::NaryVariable.

Definition at line 59 of file SoftSlopeVariable.cc.

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

Reimplemented from PLearn::NaryVariable.

Definition at line 59 of file SoftSlopeVariable.cc.

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

Reimplemented from PLearn::NaryVariable.

Definition at line 59 of file SoftSlopeVariable.cc.

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

Reimplemented from PLearn::Object.

Definition at line 59 of file SoftSlopeVariable.cc.

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

Reimplemented from PLearn::NaryVariable.

Definition at line 59 of file SoftSlopeVariable.cc.

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

Implements PLearn::Variable.

Definition at line 125 of file SoftSlopeVariable.cc.

References PLearn::fast_exact_is_equal(), PLearn::Variable::gradientdata, i, PLearn::left(), n, PLearn::VarArray::nelems(), PLearn::Variable::nelems(), PLearn::right(), PLearn::sigmoid(), PLearn::soft_slope(), tabulated, PLearn::tabulated_soft_slope(), PLearn::NaryVariable::varray, and x.

{
    int n=nelems();
    int n1=varray[0]->nelems();
    int n2=varray[1]->nelems();
    int n3=varray[2]->nelems();
    int n4=varray[3]->nelems();
    int m1= n1==1?0:1;
    int m2= n2==1?0:1;
    int m3= n3==1?0:1;
    int m4= n4==1?0:1;
    real* x = varray[0]->valuedata;
    real* smoothness = varray[1]->valuedata;
    real* left = varray[2]->valuedata;
    real* right = varray[3]->valuedata;
    real* dx = varray[0]->gradientdata;
    real* dsmoothness = varray[1]->gradientdata;
    real* dleft = varray[2]->gradientdata;
    real* dright = varray[3]->gradientdata;
    for(int i=0; i<n; i++,x+=m1,smoothness+=m2,left+=m3,right+=m4,dx+=m1,dsmoothness+=m2,dleft+=m3,dright+=m4)
    {
        if (fast_exact_is_equal(*smoothness, 0)) continue;
        real inv_smoothness = 1.0 / *smoothness;
        real t1 = sigmoid(- *smoothness*(*x-*left));
        real t2 = sigmoid(- *smoothness*(*x-*right));
        real inv_delta=1.0/(*right-*left);
        real rat = (tabulated?tabulated_soft_slope(*x, *smoothness, *left, *right):soft_slope(*x, *smoothness, *left, *right)) -1;
        real move = rat * inv_delta;
        real dss = (-t1*(*x-*left) + t2*(*x-*right))*inv_smoothness*inv_delta - rat * inv_smoothness;
        real dll = t1*inv_delta*inv_smoothness + move;
        real drr = -t2*inv_delta*inv_smoothness - move;
        real dxx = (-t1+t2)*inv_delta;
        *dx += gradientdata[i] * dxx;
        *dsmoothness += gradientdata[i] * dss;
        *dleft += gradientdata[i] * dll;
        *dright += gradientdata[i] * drr;
    }
}

Here is the call graph for this function:

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

Reimplemented from PLearn::Object.

Definition at line 59 of file SoftSlopeVariable.cc.

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

Default constructor for persistence.

Reimplemented from PLearn::NaryVariable.

Definition at line 68 of file SoftSlopeVariable.cc.

References PLearn::OptionBase::buildoption, PLearn::declareOption(), PLearn::NaryVariable::declareOptions(), and tabulated.

Here is the call graph for this function:

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

Reimplemented from PLearn::NaryVariable.

Definition at line 70 of file SoftSlopeVariable.h.

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

Reimplemented from PLearn::NaryVariable.

Definition at line 59 of file SoftSlopeVariable.cc.

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

compute output given input

Implements PLearn::Variable.

Definition at line 95 of file SoftSlopeVariable.cc.

References i, PLearn::left(), n, PLearn::VarArray::nelems(), PLearn::Variable::nelems(), PLearn::right(), PLearn::soft_slope(), tabulated, PLearn::tabulated_soft_slope(), 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();
    int n4=varray[3]->nelems();
    real* x = varray[0]->valuedata;
    real* smoothness = varray[1]->valuedata;
    real* left = varray[2]->valuedata;
    real* right = varray[3]->valuedata;

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

Here is the call graph for this function:

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

Reimplemented from PLearn::Object.

Definition at line 59 of file SoftSlopeVariable.cc.

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

Reimplemented from PLearn::Object.

Definition at line 59 of file SoftSlopeVariable.cc.

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

Reimplemented from PLearn::Object.

Definition at line 59 of file SoftSlopeVariable.cc.

void PLearn::SoftSlopeVariable::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 74 of file SoftSlopeVariable.cc.

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

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

Here is the call graph for this function:

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

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

Reimplemented from PLearn::Variable.

Definition at line 164 of file SoftSlopeVariable.cc.

References PLERROR.

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

Member Data Documentation

Reimplemented from PLearn::NaryVariable.

Definition at line 70 of file SoftSlopeVariable.h.

Definition at line 63 of file SoftSlopeVariable.h.

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


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