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

#include <SoftSlopeIntegralVariable.h>

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

List of all members.

Public Member Functions

 SoftSlopeIntegralVariable ()
 Default constructor for persistence.
 SoftSlopeIntegralVariable (Variable *smoothness, Variable *left, Variable *right, real a_=0, real b_=1, bool tabulated=true)
virtual string classname () const
virtual OptionListgetOptionList () const
virtual OptionMapgetOptionMap () const
virtual RemoteMethodMapgetRemoteMethodMap () const
virtual SoftSlopeIntegralVariabledeepCopy (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_ ()
 SoftSlopeIntegralVariable.
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

real a
real b
bool tabulated

Static Public Attributes

static StaticInitializer _static_initializer_

Private Types

typedef NaryVariable inherited

Detailed Description

Definition at line 55 of file SoftSlopeIntegralVariable.h.


Member Typedef Documentation

Reimplemented from PLearn::NaryVariable.

Definition at line 57 of file SoftSlopeIntegralVariable.h.


Constructor & Destructor Documentation

PLearn::SoftSlopeIntegralVariable::SoftSlopeIntegralVariable ( )

Default constructor for persistence.

Definition at line 57 of file SoftSlopeIntegralVariable.cc.

    : a(0), b(0), tabulated(false)
{ }
PLearn::SoftSlopeIntegralVariable::SoftSlopeIntegralVariable ( Variable smoothness,
Variable left,
Variable right,
real  a_ = 0,
real  b_ = 1,
bool  tabulated = true 
)

Definition at line 61 of file SoftSlopeIntegralVariable.cc.

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

Member Function Documentation

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

SoftSlopeIntegralVariable.

Reimplemented from PLearn::NaryVariable.

Definition at line 55 of file SoftSlopeIntegralVariable.cc.

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

Reimplemented from PLearn::NaryVariable.

Definition at line 55 of file SoftSlopeIntegralVariable.cc.

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

Reimplemented from PLearn::NaryVariable.

Definition at line 55 of file SoftSlopeIntegralVariable.cc.

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

Reimplemented from PLearn::NaryVariable.

Definition at line 55 of file SoftSlopeIntegralVariable.cc.

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

Reimplemented from PLearn::Object.

Definition at line 55 of file SoftSlopeIntegralVariable.cc.

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

Reimplemented from PLearn::NaryVariable.

Definition at line 55 of file SoftSlopeIntegralVariable.cc.

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

Implements PLearn::Variable.

Definition at line 125 of file SoftSlopeIntegralVariable.cc.

References a, b, PLearn::fast_exact_is_equal(), PLearn::Variable::gradientdata, i, PLearn::left(), n, PLearn::VarArray::nelems(), PLearn::Variable::nelems(), PLearn::right(), PLearn::softplus(), tabulated, PLearn::tabulated_softplus(), PLearn::Variable::valuedata, and PLearn::NaryVariable::varray.

{
    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* smoothness = varray[0]->valuedata;
    real* left = varray[1]->valuedata;
    real* right = varray[2]->valuedata;
    real* dsmoothness = varray[0]->gradientdata;
    real* dleft = varray[1]->gradientdata;
    real* dright = varray[2]->gradientdata;
    for(int i=0; i<n; i++,smoothness+=m1,left+=m2,right+=m3,dsmoothness+=m1,dleft+=m2,dright+=m3)
    {
        if (fast_exact_is_equal(*smoothness, 0)) continue;
        // soft_slope_integral =
        // (b - a) + (softplus_primitive(-smoothness*(b-right)) - softplus_primitive(-smoothness*(b-left))
        //    -softplus_primitive(-smoothness*(a-right)) + softplus_primitive(-smoothness*(a-left)))/
        //     (smoothness*smoothness*(right-left));
        // hence 
        //
        //  d/dsmoothness = (softplus(-smoothness*(b-right))*(right-b) + softplus(-smoothness*(b-left))*(b-left)
        //                 + softplus(-smoothness*(a-right))*(a-right) + softplus(-smoothness*(a-left))*(left-a))/
        //     (smoothness*smoothness*(right-left))
        //     - 2 * (soft_slope_integral - b + a) / smoothness
        //n
        //  d/dleft = (-softplus(-smoothness*(b-left)) + softplus(-smoothness*(a-left)))/
        //     (smoothness*(right-left))
        //     + (soft_slope_integral - b + a)/ (right-left)
        //
        //  d/dright =  (softplus(-smoothness*(b-right)) - softplus(-smoothness*(a-right)))/(smoothness*(right-left))
        //         - (soft_slope_integral - b + a)/ (right-left)
        //
        real inv_smoothness = 1.0 / *smoothness;
        real br = (b-*right);
        real bl = (b-*left);
        real ar = (a-*right);
        real al = (a-*left);
        real t1 = tabulated?tabulated_softplus(- *smoothness*br):softplus(- *smoothness*br);
        real t2 = tabulated?tabulated_softplus(- *smoothness*bl):softplus(- *smoothness*bl);
        real t3 = tabulated?tabulated_softplus(- *smoothness*ar):softplus(- *smoothness*ar);
        real t4 = tabulated?tabulated_softplus(- *smoothness*al):softplus(- *smoothness*al);
        real inv_delta=1.0/(*right-*left);
        real ssiab = valuedata[i]-b+a;
        *dsmoothness += gradientdata[i] * 
            ((-t1*br + t2*bl + t3*ar - t4*al)*inv_smoothness*inv_delta - 2*ssiab)*inv_smoothness;
        *dleft += gradientdata[i] * ((-t2 + t4)*inv_smoothness + ssiab) * inv_delta;
        *dright += gradientdata[i] * ((t1 - t3)*inv_smoothness - ssiab) * inv_delta;
    }
}

Here is the call graph for this function:

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

Reimplemented from PLearn::Object.

Definition at line 55 of file SoftSlopeIntegralVariable.cc.

void PLearn::SoftSlopeIntegralVariable::declareOptions ( OptionList ol) [static]
static const PPath& PLearn::SoftSlopeIntegralVariable::declaringFile ( ) [inline, static]

Reimplemented from PLearn::NaryVariable.

Definition at line 69 of file SoftSlopeIntegralVariable.h.

{
SoftSlopeIntegralVariable * PLearn::SoftSlopeIntegralVariable::deepCopy ( CopiesMap copies) const [virtual]

Reimplemented from PLearn::NaryVariable.

Definition at line 55 of file SoftSlopeIntegralVariable.cc.

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

compute output given input

Implements PLearn::Variable.

Definition at line 98 of file SoftSlopeIntegralVariable.cc.

References a, b, i, PLearn::left(), n, PLearn::VarArray::nelems(), PLearn::Variable::nelems(), PLearn::right(), PLearn::soft_slope_integral(), tabulated, PLearn::tabulated_soft_slope_integral(), PLearn::Variable::valuedata, and PLearn::NaryVariable::varray.

{
    int n=nelems();
    int n1=varray[0]->nelems();
    int n2=varray[1]->nelems();
    int n3=varray[2]->nelems();
    real* smoothness = 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] = tabulated?tabulated_soft_slope_integral(smoothness[i], left[i], right[i],a,b):soft_slope_integral(smoothness[i], left[i], right[i],a,b);
    else if (n1==1 && n2==n && n3==n)
        for(int i=0; i<n; i++)
            valuedata[i] = tabulated?tabulated_soft_slope_integral(*smoothness, left[i], right[i],a,b):soft_slope_integral(*smoothness, left[i], right[i],a,b);
    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++,smoothness+=m1,left+=m2,right+=m3)
            valuedata[i] = tabulated?tabulated_soft_slope_integral(*smoothness, *left, *right, a, b):soft_slope_integral(*smoothness, *left, *right, a, b);
    }
}

Here is the call graph for this function:

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

Reimplemented from PLearn::Object.

Definition at line 55 of file SoftSlopeIntegralVariable.cc.

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

Reimplemented from PLearn::Object.

Definition at line 55 of file SoftSlopeIntegralVariable.cc.

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

Reimplemented from PLearn::Object.

Definition at line 55 of file SoftSlopeIntegralVariable.cc.

void PLearn::SoftSlopeIntegralVariable::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 77 of file SoftSlopeIntegralVariable.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() && varray[0] && varray[1] && varray[2]) {
        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 SoftSlopeIntegralVariable should either have the same length/width as the others or length 1");
            }
        }
    }
}

Here is the call graph for this function:

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

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

Reimplemented from PLearn::Variable.

Definition at line 179 of file SoftSlopeIntegralVariable.cc.

References PLERROR.

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

Member Data Documentation

Reimplemented from PLearn::NaryVariable.

Definition at line 69 of file SoftSlopeIntegralVariable.h.

Definition at line 61 of file SoftSlopeIntegralVariable.h.

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

Definition at line 61 of file SoftSlopeIntegralVariable.h.

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

Definition at line 62 of file SoftSlopeIntegralVariable.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