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

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

#include <SumEntropyOfBernoullis.h>

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

List of all members.

Public Member Functions

 SumEntropyOfBernoullis ()
 ### declare public option fields (such as build options) here Start your comments with Doxygen-compatible comments such as //!
 SumEntropyOfBernoullis (Variable *input)
 Constructor initializing from input variable.
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 ()
 Nothing to do by default.
virtual void bprop ()
 Nothing to do by default.
virtual string classname () const
virtual OptionListgetOptionList () const
virtual OptionMapgetOptionMap () const
virtual RemoteMethodMapgetRemoteMethodMap () const
virtual SumEntropyOfBernoullisdeepCopy (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_ ()
 SumEntropyOfBernoullis.
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_

Static Protected Member Functions

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

Private Types

typedef UnaryVariable inherited

Private Member Functions

void build_ ()
 This does the actual building.

Detailed Description

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

* SumEntropyOfBernoullis * 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 SumEntropyOfBernoullis.h.


Member Typedef Documentation

Reimplemented from PLearn::UnaryVariable.

Definition at line 62 of file SumEntropyOfBernoullis.h.


Constructor & Destructor Documentation

PLearn::SumEntropyOfBernoullis::SumEntropyOfBernoullis ( )

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

Default constructor, usually does nothing

Definition at line 53 of file SumEntropyOfBernoullis.cc.

    : inherited(0, 1, 1)
{
}
PLearn::SumEntropyOfBernoullis::SumEntropyOfBernoullis ( Variable input)

Constructor initializing from input variable.

Definition at line 59 of file SumEntropyOfBernoullis.cc.

References build_().

    : inherited(input, 1, 1)
{
    build_();
}

Here is the call graph for this function:


Member Function Documentation

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

SumEntropyOfBernoullis.

Reimplemented from PLearn::UnaryVariable.

Definition at line 51 of file SumEntropyOfBernoullis.cc.

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

Reimplemented from PLearn::UnaryVariable.

Definition at line 51 of file SumEntropyOfBernoullis.cc.

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

Reimplemented from PLearn::UnaryVariable.

Definition at line 51 of file SumEntropyOfBernoullis.cc.

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

Reimplemented from PLearn::UnaryVariable.

Definition at line 51 of file SumEntropyOfBernoullis.cc.

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

Reimplemented from PLearn::UnaryVariable.

Definition at line 51 of file SumEntropyOfBernoullis.cc.

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

Reimplemented from PLearn::UnaryVariable.

Definition at line 51 of file SumEntropyOfBernoullis.cc.

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

Nothing to do by default.

Reimplemented from PLearn::UnaryVariable.

Definition at line 100 of file SumEntropyOfBernoullis.cc.

References PLearn::Variable::gradientdata, i, PLearn::UnaryVariable::input, j, PLearn::TMat< T >::length(), PLearn::P(), pl_log, and PLearn::TMat< T >::width().

{
    /*
      -[p log(p) + (1-p) log(1-p)]' = -[log(p) + 1 - log(1-p) - 1 ]
                                    = log(1-p) - log(p)
    */
    real gr = gradientdata[0];
    Mat P = input->matValue;
    Mat Pgr = input->matGradient;
    for(int i=0; i<Pgr.length(); i++)
    {
        const real* P_i = P[i];
        real* Pgr_i = Pgr[i];
        for(int j=0; j<Pgr.width(); j++)
        {
            double P_ij = P_i[j];
            double one_minus_P_ij = 1-P_ij;
            if(P_ij<1e-25) 
                P_ij = 1e-25;
            if(one_minus_P_ij<1e-25)
                one_minus_P_ij = 1e-25;
            Pgr_i[j] += gr*( pl_log(one_minus_P_ij) - pl_log(P_ij) );
        }
    }
    

}

Here is the call graph for this function:

void PLearn::SumEntropyOfBernoullis::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::UnaryVariable.

Definition at line 135 of file SumEntropyOfBernoullis.cc.

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

Here is the call graph for this function:

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

This does the actual building.

Reimplemented from PLearn::UnaryVariable.

Definition at line 166 of file SumEntropyOfBernoullis.cc.

Referenced by build(), and SumEntropyOfBernoullis().

{
    // ### 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::SumEntropyOfBernoullis::classname ( ) const [virtual]

Reimplemented from PLearn::UnaryVariable.

Definition at line 51 of file SumEntropyOfBernoullis.cc.

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

Declares the class options.

Reimplemented from PLearn::UnaryVariable.

Definition at line 146 of file SumEntropyOfBernoullis.cc.

References PLearn::UnaryVariable::declareOptions().

{
    // ### 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)

    // ### ex:
    // declareOption(ol, "myoption", &SumEntropyOfBernoullis::myoption,
    //               OptionBase::buildoption,
    //               "Help text describing this option");
    // ...

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

Here is the call graph for this function:

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

Reimplemented from PLearn::UnaryVariable.

Definition at line 103 of file SumEntropyOfBernoullis.h.

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

Reimplemented from PLearn::UnaryVariable.

Definition at line 51 of file SumEntropyOfBernoullis.cc.

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

Nothing to do by default.

Reimplemented from PLearn::UnaryVariable.

Definition at line 82 of file SumEntropyOfBernoullis.cc.

References i, PLearn::UnaryVariable::input, j, PLearn::TMat< T >::length(), PLearn::P(), pl_log, PLearn::Variable::valuedata, and PLearn::TMat< T >::width().

{
    double res = 0;
    Mat P = input->matValue;
    for(int i=0; i<P.length(); i++)
    {
        const real* P_i = P[i];
        for(int j=0; j<P.width(); j++)
        {
            double P_ij = P_i[j];
            if( (P_ij>1e-25) && ((1-P_ij)>1e-25) )
                res -= P_ij*pl_log(P_ij) + (1-P_ij)*pl_log(1-P_ij);
        }
    }
    valuedata[0] = (real)res;
}

Here is the call graph for this function:

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

Reimplemented from PLearn::UnaryVariable.

Definition at line 51 of file SumEntropyOfBernoullis.cc.

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

Reimplemented from PLearn::UnaryVariable.

Definition at line 51 of file SumEntropyOfBernoullis.cc.

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

Reimplemented from PLearn::UnaryVariable.

Definition at line 51 of file SumEntropyOfBernoullis.cc.

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

Transforms a shallow copy into a deep copy.

Reimplemented from PLearn::UnaryVariable.

Definition at line 141 of file SumEntropyOfBernoullis.cc.

References PLearn::UnaryVariable::makeDeepCopyFromShallowCopy().

Here is the call graph for this function:

void PLearn::SumEntropyOfBernoullis::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 76 of file SumEntropyOfBernoullis.cc.

{
    l = w = 1;
}

Member Data Documentation

Reimplemented from PLearn::UnaryVariable.

Definition at line 103 of file SumEntropyOfBernoullis.h.


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