PLearn 0.1
|
#include <Cov2CorrVariable.h>
Public Member Functions | |
Cov2CorrVariable () | |
Default constructor. | |
Cov2CorrVariable (Variable *input, int diagonal_choice_=1, double epsilon_=0, bool call_build_=true) | |
virtual string | classname () const |
virtual OptionList & | getOptionList () const |
virtual OptionMap & | getOptionMap () const |
virtual RemoteMethodMap & | getRemoteMethodMap () const |
virtual Cov2CorrVariable * | 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 | bbprop () |
here don't approximate, do d2C/dx^2 = 4 x^2 d2C/dy^2 + 2 dC/dy | |
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_ () |
Cov2CorrVariable. | |
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. | |
Public Attributes | |
int | diagonal_choice |
double | epsilon |
Static Public Attributes | |
static StaticInitializer | _static_initializer_ |
Private Types | |
typedef UnaryVariable | inherited |
Private Member Functions | |
void | build_ () |
Object-specific post-constructor. |
Definition at line 48 of file Cov2CorrVariable.h.
typedef UnaryVariable PLearn::Cov2CorrVariable::inherited [private] |
Reimplemented from PLearn::UnaryVariable.
Definition at line 50 of file Cov2CorrVariable.h.
PLearn::Cov2CorrVariable::Cov2CorrVariable | ( | ) |
Default constructor.
Definition at line 60 of file Cov2CorrVariable.cc.
: diagonal_choice(1), epsilon(0.) {}
PLearn::Cov2CorrVariable::Cov2CorrVariable | ( | Variable * | input, |
int | diagonal_choice_ = 1 , |
||
double | epsilon_ = 0 , |
||
bool | call_build_ = true |
||
) |
Definition at line 65 of file Cov2CorrVariable.cc.
References build_().
: inherited(input, input->length(), input->width(), call_build_), diagonal_choice(diagonal_choice_), epsilon(epsilon_) { if (call_build_) build_(); }
string PLearn::Cov2CorrVariable::_classname_ | ( | ) | [static] |
Reimplemented from PLearn::UnaryVariable.
Definition at line 54 of file Cov2CorrVariable.cc.
OptionList & PLearn::Cov2CorrVariable::_getOptionList_ | ( | ) | [static] |
Reimplemented from PLearn::UnaryVariable.
Definition at line 54 of file Cov2CorrVariable.cc.
RemoteMethodMap & PLearn::Cov2CorrVariable::_getRemoteMethodMap_ | ( | ) | [static] |
Reimplemented from PLearn::UnaryVariable.
Definition at line 54 of file Cov2CorrVariable.cc.
Reimplemented from PLearn::UnaryVariable.
Definition at line 54 of file Cov2CorrVariable.cc.
Object * PLearn::Cov2CorrVariable::_new_instance_for_typemap_ | ( | ) | [static] |
Reimplemented from PLearn::UnaryVariable.
Definition at line 54 of file Cov2CorrVariable.cc.
StaticInitializer Cov2CorrVariable::_static_initializer_ & PLearn::Cov2CorrVariable::_static_initialize_ | ( | ) | [static] |
Reimplemented from PLearn::UnaryVariable.
Definition at line 54 of file Cov2CorrVariable.cc.
void PLearn::Cov2CorrVariable::bbprop | ( | ) | [virtual] |
here don't approximate, do d2C/dx^2 = 4 x^2 d2C/dy^2 + 2 dC/dy
Reimplemented from PLearn::Variable.
Definition at line 200 of file Cov2CorrVariable.cc.
References PLERROR.
{ PLERROR("bbprop not implemented for this variable"); }
void PLearn::Cov2CorrVariable::bprop | ( | ) | [virtual] |
Nothing to do by default.
Reimplemented from PLearn::UnaryVariable.
Definition at line 176 of file Cov2CorrVariable.cc.
References diagonal_choice, epsilon, i, PLearn::UnaryVariable::input, j, PLearn::TMat< T >::length(), PLearn::Variable::matGradient, PLearn::Variable::matValue, w, and PLearn::TMat< T >::width().
{ Mat C = input->matValue; Mat Cg = input->matGradient; Mat D = matValue; Mat Dg = matGradient; int l = C.length(); int w = C.width(); for(int i=0; i<l; i++) for(int j=0; j<w; j++) { if(i!=j) { Cg(i,j) += Dg(i,j)*D(i,j)/C(i,j); double h = -0.5*Dg(i,j)*D(i,j)/(C(i,i)*C(j,j)+epsilon); Cg(i,i) += C(j,j)*h; Cg(j,j) += C(i,i)*h; } else if(diagonal_choice==2) Cg(i,i) += Dg(i,i); } }
void PLearn::Cov2CorrVariable::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 92 of file Cov2CorrVariable.cc.
References PLearn::UnaryVariable::build(), and build_().
{ inherited::build(); build_(); }
void PLearn::Cov2CorrVariable::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::UnaryVariable.
Definition at line 100 of file Cov2CorrVariable.cc.
Referenced by build(), and Cov2CorrVariable().
{
// Nothing to do here.
}
string PLearn::Cov2CorrVariable::classname | ( | ) | const [virtual] |
Reimplemented from PLearn::UnaryVariable.
Definition at line 54 of file Cov2CorrVariable.cc.
void PLearn::Cov2CorrVariable::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 75 of file Cov2CorrVariable.cc.
References PLearn::OptionBase::buildoption, PLearn::declareOption(), PLearn::UnaryVariable::declareOptions(), diagonal_choice, and epsilon.
{ declareOption( ol, "diagonal_choice", &Cov2CorrVariable::diagonal_choice, OptionBase::buildoption, "Controls how to fill the diagonal.\n" " 0: fill it with 0\n" " 1: fill it with 1\n" " 2: keep the diagonal of the input (i.e. the original variances)\n"); declareOption( ol, "epsilon", &Cov2CorrVariable::epsilon, OptionBase::buildoption, "value to add to product of variances before taking their sqrt.\n"); inherited::declareOptions(ol); }
static const PPath& PLearn::Cov2CorrVariable::declaringFile | ( | ) | [inline, static] |
Cov2CorrVariable * PLearn::Cov2CorrVariable::deepCopy | ( | CopiesMap & | copies | ) | const [virtual] |
Reimplemented from PLearn::UnaryVariable.
Definition at line 54 of file Cov2CorrVariable.cc.
void PLearn::Cov2CorrVariable::fprop | ( | ) | [virtual] |
Nothing to do by default.
Reimplemented from PLearn::UnaryVariable.
Definition at line 117 of file Cov2CorrVariable.cc.
References diagonal_choice, epsilon, i, PLearn::UnaryVariable::input, j, PLearn::TMat< T >::length(), PLearn::Variable::matValue, PLERROR, PLearn::sqrt(), w, and PLearn::TMat< T >::width().
{ Mat C = input->matValue; int l = C.length(); int w = C.width(); for(int i=0; i<l; i++) for(int j=0; j<w; j++) { if(i!=j) matValue(i,j) = C(i,j)/sqrt(C(i,i)*C(j,j)+epsilon); else // diagonal element { double diagval = 0; switch(diagonal_choice) { case 0: diagval = 0; break; case 1: diagval = 1; break; case 2: diagval = C(i,j); break; default: PLERROR("Invalid diagonal_choice option"); } matValue(i,j) = diagval; } } }
OptionList & PLearn::Cov2CorrVariable::getOptionList | ( | ) | const [virtual] |
Reimplemented from PLearn::UnaryVariable.
Definition at line 54 of file Cov2CorrVariable.cc.
OptionMap & PLearn::Cov2CorrVariable::getOptionMap | ( | ) | const [virtual] |
Reimplemented from PLearn::UnaryVariable.
Definition at line 54 of file Cov2CorrVariable.cc.
RemoteMethodMap & PLearn::Cov2CorrVariable::getRemoteMethodMap | ( | ) | const [virtual] |
Reimplemented from PLearn::UnaryVariable.
Definition at line 54 of file Cov2CorrVariable.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 107 of file Cov2CorrVariable.cc.
References PLearn::UnaryVariable::input, PLearn::Var::length(), and PLearn::Var::width().
void PLearn::Cov2CorrVariable::rfprop | ( | ) | [virtual] |
Reimplemented from PLearn::Variable.
Definition at line 212 of file Cov2CorrVariable.cc.
References PLERROR.
{ PLERROR("rfprop no yet implemented for this vairable"); }
void PLearn::Cov2CorrVariable::symbolicBprop | ( | ) | [virtual] |
compute a piece of new Var graph that represents the symbolic derivative of this Var
Reimplemented from PLearn::Variable.
Definition at line 206 of file Cov2CorrVariable.cc.
References PLERROR.
{ PLERROR("symbolic bprop not yet implemented for this variable"); }
Reimplemented from PLearn::UnaryVariable.
Definition at line 62 of file Cov2CorrVariable.h.
Definition at line 53 of file Cov2CorrVariable.h.
Referenced by bprop(), declareOptions(), and fprop().
Definition at line 54 of file Cov2CorrVariable.h.
Referenced by bprop(), declareOptions(), and fprop().