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

The first sentence should be a BRIEF DESCRIPTION of what the class does. More...

#include <SumVarianceOfLinearTransformedCategoricals.h>

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

List of all members.

Public Member Functions

 SumVarianceOfLinearTransformedCategoricals ()
 Default constructor.
 SumVarianceOfLinearTransformedCategoricals (Variable *input1, Variable *input2, bool call_build_=true)
 Constructor initializing from two input variables.
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 string classname () const
virtual OptionListgetOptionList () const
virtual OptionMapgetOptionMap () const
virtual RemoteMethodMapgetRemoteMethodMap () const
virtual
SumVarianceOfLinearTransformedCategoricals
deepCopy (CopiesMap &copies) const
virtual void build ()
 Post-constructor.
virtual void makeDeepCopyFromShallowCopy (CopiesMap &copies)
 Transforms a shallow copy into a deep copy.

Static Public Member Functions

static string _classname_ ()
 SumVarianceOfLinearTransformedCategoricals.
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 ()

Public Attributes

TVec< intgroupsizes
 ### declare public option fields (such as build options) here Start your comments with Doxygen-compatible comments such as //!

Static Public Attributes

static StaticInitializer _static_initializer_

Static Protected Member Functions

static void declareOptions (OptionList &ol)
 Declares the class options.

Private Types

typedef BinaryVariable inherited

Private Member Functions

void build_ ()
 This does the actual building.

Private Attributes

Vec group_sum_wik_pk

Detailed Description

The first sentence should be a BRIEF DESCRIPTION of what the class does.

* SumVarianceOfLinearTransformedCategoricals * Place the rest of the class programmer documentation here. Doxygen supports Javadoc-style comments. See http://www.doxygen.org/manual.html

Todo:
Write class to-do's here if there are any.
Deprecated:
Write deprecated stuff here if there is any. Indicate what else should be used instead.

Definition at line 60 of file SumVarianceOfLinearTransformedCategoricals.h.


Member Typedef Documentation

Reimplemented from PLearn::BinaryVariable.

Definition at line 62 of file SumVarianceOfLinearTransformedCategoricals.h.


Constructor & Destructor Documentation

PLearn::SumVarianceOfLinearTransformedCategoricals::SumVarianceOfLinearTransformedCategoricals ( )

Default constructor.

Definition at line 62 of file SumVarianceOfLinearTransformedCategoricals.cc.

    : inherited(0,0,1,1)
{}
PLearn::SumVarianceOfLinearTransformedCategoricals::SumVarianceOfLinearTransformedCategoricals ( Variable input1,
Variable input2,
bool  call_build_ = true 
)

Constructor initializing from two input variables.

Definition at line 66 of file SumVarianceOfLinearTransformedCategoricals.cc.

References build_().

    : inherited(input1, input2, 1, 1, call_build_)
{
    if (call_build_)
        build_();
}

Here is the call graph for this function:


Member Function Documentation

string PLearn::SumVarianceOfLinearTransformedCategoricals::_classname_ ( ) [static]
OptionList & PLearn::SumVarianceOfLinearTransformedCategoricals::_getOptionList_ ( ) [static]

Reimplemented from PLearn::BinaryVariable.

Definition at line 60 of file SumVarianceOfLinearTransformedCategoricals.cc.

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

Reimplemented from PLearn::BinaryVariable.

Definition at line 60 of file SumVarianceOfLinearTransformedCategoricals.cc.

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

Reimplemented from PLearn::BinaryVariable.

Definition at line 60 of file SumVarianceOfLinearTransformedCategoricals.cc.

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

Reimplemented from PLearn::Object.

Definition at line 60 of file SumVarianceOfLinearTransformedCategoricals.cc.

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

Reimplemented from PLearn::BinaryVariable.

Definition at line 60 of file SumVarianceOfLinearTransformedCategoricals.cc.

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

Implements PLearn::Variable.

Definition at line 140 of file SumVarianceOfLinearTransformedCategoricals.cc.

References d, PLearn::TVec< T >::data(), PLearn::Variable::gradient, group_sum_wik_pk, groupsizes, i, PLearn::BinaryVariable::input1, PLearn::BinaryVariable::input2, PLearn::TVec< T >::length(), PLearn::TMat< T >::length(), PLearn::P(), and PLearn::TVec< T >::resize().

{
    Mat P = input1->matValue;
    Mat Pgrad = input1->matGradient;
    Mat W = input2->matValue;
    Mat Wgrad = input2->matGradient;
    int d = W.length();
    int l = P.length();
    // int m = W.width(); // should equal sum of groupsizes

    real gr = gradient[0];

    int ngroups = groupsizes.length();
    const int* pgroupsize = groupsizes.data();    

    group_sum_wik_pk.resize(ngroups);
    real* p_group_sum_wik_pk = group_sum_wik_pk.data();

    for(int t=0; t<l; t++)
    {
        const real* p = P[t];
        real* gp = Pgrad[t];
        for(int i=0; i<d; i++)
        {
            const real* Wi = W[i];
            int k = 0;
            for(int groupnum=0; groupnum<ngroups; groupnum++)
            {
                int gs = pgroupsize[groupnum];
                double sum_wik_pk = 0;
                while(gs--)
                {
                    sum_wik_pk += Wi[k]*p[k];
                    k++;
                }
                p_group_sum_wik_pk[groupnum] = sum_wik_pk;
            }
                    
            real* gWi = Wgrad[i];
            k = 0;
            for(int groupnum=0; groupnum<ngroups; groupnum++)
            {
                int gs = pgroupsize[groupnum];
                real grsum = p_group_sum_wik_pk[groupnum];
                while(gs--)
                {
                    real Wik = Wi[k];
                    gWi[k] += gr*2*p[k]*(Wik-grsum);
                    gp[k] += gr*Wik*(Wik-2*grsum);
                    k++;
                }
            }
        }
    }

}

Here is the call graph for this function:

void PLearn::SumVarianceOfLinearTransformedCategoricals::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 204 of file SumVarianceOfLinearTransformedCategoricals.cc.

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

Here is the call graph for this function:

void PLearn::SumVarianceOfLinearTransformedCategoricals::build_ ( ) [private]

This does the actual building.

Reimplemented from PLearn::BinaryVariable.

Definition at line 244 of file SumVarianceOfLinearTransformedCategoricals.cc.

Referenced by build(), and SumVarianceOfLinearTransformedCategoricals().

{
    // ### This method should do the real building of the object,
    // ### according to set 'options', in *any* situation.
    // ### Typical situations include:
    // ###  - Initial building of an object from a few user-specified options
    // ###  - Building of a "reloaded" object: i.e. from the complete set of
    // ###    all serialised options.
    // ###  - Updating or "re-building" of an object after a few "tuning"
    // ###    options have been modified.
    // ### You should assume that the parent class' build_() has already been
    // ### called.
}

Here is the caller graph for this function:

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

Reimplemented from PLearn::Object.

Definition at line 60 of file SumVarianceOfLinearTransformedCategoricals.cc.

void PLearn::SumVarianceOfLinearTransformedCategoricals::declareOptions ( OptionList ol) [static, protected]

Declares the class options.

Reimplemented from PLearn::BinaryVariable.

Definition at line 226 of file SumVarianceOfLinearTransformedCategoricals.cc.

References PLearn::OptionBase::buildoption, PLearn::declareOption(), PLearn::BinaryVariable::declareOptions(), and groupsizes.

{
    // ### Declare all of this object's options here.
    // ### For the "flags" of each option, you should typically specify
    // ### one of OptionBase::buildoption, OptionBase::learntoption or
    // ### OptionBase::tuningoption. If you don't provide one of these three,
    // ### this option will be ignored when loading values from a script.
    // ### You can also combine flags, for example with OptionBase::nosave:
    // ### (OptionBase::buildoption | OptionBase::nosave)

    declareOption(ol, "groupsizes", &SumVarianceOfLinearTransformedCategoricals::groupsizes,
                  OptionBase::buildoption,
                  "defines the dimensions of the categorical variables.");

    // Now call the parent class' declareOptions
    inherited::declareOptions(ol);
}

Here is the call graph for this function:

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

Reimplemented from PLearn::BinaryVariable.

Definition at line 105 of file SumVarianceOfLinearTransformedCategoricals.h.

:
    //#####  Protected Options  ###############################################
SumVarianceOfLinearTransformedCategoricals * PLearn::SumVarianceOfLinearTransformedCategoricals::deepCopy ( CopiesMap copies) const [virtual]

Reimplemented from PLearn::BinaryVariable.

Definition at line 60 of file SumVarianceOfLinearTransformedCategoricals.cc.

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

compute output given input

Implements PLearn::Variable.

Definition at line 95 of file SumVarianceOfLinearTransformedCategoricals.cc.

References d, PLearn::TVec< T >::data(), groupsizes, i, PLearn::BinaryVariable::input1, PLearn::BinaryVariable::input2, PLearn::TVec< T >::length(), PLearn::TMat< T >::length(), PLearn::P(), PLERROR, PLearn::Variable::value, and PLearn::Var::width().

{
    if(input1.width()!=input2.width())
        PLERROR("Incompatible sizes: width of P (input1) must equal width of W (input2)"); 

    Mat P = input1->matValue;
    Mat W = input2->matValue;
    int d = W.length();
    int l = P.length();
    // int m = W.width(); // should equal sum of groupsizes

    double simplesum = 0;
    double sqsum = 0;

    int ngroups = groupsizes.length();
    const int* pgroupsize = groupsizes.data();

    for(int t=0; t<l; t++)
    {
        const real* p = P[t];
        for(int i=0; i<d; i++)
        {
            const real* Wi = W[i];
            int k = 0;
            for(int groupnum=0; groupnum<ngroups; groupnum++)
            {
                double tmpsqsum = 0;
                int gs = pgroupsize[groupnum];
                while(gs--)
                {
                    real Wik = Wi[k];
                    real pk = p[k];
                    real Wik_pk = Wik*pk;
                    simplesum += Wik*Wik_pk;
                    tmpsqsum += Wik_pk;
                    k++;
                }
                sqsum += tmpsqsum*tmpsqsum;
            }
        }
    }
    value[0] = simplesum-sqsum;
}

Here is the call graph for this function:

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

Reimplemented from PLearn::Object.

Definition at line 60 of file SumVarianceOfLinearTransformedCategoricals.cc.

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

Reimplemented from PLearn::Object.

Definition at line 60 of file SumVarianceOfLinearTransformedCategoricals.cc.

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

Reimplemented from PLearn::Object.

Definition at line 60 of file SumVarianceOfLinearTransformedCategoricals.cc.

void PLearn::SumVarianceOfLinearTransformedCategoricals::makeDeepCopyFromShallowCopy ( CopiesMap copies) [virtual]

Transforms a shallow copy into a deep copy.

Reimplemented from PLearn::BinaryVariable.

Definition at line 210 of file SumVarianceOfLinearTransformedCategoricals.cc.

References PLearn::deepCopyField(), group_sum_wik_pk, groupsizes, and PLearn::BinaryVariable::makeDeepCopyFromShallowCopy().

{
    inherited::makeDeepCopyFromShallowCopy(copies);

    // ### Call deepCopyField on all "pointer-like" fields
    // ### that you wish to be deepCopied rather than
    // ### shallow-copied.
    // ### ex:
    // deepCopyField(trainvec, copies);
    deepCopyField(groupsizes, copies);
    deepCopyField(group_sum_wik_pk, copies);

    // ### If you want to deepCopy a Var field:
    // varDeepCopyField(somevariable, copies);
}

Here is the call graph for this function:

void PLearn::SumVarianceOfLinearTransformedCategoricals::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 SumVarianceOfLinearTransformedCategoricals.cc.

{
    l = 1;
    w = 1;
}

Member Data Documentation

Reimplemented from PLearn::BinaryVariable.

Definition at line 105 of file SumVarianceOfLinearTransformedCategoricals.h.

### declare public option fields (such as build options) here Start your comments with Doxygen-compatible comments such as //!

Definition at line 69 of file SumVarianceOfLinearTransformedCategoricals.h.

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


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