PLearn 0.1
|
The first sentence should be a BRIEF DESCRIPTION of what the class does. More...
#include <LinearCombinationOfScalarVariables.h>
Public Member Functions | |
LinearCombinationOfScalarVariables () | |
Default constructor, usually does nothing. | |
LinearCombinationOfScalarVariables (const VarArray &vararray, Vec the_coefs) | |
Constructor initializing from 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 LinearCombinationOfScalarVariables * | 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_ () |
LinearCombinationOfScalarVariables. | |
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 | |
Vec | coefs |
### declare public option fields (such as build options) here Start your comments with Doxygen-compatible comments such as //! | |
real | constant_term |
bool | appendinputs |
Static Public Attributes | |
static StaticInitializer | _static_initializer_ |
Static Protected Member Functions | |
static void | declareOptions (OptionList &ol) |
Declares the class options. | |
Private Types | |
typedef NaryVariable | inherited |
Private Member Functions | |
void | build_ () |
This does the actual building. |
The first sentence should be a BRIEF DESCRIPTION of what the class does.
* LinearCombinationOfScalarVariables * 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 LinearCombinationOfScalarVariables.h.
typedef NaryVariable PLearn::LinearCombinationOfScalarVariables::inherited [private] |
Reimplemented from PLearn::NaryVariable.
Definition at line 62 of file LinearCombinationOfScalarVariables.h.
PLearn::LinearCombinationOfScalarVariables::LinearCombinationOfScalarVariables | ( | ) |
Default constructor, usually does nothing.
Definition at line 54 of file LinearCombinationOfScalarVariables.cc.
:constant_term(0), appendinputs(false) {}
PLearn::LinearCombinationOfScalarVariables::LinearCombinationOfScalarVariables | ( | const VarArray & | vararray, |
Vec | the_coefs | ||
) |
Constructor initializing from input variables.
Definition at line 88 of file LinearCombinationOfScalarVariables.cc.
References build_().
: inherited(vararray, 1, appendinputs?(1+vararray.length()):1), coefs(the_coefs), constant_term(0), appendinputs(false) { build_(); }
string PLearn::LinearCombinationOfScalarVariables::_classname_ | ( | ) | [static] |
LinearCombinationOfScalarVariables.
Reimplemented from PLearn::NaryVariable.
Definition at line 52 of file LinearCombinationOfScalarVariables.cc.
OptionList & PLearn::LinearCombinationOfScalarVariables::_getOptionList_ | ( | ) | [static] |
Reimplemented from PLearn::NaryVariable.
Definition at line 52 of file LinearCombinationOfScalarVariables.cc.
RemoteMethodMap & PLearn::LinearCombinationOfScalarVariables::_getRemoteMethodMap_ | ( | ) | [static] |
Reimplemented from PLearn::NaryVariable.
Definition at line 52 of file LinearCombinationOfScalarVariables.cc.
Reimplemented from PLearn::NaryVariable.
Definition at line 52 of file LinearCombinationOfScalarVariables.cc.
Object * PLearn::LinearCombinationOfScalarVariables::_new_instance_for_typemap_ | ( | ) | [static] |
Reimplemented from PLearn::Object.
Definition at line 52 of file LinearCombinationOfScalarVariables.cc.
StaticInitializer LinearCombinationOfScalarVariables::_static_initializer_ & PLearn::LinearCombinationOfScalarVariables::_static_initialize_ | ( | ) | [static] |
Reimplemented from PLearn::NaryVariable.
Definition at line 52 of file LinearCombinationOfScalarVariables.cc.
void PLearn::LinearCombinationOfScalarVariables::bprop | ( | ) | [virtual] |
Implements PLearn::Variable.
Definition at line 142 of file LinearCombinationOfScalarVariables.cc.
References coefs, PLearn::Variable::gradientdata, PLearn::TVec< T >::length(), and PLearn::NaryVariable::varray.
{ real gr = gradientdata[0]; for(int k=0; k<varray.length(); k++) varray[k]->gradientdata[0] += gr*coefs[k]; }
void PLearn::LinearCombinationOfScalarVariables::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 156 of file LinearCombinationOfScalarVariables.cc.
References PLearn::NaryVariable::build(), and build_().
{ inherited::build(); build_(); }
void PLearn::LinearCombinationOfScalarVariables::build_ | ( | ) | [private] |
This does the actual building.
Reimplemented from PLearn::NaryVariable.
Definition at line 198 of file LinearCombinationOfScalarVariables.cc.
Referenced by build(), and LinearCombinationOfScalarVariables().
{ // ### 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::LinearCombinationOfScalarVariables::classname | ( | ) | const [virtual] |
Reimplemented from PLearn::Object.
Definition at line 52 of file LinearCombinationOfScalarVariables.cc.
void PLearn::LinearCombinationOfScalarVariables::declareOptions | ( | OptionList & | ol | ) | [static, protected] |
Declares the class options.
Reimplemented from PLearn::NaryVariable.
Definition at line 168 of file LinearCombinationOfScalarVariables.cc.
References appendinputs, PLearn::OptionBase::buildoption, coefs, constant_term, PLearn::declareOption(), and PLearn::NaryVariable::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) declareOption(ol, "coefs", &LinearCombinationOfScalarVariables::coefs, OptionBase::buildoption, "The vector of coefficients for the linear combination (weights for the sum)"); declareOption(ol, "constant_term", &LinearCombinationOfScalarVariables::constant_term, OptionBase::buildoption, "A constant term whose valiue will be added to the linear combination"); declareOption(ol, "appendinputs", &LinearCombinationOfScalarVariables::appendinputs, OptionBase::buildoption, "If true, the values of the first element of all input variables \n" "(with which we compute the weighted sum) will be appended in the \n" "produced output vector (just after their weighted sum). \n" "Note: gradient received on those appended elements is ignored (i.e. not backpropagated).\n" " these are only useful as extra information (a decomposition of the cost) for reporting purpose"); // Now call the parent class' declareOptions inherited::declareOptions(ol); }
static const PPath& PLearn::LinearCombinationOfScalarVariables::declaringFile | ( | ) | [inline, static] |
Reimplemented from PLearn::NaryVariable.
Definition at line 121 of file LinearCombinationOfScalarVariables.h.
:
//##### Protected Options ###############################################
LinearCombinationOfScalarVariables * PLearn::LinearCombinationOfScalarVariables::deepCopy | ( | CopiesMap & | copies | ) | const [virtual] |
Reimplemented from PLearn::NaryVariable.
Definition at line 52 of file LinearCombinationOfScalarVariables.cc.
void PLearn::LinearCombinationOfScalarVariables::fprop | ( | ) | [virtual] |
compute output given input
Implements PLearn::Variable.
Definition at line 120 of file LinearCombinationOfScalarVariables.cc.
References appendinputs, coefs, constant_term, PLearn::TVec< T >::length(), n, PLearn::Variable::valuedata, and PLearn::NaryVariable::varray.
{ real res = constant_term; int n = varray.length(); if(appendinputs) { for(int k=0; k<n; k++) { real val = varray[k]->valuedata[0]; valuedata[1+k] = val; res += coefs[k]*val; } } else { for(int k=0; k<n; k++) res += coefs[k]*varray[k]->valuedata[0]; } valuedata[0] = res; }
OptionList & PLearn::LinearCombinationOfScalarVariables::getOptionList | ( | ) | const [virtual] |
Reimplemented from PLearn::Object.
Definition at line 52 of file LinearCombinationOfScalarVariables.cc.
OptionMap & PLearn::LinearCombinationOfScalarVariables::getOptionMap | ( | ) | const [virtual] |
Reimplemented from PLearn::Object.
Definition at line 52 of file LinearCombinationOfScalarVariables.cc.
RemoteMethodMap & PLearn::LinearCombinationOfScalarVariables::getRemoteMethodMap | ( | ) | const [virtual] |
Reimplemented from PLearn::Object.
Definition at line 52 of file LinearCombinationOfScalarVariables.cc.
void PLearn::LinearCombinationOfScalarVariables::makeDeepCopyFromShallowCopy | ( | CopiesMap & | copies | ) | [virtual] |
Transforms a shallow copy into a deep copy.
Reimplemented from PLearn::NaryVariable.
Definition at line 162 of file LinearCombinationOfScalarVariables.cc.
References coefs, PLearn::deepCopyField(), and PLearn::NaryVariable::makeDeepCopyFromShallowCopy().
{ inherited::makeDeepCopyFromShallowCopy(copies); deepCopyField(coefs, 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 110 of file LinearCombinationOfScalarVariables.cc.
References appendinputs, PLearn::TVec< T >::length(), and PLearn::NaryVariable::varray.
{ l = 1; if(!appendinputs) w = 1; else w = 1+varray.length(); }
Reimplemented from PLearn::NaryVariable.
Definition at line 121 of file LinearCombinationOfScalarVariables.h.
Definition at line 73 of file LinearCombinationOfScalarVariables.h.
Referenced by declareOptions(), fprop(), and recomputeSize().
### declare public option fields (such as build options) here Start your comments with Doxygen-compatible comments such as //!
The coeficients for the linear combination
Definition at line 71 of file LinearCombinationOfScalarVariables.h.
Referenced by bprop(), declareOptions(), fprop(), and makeDeepCopyFromShallowCopy().
Definition at line 72 of file LinearCombinationOfScalarVariables.h.
Referenced by declareOptions(), and fprop().