PLearn 0.1
|
#include <NegLogPoissonVariable.h>
Public Member Functions | |
NegLogPoissonVariable () | |
Default constructor for persistence. | |
NegLogPoissonVariable (VarArray &the_varray) | |
virtual string | classname () const |
virtual OptionList & | getOptionList () const |
virtual OptionMap & | getOptionMap () const |
virtual RemoteMethodMap & | getRemoteMethodMap () const |
virtual NegLogPoissonVariable * | deepCopy (CopiesMap &copies) const |
virtual void | build () |
Post-constructor. | |
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 () |
Static Public Member Functions | |
static string | _classname_ () |
NegLogPoissonVariable. | |
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 () |
Public Attributes | |
bool | scaled_targets |
Static Public Attributes | |
static StaticInitializer | _static_initializer_ |
Protected Member Functions | |
void | build_ () |
Object-specific post-constructor. | |
Protected Attributes | |
bool | has_weight |
Private Types | |
typedef NaryVariable | inherited |
Definition at line 52 of file NegLogPoissonVariable.h.
typedef NaryVariable PLearn::NegLogPoissonVariable::inherited [private] |
Reimplemented from PLearn::NaryVariable.
Definition at line 54 of file NegLogPoissonVariable.h.
PLearn::NegLogPoissonVariable::NegLogPoissonVariable | ( | ) | [inline] |
PLearn::NegLogPoissonVariable::NegLogPoissonVariable | ( | VarArray & | the_varray | ) |
Definition at line 67 of file NegLogPoissonVariable.cc.
References build_().
string PLearn::NegLogPoissonVariable::_classname_ | ( | ) | [static] |
Reimplemented from PLearn::NaryVariable.
Definition at line 57 of file NegLogPoissonVariable.cc.
OptionList & PLearn::NegLogPoissonVariable::_getOptionList_ | ( | ) | [static] |
Reimplemented from PLearn::NaryVariable.
Definition at line 57 of file NegLogPoissonVariable.cc.
RemoteMethodMap & PLearn::NegLogPoissonVariable::_getRemoteMethodMap_ | ( | ) | [static] |
Reimplemented from PLearn::NaryVariable.
Definition at line 57 of file NegLogPoissonVariable.cc.
Reimplemented from PLearn::NaryVariable.
Definition at line 57 of file NegLogPoissonVariable.cc.
Object * PLearn::NegLogPoissonVariable::_new_instance_for_typemap_ | ( | ) | [static] |
Reimplemented from PLearn::Object.
Definition at line 57 of file NegLogPoissonVariable.cc.
StaticInitializer NegLogPoissonVariable::_static_initializer_ & PLearn::NegLogPoissonVariable::_static_initialize_ | ( | ) | [static] |
Reimplemented from PLearn::NaryVariable.
Definition at line 57 of file NegLogPoissonVariable.cc.
void PLearn::NegLogPoissonVariable::bprop | ( | ) | [virtual] |
Implements PLearn::Variable.
Definition at line 117 of file NegLogPoissonVariable.cc.
References PLearn::exp(), PLearn::Variable::gradient, i, PLearn::TVec< T >::size(), PLearn::Variable::valuedata, and PLearn::NaryVariable::varray.
{ real gr = gradient[0]; for (int i=0; i<varray[0]->size(); i++) { real output = varray[0]->valuedata[i]; real target = varray[1]->valuedata[i]; real weight = 1; if (varray.size()>2) weight = varray[2]->valuedata[i]; if (weight > 0) varray[0]->gradientdata[i] += gr * ( exp(output) - target / weight); // varray[0]->gradientdata[i] += gr* ( exp(output) * weight - target); } }
void PLearn::NegLogPoissonVariable::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::NaryVariable.
Definition at line 74 of file NegLogPoissonVariable.cc.
References PLearn::NaryVariable::build(), and build_().
{ inherited::build(); build_(); }
void PLearn::NegLogPoissonVariable::build_ | ( | ) | [protected] |
Object-specific post-constructor.
This method should be redefined in subclasses and do the actual building of the object according to previously set option fields. Constructors can just set option fields, and then call build_. This method is NOT virtual, and will typically be called only from three places: a constructor, the public virtual build()
method, and possibly the public virtual read method (which calls its parent's read). build_()
can assume that its parent's build_()
has already been called.
Reimplemented from PLearn::NaryVariable.
Definition at line 81 of file NegLogPoissonVariable.cc.
References PLERROR, PLearn::TVec< T >::size(), PLearn::Variable::size(), and PLearn::NaryVariable::varray.
Referenced by build(), and NegLogPoissonVariable().
{ if (varray[0] && varray[1] && (varray[0]->size() != varray[1]->size())) PLERROR("In NegLogPoissonVariable: netout and target must have the same size"); if (varray.size()>2 && varray[0] && varray[2] && (varray[0]->size() != varray[2]->size())) PLERROR("In NegLogPoissonVariable: netout and weight must have the same size"); }
string PLearn::NegLogPoissonVariable::classname | ( | ) | const [virtual] |
Reimplemented from PLearn::Object.
Definition at line 57 of file NegLogPoissonVariable.cc.
static const PPath& PLearn::NegLogPoissonVariable::declaringFile | ( | ) | [inline, static] |
Reimplemented from PLearn::NaryVariable.
Definition at line 61 of file NegLogPoissonVariable.h.
: void build_();
NegLogPoissonVariable * PLearn::NegLogPoissonVariable::deepCopy | ( | CopiesMap & | copies | ) | const [virtual] |
Reimplemented from PLearn::NaryVariable.
Definition at line 57 of file NegLogPoissonVariable.cc.
void PLearn::NegLogPoissonVariable::fprop | ( | ) | [virtual] |
compute output given input
Implements PLearn::Variable.
Definition at line 92 of file NegLogPoissonVariable.cc.
References PLearn::exp(), i, PLearn::is_missing(), PLearn::max(), PLearn::pl_gammln(), pl_log, PLERROR, PLearn::TVec< T >::size(), PLearn::Variable::valuedata, and PLearn::NaryVariable::varray.
{ real cost = 0.0; for (int i=0; i<varray[0]->size(); i++) { real output = varray[0]->valuedata[i]; real target = varray[1]->valuedata[i]; real weight = 1; if (varray.size()>2) weight = varray[2]->valuedata[i]; static real EPSILON = 1e-8; // Regularization real log_fact_target = pl_gammln(max(target, EPSILON)+1); // cost += exp(output) * weight - (output + pl_log(weight) ) * target + log_fact_target; if (weight > 0) cost += exp(output) - (output + pl_log(weight)) * target / weight + log_fact_target / weight; } if (is_missing(cost)) PLERROR("NegLogPoissonVariable::fprop: encountered NaN cost"); valuedata[0] = cost; }
OptionList & PLearn::NegLogPoissonVariable::getOptionList | ( | ) | const [virtual] |
Reimplemented from PLearn::Object.
Definition at line 57 of file NegLogPoissonVariable.cc.
OptionMap & PLearn::NegLogPoissonVariable::getOptionMap | ( | ) | const [virtual] |
Reimplemented from PLearn::Object.
Definition at line 57 of file NegLogPoissonVariable.cc.
RemoteMethodMap & PLearn::NegLogPoissonVariable::getRemoteMethodMap | ( | ) | const [virtual] |
Reimplemented from PLearn::Object.
Definition at line 57 of file NegLogPoissonVariable.cc.
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 89 of file NegLogPoissonVariable.cc.
{ l=1, w=1; }
Reimplemented from PLearn::NaryVariable.
Definition at line 61 of file NegLogPoissonVariable.h.
bool PLearn::NegLogPoissonVariable::has_weight [protected] |
Definition at line 78 of file NegLogPoissonVariable.h.
Definition at line 74 of file NegLogPoissonVariable.h.