PLearn 0.1
|
#include <SourceVariable.h>
Public Member Functions | |
virtual void | build () |
Post-constructor. | |
SourceVariable () | |
Default constructor for persistence. | |
SourceVariable (int thelength, int thewidth, bool call_build_=true) | |
SourceVariable (const Vec &v, bool vertical=true, bool call_build_=true) | |
SourceVariable (const Mat &m, bool call_build_=true) | |
SourceVariable (int thelength, int thewidth, string random_type_, real random_a_=0, real random_b_=1, bool clear_first_row_=false, bool call_build_=true) | |
virtual void | setParents (const VarArray &parents) |
set this Variable's parents. To use with default constructor. | |
virtual bool | markPath () |
Sets the marked flag of all the sVariable that are to be in the fprop path. | |
virtual void | buildPath (VarArray &proppath) |
Finally buildPath is to be called from the output Variable of interest (this will build the proppath at the same time as erasing the marks) | |
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 string | classname () const |
virtual OptionList & | getOptionList () const |
virtual OptionMap & | getOptionMap () const |
virtual RemoteMethodMap & | getRemoteMethodMap () const |
virtual SourceVariable * | deepCopy (CopiesMap &copies) const |
virtual void | randomInitialize (PP< PRandom > random_gen) |
Initializes the value of this variable from the given generator, according to options. | |
virtual void | fprop () |
compute output given input | |
virtual void | bprop () |
virtual void | bbprop () |
compute an approximation to diag(d^2/dinput^2) given diag(d^2/doutput^2), with diag(d^2/dinput^2) ~=~ (doutput/dinput)' diag(d^2/doutput^2) (doutput/dinput) In particular: if 'C' depends on 'y' and 'y' depends on x ... | |
virtual void | symbolicBprop () |
compute a piece of new Var graph that represents the symbolic derivative of this Var | |
virtual void | rfprop () |
virtual VarArray | sources () |
if not marked, find all constant sources that influence this Variable. | |
virtual VarArray | random_sources () |
return ancestors which compute a non-deterministic function of their parents | |
virtual VarArray | ancestors () |
if not marked, find all Variables that influence this Variable. | |
virtual void | unmarkAncestors () |
undo any marking done by a call to sources() or ancestors() | |
virtual VarArray | parents () |
returns all the direct parents of this Var that are not marked (the call doesn't change any mark) | |
bool | isConstant () |
void | printInfo (bool print_gradient) |
Static Public Member Functions | |
static string | _classname_ () |
SourceVariable. | |
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 | build_length |
int | build_width |
string | random_type |
real | random_a |
real | random_b |
bool | random_clear_first_row |
Static Public Attributes | |
static StaticInitializer | _static_initializer_ |
Static Protected Member Functions | |
static void | declareOptions (OptionList &ol) |
Declare options (data fields) for the class. | |
Private Types | |
typedef Variable | inherited |
Private Member Functions | |
void | build_ () |
Object-specific post-constructor. |
Definition at line 52 of file SourceVariable.h.
typedef Variable PLearn::SourceVariable::inherited [private] |
Reimplemented from PLearn::Variable.
Reimplemented in PLearn::ConstrainedSourceVariable.
Definition at line 54 of file SourceVariable.h.
PLearn::SourceVariable::SourceVariable | ( | ) |
Default constructor for persistence.
Definition at line 59 of file SourceVariable.cc.
: build_length(-1), build_width(-1), random_type("none"), random_a(0.), random_b(1.), random_clear_first_row(false) {}
Definition at line 68 of file SourceVariable.cc.
References build_().
: inherited(thelength, thewidth, call_build_), build_length(-1), build_width(-1), random_type("none"), random_a(0.), random_b(1.), random_clear_first_row(false) { if (call_build_) build_(); }
PLearn::SourceVariable::SourceVariable | ( | const Vec & | v, |
bool | vertical = true , |
||
bool | call_build_ = true |
||
) |
Definition at line 96 of file SourceVariable.cc.
References build_().
: inherited(vertical ?v.toMat(v.length(),1) :v.toMat(1,v.length()), call_build_), build_length(-1), build_width(-1), random_type("none"), random_a(0.), random_b(1.), random_clear_first_row(false) { if (call_build_) build_(); }
Definition at line 110 of file SourceVariable.cc.
References build_().
: inherited(m, call_build_), build_length(-1), build_width(-1), random_type("none"), random_a(0.), random_b(1.), random_clear_first_row(false) { if (call_build_) build_(); }
PLearn::SourceVariable::SourceVariable | ( | int | thelength, |
int | thewidth, | ||
string | random_type_, | ||
real | random_a_ = 0 , |
||
real | random_b_ = 1 , |
||
bool | clear_first_row_ = false , |
||
bool | call_build_ = true |
||
) |
Definition at line 81 of file SourceVariable.cc.
References build_().
: inherited(thelength, thewidth, call_build_), build_length(thelength), build_width(thewidth), random_type(random_type_), random_a(random_a_), random_b(random_b_), random_clear_first_row(clear_first_row_) { if (call_build_) build_(); }
string PLearn::SourceVariable::_classname_ | ( | ) | [static] |
Reimplemented from PLearn::Variable.
Reimplemented in PLearn::ConstrainedSourceVariable.
Definition at line 54 of file SourceVariable.cc.
OptionList & PLearn::SourceVariable::_getOptionList_ | ( | ) | [static] |
Reimplemented from PLearn::Variable.
Reimplemented in PLearn::ConstrainedSourceVariable.
Definition at line 54 of file SourceVariable.cc.
RemoteMethodMap & PLearn::SourceVariable::_getRemoteMethodMap_ | ( | ) | [static] |
Reimplemented from PLearn::Variable.
Reimplemented in PLearn::ConstrainedSourceVariable.
Definition at line 54 of file SourceVariable.cc.
Reimplemented from PLearn::Variable.
Reimplemented in PLearn::ConstrainedSourceVariable.
Definition at line 54 of file SourceVariable.cc.
Object * PLearn::SourceVariable::_new_instance_for_typemap_ | ( | ) | [static] |
Reimplemented from PLearn::Object.
Reimplemented in PLearn::ConstrainedSourceVariable.
Definition at line 54 of file SourceVariable.cc.
StaticInitializer SourceVariable::_static_initializer_ & PLearn::SourceVariable::_static_initialize_ | ( | ) | [static] |
Reimplemented from PLearn::Variable.
Reimplemented in PLearn::ConstrainedSourceVariable.
Definition at line 54 of file SourceVariable.cc.
VarArray PLearn::SourceVariable::ancestors | ( | ) | [virtual] |
if not marked, find all Variables that influence this Variable.
Implements PLearn::Variable.
Definition at line 206 of file SourceVariable.cc.
References PLearn::Variable::marked, PLearn::Variable::setMark(), and PLearn::Variable::Var.
void PLearn::SourceVariable::bbprop | ( | ) | [virtual] |
compute an approximation to diag(d^2/dinput^2) given diag(d^2/doutput^2), with diag(d^2/dinput^2) ~=~ (doutput/dinput)' diag(d^2/doutput^2) (doutput/dinput) In particular: if 'C' depends on 'y' and 'y' depends on x ...
d^2C/dx^2 = d^2C/dy^2 * (dy/dx)^2 + dC/dy * d^2y/dx^2 (diaghessian) (gradient)
Reimplemented from PLearn::Variable.
Definition at line 185 of file SourceVariable.cc.
{} // No input: nothing to bbprop
void PLearn::SourceVariable::bprop | ( | ) | [virtual] |
Implements PLearn::Variable.
Reimplemented in PLearn::SourceSampleVariable.
Definition at line 184 of file SourceVariable.cc.
{} // No input: nothing to bprop
void PLearn::SourceVariable::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::Variable.
Reimplemented in PLearn::ConstrainedSourceVariable.
Definition at line 170 of file SourceVariable.cc.
References PLearn::Variable::build(), and build_().
{ inherited::build(); build_(); }
void PLearn::SourceVariable::build_ | ( | ) | [private] |
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::Variable.
Reimplemented in PLearn::ConstrainedSourceVariable.
Definition at line 161 of file SourceVariable.cc.
References build_length, build_width, and PLearn::Variable::resize().
Referenced by build(), and SourceVariable().
{ if(build_length>0 && build_width>0) resize(build_length, build_width); }
void PLearn::SourceVariable::buildPath | ( | VarArray & | proppath | ) | [virtual] |
Finally buildPath is to be called from the output Variable of interest (this will build the proppath at the same time as erasing the marks)
Implements PLearn::Variable.
Definition at line 226 of file SourceVariable.cc.
References PLearn::TVec< T >::append(), PLearn::Variable::clearMark(), PLearn::Variable::marked, and PLearn::Variable::Var.
string PLearn::SourceVariable::classname | ( | ) | const [virtual] |
Reimplemented from PLearn::Object.
Reimplemented in PLearn::SourceSampleVariable, PLearn::UniformSampleVariable, and PLearn::ConstrainedSourceVariable.
Definition at line 54 of file SourceVariable.cc.
void PLearn::SourceVariable::declareOptions | ( | OptionList & | ol | ) | [static, protected] |
Declare options (data fields) for the class.
Redefine this in subclasses: call declareOption
(...) for each option, and then call inherited::declareOptions(options)
. Please call the inherited
method AT THE END to get the options listed in a consistent order (from most recently defined to least recently defined).
static void MyDerivedClass::declareOptions(OptionList& ol) { declareOption(ol, "inputsize", &MyObject::inputsize_, OptionBase::buildoption, "The size of the input; it must be provided"); declareOption(ol, "weights", &MyObject::weights, OptionBase::learntoption, "The learned model weights"); inherited::declareOptions(ol); }
ol | List of options that is progressively being constructed for the current class. |
Reimplemented from PLearn::Variable.
Reimplemented in PLearn::ConstrainedSourceVariable.
Definition at line 126 of file SourceVariable.cc.
References build_length, build_width, PLearn::OptionBase::buildoption, PLearn::declareOption(), PLearn::Variable::declareOptions(), random_a, random_b, random_clear_first_row, and random_type.
{ declareOption(ol, "build_length", &SourceVariable::build_length, OptionBase::buildoption, "Forced value of the variable's length."); declareOption(ol, "build_width", &SourceVariable::build_width, OptionBase::buildoption, "Forced value of the variable's width."); declareOption(ol, "random_type", &SourceVariable::random_type, OptionBase::buildoption, "Type of random generation to use:\n" " - none = no random initialization\n" " - fill = fill with 'random_a'\n" " - uniform = uniform distribution in [random_a, random_b]\n" " - normal = normal distribution with mean 'random_a' and\n" " standard deviation 'random_b'\n" "Note that the variable is not filled randomly at build time: random\n" "generation requires an explicit call to randomInitialize(..)."); declareOption(ol, "random_a", &SourceVariable::random_a, OptionBase::buildoption, "A first parameter for random generation"); declareOption(ol, "random_b", &SourceVariable::random_b, OptionBase::buildoption, "A second parameter for random generation"); declareOption(ol, "random_clear_first_row", &SourceVariable::random_clear_first_row, OptionBase::buildoption, "Indicates if we assign 0 to the elements of the first " "row when doing random generation"); inherited::declareOptions(ol); }
static const PPath& PLearn::SourceVariable::declaringFile | ( | ) | [inline, static] |
Reimplemented from PLearn::Variable.
Reimplemented in PLearn::ConstrainedSourceVariable.
Definition at line 93 of file SourceVariable.h.
{ return true; }
SourceVariable * PLearn::SourceVariable::deepCopy | ( | CopiesMap & | copies | ) | const [virtual] |
Reimplemented from PLearn::Variable.
Reimplemented in PLearn::SourceSampleVariable, PLearn::UniformSampleVariable, and PLearn::ConstrainedSourceVariable.
Definition at line 54 of file SourceVariable.cc.
void PLearn::SourceVariable::fprop | ( | ) | [virtual] |
compute output given input
Implements PLearn::Variable.
Reimplemented in PLearn::UniformSampleVariable.
Definition at line 183 of file SourceVariable.cc.
{} // No input: nothing to fprop
OptionList & PLearn::SourceVariable::getOptionList | ( | ) | const [virtual] |
Reimplemented from PLearn::Object.
Reimplemented in PLearn::ConstrainedSourceVariable.
Definition at line 54 of file SourceVariable.cc.
OptionMap & PLearn::SourceVariable::getOptionMap | ( | ) | const [virtual] |
Reimplemented from PLearn::Object.
Reimplemented in PLearn::ConstrainedSourceVariable.
Definition at line 54 of file SourceVariable.cc.
RemoteMethodMap & PLearn::SourceVariable::getRemoteMethodMap | ( | ) | const [virtual] |
Reimplemented from PLearn::Object.
Reimplemented in PLearn::ConstrainedSourceVariable.
Definition at line 54 of file SourceVariable.cc.
bool PLearn::SourceVariable::isConstant | ( | ) | [inline, virtual] |
Reimplemented from PLearn::Variable.
Definition at line 109 of file SourceVariable.h.
{ return true; }
void PLearn::SourceVariable::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::Variable.
Reimplemented in PLearn::ConstrainedSourceVariable.
Definition at line 177 of file SourceVariable.cc.
References PLearn::deepCopyField(), PLearn::Variable::makeDeepCopyFromShallowCopy(), and PLearn::Variable::rows_to_update.
Referenced by PLearn::UniformSampleVariable::deepCopy().
{ inherited::makeDeepCopyFromShallowCopy(copies); deepCopyField(rows_to_update, copies); }
bool PLearn::SourceVariable::markPath | ( | ) | [virtual] |
Sets the marked flag of all the sVariable that are to be in the fprop path.
The input sVariable that are of interest are to be marked first. Then markPath is to be called from the output Variable of interest
Implements PLearn::Variable.
Definition at line 223 of file SourceVariable.cc.
References PLearn::Variable::marked.
{ return marked; }
VarArray PLearn::SourceVariable::parents | ( | ) | [virtual] |
returns all the direct parents of this Var that are not marked (the call doesn't change any mark)
Implements PLearn::Variable.
Definition at line 220 of file SourceVariable.cc.
{ return VarArray(0,0); }
void PLearn::SourceVariable::printInfo | ( | bool | print_gradient | ) | [inline, virtual] |
Implements PLearn::Variable.
Definition at line 111 of file SourceVariable.h.
References PLearn::endl(), and PLearn::pout.
{ pout << getName() << "[" << (void*)this << "] " << *this << " = " << value; if (print_gradient) pout << " gradient=" << gradient; pout << endl; }
VarArray PLearn::SourceVariable::random_sources | ( | ) | [virtual] |
return ancestors which compute a non-deterministic function of their parents
Implements PLearn::Variable.
Reimplemented in PLearn::SourceSampleVariable.
Definition at line 199 of file SourceVariable.cc.
References PLearn::Variable::marked, and PLearn::Variable::setMark().
Initializes the value of this variable from the given generator, according to options.
Definition at line 239 of file SourceVariable.cc.
References PLearn::TMat< T >::fill(), PLearn::TMat< T >::length(), PLearn::Variable::matValue, PLERROR, random_a, random_b, random_clear_first_row, random_type, and PLearn::TMat< T >::subMatRows().
Referenced by PLearn::VerifyGradientCommand::run().
{ Mat values = matValue; if(random_clear_first_row) values = values.subMatRows(1, values.length()-1); if (random_type == "fill") { values.fill(random_a); } else if (random_type == "uniform") { random_gen->fill_random_uniform(values, random_a, random_b); } else if (random_type == "normal") { random_gen->fill_random_normal(values, random_a, random_b); } else { PLERROR("In SourceVariable::randomInitialize - Invalid value for " "'random_type': %s", random_type.c_str()); } }
void PLearn::SourceVariable::rfprop | ( | ) | [virtual] |
Reimplemented from PLearn::Variable.
Definition at line 186 of file SourceVariable.cc.
{} // No input: nothing to rfprop
virtual void PLearn::SourceVariable::setParents | ( | const VarArray & | parents | ) | [inline, virtual] |
set this Variable's parents. To use with default constructor.
Reimplemented from PLearn::Variable.
Definition at line 86 of file SourceVariable.h.
References PLERROR.
{ PLERROR("In Variable::setParents trying to set parents of a SourceVariable..."); }
VarArray PLearn::SourceVariable::sources | ( | ) | [virtual] |
if not marked, find all constant sources that influence this Variable.
A constant source is normally a SourceVariable.
Implements PLearn::Variable.
Definition at line 189 of file SourceVariable.cc.
References PLearn::Variable::marked, PLearn::Variable::setMark(), and PLearn::Variable::Var.
void PLearn::SourceVariable::symbolicBprop | ( | ) | [virtual] |
compute a piece of new Var graph that represents the symbolic derivative of this Var
Reimplemented from PLearn::Variable.
Definition at line 187 of file SourceVariable.cc.
{} // No input: nothing to bprop
void PLearn::SourceVariable::unmarkAncestors | ( | ) | [virtual] |
undo any marking done by a call to sources() or ancestors()
Implements PLearn::Variable.
Definition at line 214 of file SourceVariable.cc.
References PLearn::Variable::clearMark(), and PLearn::Variable::marked.
Reimplemented from PLearn::Variable.
Reimplemented in PLearn::ConstrainedSourceVariable.
Definition at line 93 of file SourceVariable.h.
Definition at line 58 of file SourceVariable.h.
Referenced by build_(), and declareOptions().
Definition at line 59 of file SourceVariable.h.
Referenced by build_(), and declareOptions().
Definition at line 63 of file SourceVariable.h.
Referenced by declareOptions(), and randomInitialize().
Definition at line 64 of file SourceVariable.h.
Referenced by declareOptions(), and randomInitialize().
Definition at line 66 of file SourceVariable.h.
Referenced by declareOptions(), and randomInitialize().
Definition at line 61 of file SourceVariable.h.
Referenced by declareOptions(), and randomInitialize().