PLearn 0.1
|
The first sentence should be a BRIEF DESCRIPTION of what the class does. More...
#include <SumEntropyOfBernoullis.h>
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 OptionList & | getOptionList () const |
virtual OptionMap & | getOptionMap () const |
virtual RemoteMethodMap & | getRemoteMethodMap () const |
virtual SumEntropyOfBernoullis * | 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_ () |
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 PPath & | declaringFile () |
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. |
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
Definition at line 60 of file SumEntropyOfBernoullis.h.
typedef UnaryVariable PLearn::SumEntropyOfBernoullis::inherited [private] |
Reimplemented from PLearn::UnaryVariable.
Definition at line 62 of file SumEntropyOfBernoullis.h.
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 | ) |
string PLearn::SumEntropyOfBernoullis::_classname_ | ( | ) | [static] |
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.
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) ); } } }
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_().
{ inherited::build(); build_(); }
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. }
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); }
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; }
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().
{ inherited::makeDeepCopyFromShallowCopy(copies); }
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; }
Reimplemented from PLearn::UnaryVariable.
Definition at line 103 of file SumEntropyOfBernoullis.h.