PLearn 0.1
|
A subsample var; equals subrample(input, the_subsamplefactor) More...
#include <SubsampleVariable.h>
Public Member Functions | |
SubsampleVariable () | |
Default constructor for persistence. | |
SubsampleVariable (Variable *input, int the_subsamplefactor) | |
virtual string | classname () const |
virtual OptionList & | getOptionList () const |
virtual OptionMap & | getOptionMap () const |
virtual RemoteMethodMap & | getRemoteMethodMap () const |
virtual SubsampleVariable * | 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 () |
Nothing to do by default. | |
virtual void | bprop () |
Nothing to do by default. | |
virtual void | symbolicBprop () |
compute a piece of new Var graph that represents the symbolic derivative of this Var | |
Static Public Member Functions | |
static string | _classname_ () |
SubsampleVariable. | |
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) |
Declare options (data fields) for the class. | |
Static Public Attributes | |
static StaticInitializer | _static_initializer_ |
Protected Member Functions | |
void | build_ () |
Object-specific post-constructor. | |
Protected Attributes | |
int | subsamplefactor |
Private Types | |
typedef UnaryVariable | inherited |
A subsample var; equals subrample(input, the_subsamplefactor)
Definition at line 53 of file SubsampleVariable.h.
typedef UnaryVariable PLearn::SubsampleVariable::inherited [private] |
Reimplemented from PLearn::UnaryVariable.
Definition at line 55 of file SubsampleVariable.h.
PLearn::SubsampleVariable::SubsampleVariable | ( | ) | [inline] |
Default constructor for persistence.
Definition at line 62 of file SubsampleVariable.h.
: subsamplefactor(1) {}
Definition at line 55 of file SubsampleVariable.cc.
References build_().
: inherited(input, input->length()/the_subsamplefactor, input->width()/the_subsamplefactor), subsamplefactor(the_subsamplefactor) { build_(); }
string PLearn::SubsampleVariable::_classname_ | ( | ) | [static] |
Reimplemented from PLearn::UnaryVariable.
Definition at line 53 of file SubsampleVariable.cc.
OptionList & PLearn::SubsampleVariable::_getOptionList_ | ( | ) | [static] |
Reimplemented from PLearn::UnaryVariable.
Definition at line 53 of file SubsampleVariable.cc.
RemoteMethodMap & PLearn::SubsampleVariable::_getRemoteMethodMap_ | ( | ) | [static] |
Reimplemented from PLearn::UnaryVariable.
Definition at line 53 of file SubsampleVariable.cc.
Reimplemented from PLearn::UnaryVariable.
Definition at line 53 of file SubsampleVariable.cc.
Object * PLearn::SubsampleVariable::_new_instance_for_typemap_ | ( | ) | [static] |
Reimplemented from PLearn::UnaryVariable.
Definition at line 53 of file SubsampleVariable.cc.
StaticInitializer SubsampleVariable::_static_initializer_ & PLearn::SubsampleVariable::_static_initialize_ | ( | ) | [static] |
Reimplemented from PLearn::UnaryVariable.
Definition at line 53 of file SubsampleVariable.cc.
void PLearn::SubsampleVariable::bprop | ( | ) | [virtual] |
Nothing to do by default.
Reimplemented from PLearn::UnaryVariable.
Definition at line 100 of file SubsampleVariable.cc.
References c, i, PLearn::UnaryVariable::input, j, PLearn::Variable::length(), PLearn::Variable::matGradient, PLearn::norm(), subsamplefactor, and PLearn::Variable::width().
{ int norm = subsamplefactor * subsamplefactor; for(int i=0; i<length(); i++) for(int j=0; j<width(); j++) { real* inputgradientptr = input->matGradient[subsamplefactor*i]+subsamplefactor*j; real thisgradient = matGradient(i,j); for(int l=0; l<subsamplefactor; l++, inputgradientptr += input->matGradient.mod()) for(int c=0; c<subsamplefactor; c++) { inputgradientptr[c] = thisgradient/norm; } } }
void PLearn::SubsampleVariable::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::UnaryVariable.
Definition at line 63 of file SubsampleVariable.cc.
References PLearn::UnaryVariable::build(), and build_().
{ inherited::build(); build_(); }
void PLearn::SubsampleVariable::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::UnaryVariable.
Definition at line 70 of file SubsampleVariable.cc.
References PLearn::UnaryVariable::input, PLearn::Var::length(), PLERROR, subsamplefactor, and PLearn::Var::width().
Referenced by build(), and SubsampleVariable().
{ if (input) { if (input->length() % subsamplefactor != 0 || input->width() % subsamplefactor != 0) PLERROR("In SubsampleVariable constructor: Dimensions of input are not dividable by subsamplefactor"); } }
string PLearn::SubsampleVariable::classname | ( | ) | const [virtual] |
Reimplemented from PLearn::UnaryVariable.
Definition at line 53 of file SubsampleVariable.cc.
void PLearn::SubsampleVariable::declareOptions | ( | OptionList & | ol | ) | [static] |
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::UnaryVariable.
Definition at line 79 of file SubsampleVariable.cc.
References PLearn::OptionBase::buildoption, PLearn::declareOption(), PLearn::UnaryVariable::declareOptions(), and subsamplefactor.
{ declareOption(ol, "subsamplefactor", &SubsampleVariable::subsamplefactor, OptionBase::buildoption, ""); inherited::declareOptions(ol); }
static const PPath& PLearn::SubsampleVariable::declaringFile | ( | ) | [inline, static] |
Reimplemented from PLearn::UnaryVariable.
Definition at line 65 of file SubsampleVariable.h.
: void build_();
SubsampleVariable * PLearn::SubsampleVariable::deepCopy | ( | CopiesMap & | copies | ) | const [virtual] |
Reimplemented from PLearn::UnaryVariable.
Definition at line 53 of file SubsampleVariable.cc.
void PLearn::SubsampleVariable::fprop | ( | ) | [virtual] |
Nothing to do by default.
Reimplemented from PLearn::UnaryVariable.
Definition at line 94 of file SubsampleVariable.cc.
References PLearn::UnaryVariable::input, PLearn::Variable::matValue, PLearn::subsample(), and subsamplefactor.
{ subsample(input->matValue, subsamplefactor, matValue); }
OptionList & PLearn::SubsampleVariable::getOptionList | ( | ) | const [virtual] |
Reimplemented from PLearn::UnaryVariable.
Definition at line 53 of file SubsampleVariable.cc.
OptionMap & PLearn::SubsampleVariable::getOptionMap | ( | ) | const [virtual] |
Reimplemented from PLearn::UnaryVariable.
Definition at line 53 of file SubsampleVariable.cc.
RemoteMethodMap & PLearn::SubsampleVariable::getRemoteMethodMap | ( | ) | const [virtual] |
Reimplemented from PLearn::UnaryVariable.
Definition at line 53 of file SubsampleVariable.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 85 of file SubsampleVariable.cc.
References PLearn::UnaryVariable::input, PLearn::Var::length(), subsamplefactor, and PLearn::Var::width().
{ if (input) { l = input->length() / subsamplefactor; w = input->width()/subsamplefactor; } else l = w = 0; }
void PLearn::SubsampleVariable::symbolicBprop | ( | ) | [virtual] |
compute a piece of new Var graph that represents the symbolic derivative of this Var
Reimplemented from PLearn::Variable.
Definition at line 117 of file SubsampleVariable.cc.
References PLERROR.
{ PLERROR("SubsampleVariable::symbolicBprop() not yet implemented"); }
Reimplemented from PLearn::UnaryVariable.
Definition at line 65 of file SubsampleVariable.h.
int PLearn::SubsampleVariable::subsamplefactor [protected] |
Definition at line 58 of file SubsampleVariable.h.
Referenced by bprop(), build_(), declareOptions(), fprop(), and recomputeSize().