PLearn 0.1
|
#include <PotentialsVariable.h>
Public Member Functions | |
PotentialsVariable () | |
protected default constructor for persistence | |
PotentialsVariable (Var the_input, Var the_comp_input, Var the_dp_target, Var the_target_dist_rep, Var output, VarArray params, VMat the_distr) | |
virtual string | classname () const |
virtual OptionList & | getOptionList () const |
virtual OptionMap & | getOptionMap () const |
virtual RemoteMethodMap & | getRemoteMethodMap () const |
virtual PotentialsVariable * | 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 | makeDeepCopyFromShallowCopy (CopiesMap &copies) |
Does the necessary operations to transform a shallow copy (this) into a deep copy by deep-copying all the members that need to be. | |
virtual void | fprop () |
compute output given input | |
virtual void | bprop () |
virtual void | symbolicBprop () |
compute a piece of new Var graph that represents the symbolic derivative of this Var | |
virtual void | rfprop () |
Static Public Member Functions | |
static string | _classname_ () |
PotentialsVariable. | |
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 void | declareOptions (OptionList &ol) |
Default constructor for persistence. | |
Public Attributes | |
VMat | distr |
Var | input |
Var | output |
Var | comp_input |
Var | dp_target |
Var | target_dist_reps |
VarArray | params |
Static Public Attributes | |
static StaticInitializer | _static_initializer_ |
Protected Member Functions | |
void | build_ () |
Object-specific post-constructor. | |
Protected Attributes | |
TVec< VarArray > | temp_comps |
Temporary computations. | |
VarArray | proppath |
Vec | values |
Private Types | |
typedef NaryVariable | inherited |
Definition at line 52 of file PotentialsVariable.h.
typedef NaryVariable PLearn::PotentialsVariable::inherited [private] |
Reimplemented from PLearn::NaryVariable.
Definition at line 54 of file PotentialsVariable.h.
PLearn::PotentialsVariable::PotentialsVariable | ( | ) | [inline] |
protected default constructor for persistence
Definition at line 76 of file PotentialsVariable.h.
{}
PLearn::PotentialsVariable::PotentialsVariable | ( | Var | the_input, |
Var | the_comp_input, | ||
Var | the_dp_target, | ||
Var | the_target_dist_rep, | ||
Var | output, | ||
VarArray | params, | ||
VMat | the_distr | ||
) |
Definition at line 57 of file PotentialsVariable.cc.
References build_().
: inherited(the_input & the_comp_input & the_dp_target & the_params & the_target_dist_reps, 2, // Temporary value 1 // idem ), distr(the_distr), input(the_input), output(the_output), comp_input(the_comp_input), dp_target(the_dp_target), target_dist_reps(the_target_dist_reps), params(the_params) { build_(); }
string PLearn::PotentialsVariable::_classname_ | ( | ) | [static] |
Reimplemented from PLearn::NaryVariable.
Definition at line 55 of file PotentialsVariable.cc.
OptionList & PLearn::PotentialsVariable::_getOptionList_ | ( | ) | [static] |
Reimplemented from PLearn::NaryVariable.
Definition at line 55 of file PotentialsVariable.cc.
RemoteMethodMap & PLearn::PotentialsVariable::_getRemoteMethodMap_ | ( | ) | [static] |
Reimplemented from PLearn::NaryVariable.
Definition at line 55 of file PotentialsVariable.cc.
Reimplemented from PLearn::NaryVariable.
Definition at line 55 of file PotentialsVariable.cc.
Object * PLearn::PotentialsVariable::_new_instance_for_typemap_ | ( | ) | [static] |
Reimplemented from PLearn::Object.
Definition at line 55 of file PotentialsVariable.cc.
StaticInitializer PotentialsVariable::_static_initializer_ & PLearn::PotentialsVariable::_static_initialize_ | ( | ) | [static] |
Reimplemented from PLearn::NaryVariable.
Definition at line 55 of file PotentialsVariable.cc.
void PLearn::PotentialsVariable::bprop | ( | ) | [virtual] |
Implements PLearn::Variable.
Definition at line 182 of file PotentialsVariable.cc.
References PLearn::VarArray::bprop(), PLearn::VarArray::clearGradient(), PLearn::TVec< T >::data(), dp_target, PLearn::Variable::gradient, i, j, PLearn::Variable::length(), output, proppath, PLearn::TVec< T >::size(), target_dist_reps, temp_comps, and values.
{ for(int i=0; i<length(); i++) { // Point to temp_comps for values and gradients of proppath for(int j=0; j<proppath.size(); j++) { proppath[j]->matValue = temp_comps[i][j]->matValue; proppath[j]->value = proppath[j]->matValue.toVec(); proppath[j]->valuedata = proppath[j]->value.data(); proppath[j]->matGradient = temp_comps[i][j]->matGradient; proppath[j]->gradient = proppath[j]->matGradient.toVec(); proppath[j]->gradientdata = proppath[j]->gradient.data(); } //proppath << temp_comps(i); dp_target->value << target_dist_reps->matValue((int)values[i]); proppath.clearGradient(); dp_target->clearGradient(); output->gradient[0] = gradient[i]; proppath.bprop(); target_dist_reps->matGradient((int)values[i]) += dp_target->gradient; target_dist_reps->updateRow((int)values[i]); } }
void PLearn::PotentialsVariable::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 PotentialsVariable.cc.
References PLearn::NaryVariable::build(), and build_().
{ inherited::build(); build_(); }
void PLearn::PotentialsVariable::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 PotentialsVariable.cc.
References comp_input, dp_target, i, input, PLearn::Variable::length(), output, params, PLERROR, PLearn::propagationPath(), proppath, PLearn::TVec< T >::resize(), PLearn::TVec< T >::size(), temp_comps, and PLearn::Variable::Var.
Referenced by build(), and PotentialsVariable().
{ if ( input && output && comp_input && dp_target && params.size() != 0) { if(output->size() != 1) PLERROR("In PotentialsVariable::build_(): to_output function has output size different from 1"); proppath = propagationPath(comp_input & dp_target & params, output); // Initialize temp_comps temp_comps.resize(1); temp_comps[0].resize(proppath.size()); for(int i=0; i<proppath.size(); i++) temp_comps[0][i] = Var(proppath[i]->length(), proppath[i]->width()); } }
string PLearn::PotentialsVariable::classname | ( | ) | const [virtual] |
Reimplemented from PLearn::Object.
Definition at line 55 of file PotentialsVariable.cc.
void PLearn::PotentialsVariable::declareOptions | ( | OptionList & | ol | ) | [static] |
Default constructor for persistence.
Reimplemented from PLearn::NaryVariable.
Definition at line 99 of file PotentialsVariable.cc.
References PLearn::OptionBase::buildoption, comp_input, PLearn::declareOption(), PLearn::NaryVariable::declareOptions(), distr, dp_target, input, output, params, and target_dist_reps.
{ declareOption(ol, "distr", &PotentialsVariable::distr, OptionBase::buildoption, ""); declareOption(ol, "output", &PotentialsVariable::output, OptionBase::buildoption, ""); declareOption(ol, "comp_input", &PotentialsVariable::comp_input, OptionBase::buildoption, ""); declareOption(ol, "dp_target", &PotentialsVariable::dp_target, OptionBase::buildoption, ""); declareOption(ol, "target_dist_reps", &PotentialsVariable::target_dist_reps, OptionBase::buildoption, ""); declareOption(ol, "input", &PotentialsVariable::input, OptionBase::buildoption, ""); declareOption(ol, "params", &PotentialsVariable::params, OptionBase::buildoption, ""); inherited::declareOptions(ol); }
static const PPath& PLearn::PotentialsVariable::declaringFile | ( | ) | [inline, static] |
Reimplemented from PLearn::NaryVariable.
Definition at line 79 of file PotentialsVariable.h.
: void build_();
PotentialsVariable * PLearn::PotentialsVariable::deepCopy | ( | CopiesMap & | copies | ) | const [virtual] |
Reimplemented from PLearn::NaryVariable.
Definition at line 55 of file PotentialsVariable.cc.
void PLearn::PotentialsVariable::fprop | ( | ) | [virtual] |
compute output given input
Implements PLearn::Variable.
Definition at line 141 of file PotentialsVariable.cc.
References PLearn::TVec< T >::data(), distr, dp_target, PLearn::VarArray::fprop(), i, input, j, PLearn::TVec< T >::length(), PLearn::Variable::length(), output, proppath, PLearn::TVec< T >::resize(), PLearn::TVec< T >::size(), target_dist_reps, temp_comps, PLearn::Variable::value, values, and PLearn::Variable::Var.
{ //temp_comps.resize(length(),proppath.nelems()); distr->getValues(input->value,distr->inputsize(),values); for(int i=0; i<length(); i++) { // Add some elements in temp_comps if necessary if(temp_comps.length() < length()) { int last_size = temp_comps.length(); temp_comps.resize(length()); for(int j=last_size; j<temp_comps.length(); j++) { temp_comps[j].resize(proppath.size()); for(int k=0; k<proppath.size(); k++) temp_comps[j][k] = Var(proppath[k]->length(), proppath[k]->width()); } } // Point to temp_comps for values and gradients of proppath for(int j=0; j<proppath.size(); j++) { proppath[j]->matValue = temp_comps[i][j]->matValue; proppath[j]->value = proppath[j]->matValue.toVec(); proppath[j]->valuedata = proppath[j]->value.data(); proppath[j]->matGradient = temp_comps[i][j]->matGradient; proppath[j]->gradient = proppath[j]->matGradient.toVec(); proppath[j]->gradientdata = proppath[j]->gradient.data(); } dp_target->value << target_dist_reps->matValue((int)values[i]); proppath.fprop(); //proppath >> temp_comps(i); value[i] = output->value[0]; } }
OptionList & PLearn::PotentialsVariable::getOptionList | ( | ) | const [virtual] |
Reimplemented from PLearn::Object.
Definition at line 55 of file PotentialsVariable.cc.
OptionMap & PLearn::PotentialsVariable::getOptionMap | ( | ) | const [virtual] |
Reimplemented from PLearn::Object.
Definition at line 55 of file PotentialsVariable.cc.
RemoteMethodMap & PLearn::PotentialsVariable::getRemoteMethodMap | ( | ) | const [virtual] |
Reimplemented from PLearn::Object.
Definition at line 55 of file PotentialsVariable.cc.
void PLearn::PotentialsVariable::makeDeepCopyFromShallowCopy | ( | CopiesMap & | copies | ) | [virtual] |
Does the necessary operations to transform a shallow copy (this) into a deep copy by deep-copying all the members that need to be.
This needs to be overridden by every class that adds "complex" data members to the class, such as Vec
, Mat
, PP<Something>
, etc. Typical implementation:
void CLASS_OF_THIS::makeDeepCopyFromShallowCopy(CopiesMap& copies) { inherited::makeDeepCopyFromShallowCopy(copies); deepCopyField(complex_data_member1, copies); deepCopyField(complex_data_member2, copies); ... }
copies | A map used by the deep-copy mechanism to keep track of already-copied objects. |
Reimplemented from PLearn::NaryVariable.
Definition at line 123 of file PotentialsVariable.cc.
References comp_input, PLearn::deepCopyField(), distr, dp_target, input, PLearn::NaryVariable::makeDeepCopyFromShallowCopy(), output, params, proppath, target_dist_reps, temp_comps, values, and PLearn::varDeepCopyField().
{ inherited::makeDeepCopyFromShallowCopy(copies); varDeepCopyField(output, copies); varDeepCopyField(comp_input, copies); varDeepCopyField(dp_target, copies); varDeepCopyField(target_dist_reps, copies); varDeepCopyField(input, copies); deepCopyField(distr, copies); deepCopyField(temp_comps, copies); deepCopyField(values, copies); deepCopyField(proppath, copies); deepCopyField(params, 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 112 of file PotentialsVariable.cc.
References distr, input, PLearn::TVec< T >::length(), and values.
{ if (distr) { distr->getValues(input->value,distr->inputsize(),values); l = values.length(); w = 1; } else l = w = 0; }
void PLearn::PotentialsVariable::rfprop | ( | ) | [virtual] |
Reimplemented from PLearn::Variable.
Definition at line 218 of file PotentialsVariable.cc.
References PLERROR.
{ PLERROR("In PotentialsVariable::rfprop(): not implemented"); }
void PLearn::PotentialsVariable::symbolicBprop | ( | ) | [virtual] |
compute a piece of new Var graph that represents the symbolic derivative of this Var
Reimplemented from PLearn::Variable.
Definition at line 212 of file PotentialsVariable.cc.
References PLERROR.
{ PLERROR("In PotentialsVariable::symbolicBprop(): not implemented"); }
Reimplemented from PLearn::NaryVariable.
Definition at line 79 of file PotentialsVariable.h.
Definition at line 70 of file PotentialsVariable.h.
Referenced by build_(), declareOptions(), and makeDeepCopyFromShallowCopy().
Definition at line 67 of file PotentialsVariable.h.
Referenced by declareOptions(), fprop(), makeDeepCopyFromShallowCopy(), and recomputeSize().
Definition at line 71 of file PotentialsVariable.h.
Referenced by bprop(), build_(), declareOptions(), fprop(), and makeDeepCopyFromShallowCopy().
Definition at line 68 of file PotentialsVariable.h.
Referenced by build_(), declareOptions(), fprop(), makeDeepCopyFromShallowCopy(), and recomputeSize().
Definition at line 69 of file PotentialsVariable.h.
Referenced by bprop(), build_(), declareOptions(), fprop(), and makeDeepCopyFromShallowCopy().
Definition at line 73 of file PotentialsVariable.h.
Referenced by build_(), declareOptions(), and makeDeepCopyFromShallowCopy().
VarArray PLearn::PotentialsVariable::proppath [protected] |
Definition at line 61 of file PotentialsVariable.h.
Referenced by bprop(), build_(), fprop(), and makeDeepCopyFromShallowCopy().
Definition at line 72 of file PotentialsVariable.h.
Referenced by bprop(), declareOptions(), fprop(), and makeDeepCopyFromShallowCopy().
TVec< VarArray > PLearn::PotentialsVariable::temp_comps [protected] |
Temporary computations.
Definition at line 60 of file PotentialsVariable.h.
Referenced by bprop(), build_(), fprop(), and makeDeepCopyFromShallowCopy().
Vec PLearn::PotentialsVariable::values [mutable, protected] |
Definition at line 63 of file PotentialsVariable.h.
Referenced by bprop(), fprop(), makeDeepCopyFromShallowCopy(), and recomputeSize().