PLearn 0.1
|
WeightsVariable updated online, based on negative log-likelihood of the neighbors. More...
#include <NLLNeighborhoodWeightsVariable.h>
Public Member Functions | |
NLLNeighborhoodWeightsVariable () | |
Default constructor, usually does nothing. | |
NLLNeighborhoodWeightsVariable (Variable *neighbor_nlls, Variable *neighbor_indexes, int n, real alpha) | |
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 OptionList & | getOptionList () const |
virtual OptionMap & | getOptionMap () const |
virtual RemoteMethodMap & | getRemoteMethodMap () const |
virtual NLLNeighborhoodWeightsVariable * | 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_ () |
NLLNeighborhoodWeightsVariable. | |
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 | |
int | n |
Total number of points to be weighted. | |
real | alpha |
Exponential decay. | |
Static Public Attributes | |
static StaticInitializer | _static_initializer_ |
Static Protected Member Functions | |
static void | declareOptions (OptionList &ol) |
Declares the class options. | |
Protected Attributes | |
TVec< real > | online_weights_log_sum |
Online log-sum of weights. | |
real | log_alpha |
log(alpha) | |
real | log_1_minus_alpha |
Private Types | |
typedef BinaryVariable | inherited |
Private Member Functions | |
void | build_ () |
This does the actual building. |
WeightsVariable updated online, based on negative log-likelihood of the neighbors.
* NLLNeighborhoodWeightsVariable *
Definition at line 53 of file NLLNeighborhoodWeightsVariable.h.
typedef BinaryVariable PLearn::NLLNeighborhoodWeightsVariable::inherited [private] |
Reimplemented from PLearn::BinaryVariable.
Definition at line 55 of file NLLNeighborhoodWeightsVariable.h.
PLearn::NLLNeighborhoodWeightsVariable::NLLNeighborhoodWeightsVariable | ( | ) |
Default constructor, usually does nothing.
Definition at line 55 of file NLLNeighborhoodWeightsVariable.cc.
string PLearn::NLLNeighborhoodWeightsVariable::_classname_ | ( | ) | [static] |
NLLNeighborhoodWeightsVariable.
Reimplemented from PLearn::BinaryVariable.
Definition at line 53 of file NLLNeighborhoodWeightsVariable.cc.
OptionList & PLearn::NLLNeighborhoodWeightsVariable::_getOptionList_ | ( | ) | [static] |
Reimplemented from PLearn::BinaryVariable.
Definition at line 53 of file NLLNeighborhoodWeightsVariable.cc.
RemoteMethodMap & PLearn::NLLNeighborhoodWeightsVariable::_getRemoteMethodMap_ | ( | ) | [static] |
Reimplemented from PLearn::BinaryVariable.
Definition at line 53 of file NLLNeighborhoodWeightsVariable.cc.
Reimplemented from PLearn::BinaryVariable.
Definition at line 53 of file NLLNeighborhoodWeightsVariable.cc.
Object * PLearn::NLLNeighborhoodWeightsVariable::_new_instance_for_typemap_ | ( | ) | [static] |
Reimplemented from PLearn::Object.
Definition at line 53 of file NLLNeighborhoodWeightsVariable.cc.
StaticInitializer NLLNeighborhoodWeightsVariable::_static_initializer_ & PLearn::NLLNeighborhoodWeightsVariable::_static_initialize_ | ( | ) | [static] |
Reimplemented from PLearn::BinaryVariable.
Definition at line 53 of file NLLNeighborhoodWeightsVariable.cc.
void PLearn::NLLNeighborhoodWeightsVariable::bprop | ( | ) | [virtual] |
void PLearn::NLLNeighborhoodWeightsVariable::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 114 of file NLLNeighborhoodWeightsVariable.cc.
References PLearn::BinaryVariable::build(), and build_().
Referenced by NLLNeighborhoodWeightsVariable().
{ inherited::build(); build_(); }
void PLearn::NLLNeighborhoodWeightsVariable::build_ | ( | ) | [private] |
This does the actual building.
Reimplemented from PLearn::BinaryVariable.
Definition at line 143 of file NLLNeighborhoodWeightsVariable.cc.
References alpha, PLearn::TVec< T >::fill(), PLearn::BinaryVariable::input1, PLearn::BinaryVariable::input2, log_1_minus_alpha, log_alpha, MISSING_VALUE, n, online_weights_log_sum, pl_log, PLERROR, PLearn::TVec< T >::resize(), and PLearn::Var::width().
Referenced by build().
{ if(input1 && input2) { if(n<=0) PLERROR("In NLLNeighborhoodWeightsVariable::build_(): n must be > 0"); if(alpha <= 0 || alpha >= 1) PLERROR("In NLLNeighborhoodWeightsVariable::build_(): alpha must be in ]0,1["); log_alpha = pl_log(alpha); log_1_minus_alpha = pl_log(1-alpha); online_weights_log_sum.resize(n); online_weights_log_sum.fill(MISSING_VALUE); if(input1->width() != 1) PLERROR("In NLLNeighborhoodWeightsVariable::build_(): input1 must be column vector"); if(input2->width() != 1) PLERROR("In NLLNeighborhoodWeightsVariable::build_(): input2 must be column vector"); if(input1->size() != input2->size()) PLERROR("In NLLNeighborhoodWeightsVariable::build_(): input1 and input2 must be of same size"); } }
string PLearn::NLLNeighborhoodWeightsVariable::classname | ( | ) | const [virtual] |
Reimplemented from PLearn::Object.
Definition at line 53 of file NLLNeighborhoodWeightsVariable.cc.
void PLearn::NLLNeighborhoodWeightsVariable::declareOptions | ( | OptionList & | ol | ) | [static, protected] |
Declares the class options.
Reimplemented from PLearn::BinaryVariable.
Definition at line 129 of file NLLNeighborhoodWeightsVariable.cc.
References alpha, PLearn::OptionBase::buildoption, PLearn::declareOption(), PLearn::BinaryVariable::declareOptions(), and n.
{ declareOption(ol, "n", &NLLNeighborhoodWeightsVariable::n, OptionBase::buildoption, "Total number of points to be weighted"); declareOption(ol, "alpha", &NLLNeighborhoodWeightsVariable::alpha, OptionBase::buildoption, "Exponential decay"); // Now call the parent class' declareOptions inherited::declareOptions(ol); }
static const PPath& PLearn::NLLNeighborhoodWeightsVariable::declaringFile | ( | ) | [inline, static] |
Reimplemented from PLearn::BinaryVariable.
Definition at line 90 of file NLLNeighborhoodWeightsVariable.h.
:
//##### Protected Options ###############################################
NLLNeighborhoodWeightsVariable * PLearn::NLLNeighborhoodWeightsVariable::deepCopy | ( | CopiesMap & | copies | ) | const [virtual] |
Reimplemented from PLearn::BinaryVariable.
Definition at line 53 of file NLLNeighborhoodWeightsVariable.cc.
void PLearn::NLLNeighborhoodWeightsVariable::fprop | ( | ) | [virtual] |
compute output given input
Implements PLearn::Variable.
Definition at line 76 of file NLLNeighborhoodWeightsVariable.cc.
References PLearn::exp(), i, PLearn::BinaryVariable::input1, PLearn::BinaryVariable::input2, PLearn::is_missing(), PLearn::TVec< T >::length(), PLearn::Variable::length(), log_1_minus_alpha, log_alpha, PLearn::logadd(), n, online_weights_log_sum, PLERROR, and PLearn::Variable::valuedata.
{ int index; for(int i=0; i<length(); i++) { index = (int)input2->valuedata[i]; #ifdef BOUNDCHECK if(index < 0 || index >= online_weights_log_sum.length()) PLERROR("In NLLNeighborhoodWeightsVariable::fprop(): input2->valuedata[%d] should be between 0 and n=%d",index,n); #endif if(is_missing(online_weights_log_sum[index])) { online_weights_log_sum[index] = -1*input1->valuedata[i]; } else { online_weights_log_sum[index] = logadd(log_1_minus_alpha + online_weights_log_sum[index], log_alpha - input1->valuedata[i]); } } for(int i=0; i<length(); i++) { valuedata[i] = exp(-input1->valuedata[i] - online_weights_log_sum[(int)input2->valuedata[i]]); } //cout << "weights="<< value << endl; }
OptionList & PLearn::NLLNeighborhoodWeightsVariable::getOptionList | ( | ) | const [virtual] |
Reimplemented from PLearn::Object.
Definition at line 53 of file NLLNeighborhoodWeightsVariable.cc.
OptionMap & PLearn::NLLNeighborhoodWeightsVariable::getOptionMap | ( | ) | const [virtual] |
Reimplemented from PLearn::Object.
Definition at line 53 of file NLLNeighborhoodWeightsVariable.cc.
RemoteMethodMap & PLearn::NLLNeighborhoodWeightsVariable::getRemoteMethodMap | ( | ) | const [virtual] |
Reimplemented from PLearn::Object.
Definition at line 53 of file NLLNeighborhoodWeightsVariable.cc.
void PLearn::NLLNeighborhoodWeightsVariable::makeDeepCopyFromShallowCopy | ( | CopiesMap & | copies | ) | [virtual] |
Transforms a shallow copy into a deep copy.
Reimplemented from PLearn::BinaryVariable.
Definition at line 120 of file NLLNeighborhoodWeightsVariable.cc.
References PLearn::deepCopyField(), PLearn::BinaryVariable::makeDeepCopyFromShallowCopy(), and online_weights_log_sum.
{ inherited::makeDeepCopyFromShallowCopy(copies); deepCopyField(online_weights_log_sum, copies); //PLERROR("NLLNeighborhoodWeightsVariable::makeDeepCopyFromShallowCopy not fully (correctly) implemented yet!"); }
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 67 of file NLLNeighborhoodWeightsVariable.cc.
References PLearn::BinaryVariable::input1, PLearn::BinaryVariable::input2, and PLearn::Var::length().
Reimplemented from PLearn::BinaryVariable.
Definition at line 90 of file NLLNeighborhoodWeightsVariable.h.
Exponential decay.
Definition at line 63 of file NLLNeighborhoodWeightsVariable.h.
Referenced by build_(), and declareOptions().
Definition at line 106 of file NLLNeighborhoodWeightsVariable.h.
log(alpha)
Definition at line 105 of file NLLNeighborhoodWeightsVariable.h.
Total number of points to be weighted.
Definition at line 61 of file NLLNeighborhoodWeightsVariable.h.
Referenced by build_(), declareOptions(), and fprop().
Online log-sum of weights.
Definition at line 103 of file NLLNeighborhoodWeightsVariable.h.
Referenced by build_(), fprop(), and makeDeepCopyFromShallowCopy().