PLearn 0.1
|
The first sentence should be a BRIEF DESCRIPTION of what the class does. More...
#include <SumVarianceOfLinearTransformedCategoricals.h>
Public Member Functions | |
SumVarianceOfLinearTransformedCategoricals () | |
Default constructor. | |
SumVarianceOfLinearTransformedCategoricals (Variable *input1, Variable *input2, bool call_build_=true) | |
Constructor initializing from two 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 SumVarianceOfLinearTransformedCategoricals * | 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_ () |
SumVarianceOfLinearTransformedCategoricals. | |
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 | |
TVec< int > | groupsizes |
### declare public option fields (such as build options) here Start your comments with Doxygen-compatible comments such as //! | |
Static Public Attributes | |
static StaticInitializer | _static_initializer_ |
Static Protected Member Functions | |
static void | declareOptions (OptionList &ol) |
Declares the class options. | |
Private Types | |
typedef BinaryVariable | inherited |
Private Member Functions | |
void | build_ () |
This does the actual building. | |
Private Attributes | |
Vec | group_sum_wik_pk |
The first sentence should be a BRIEF DESCRIPTION of what the class does.
* SumVarianceOfLinearTransformedCategoricals * 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 SumVarianceOfLinearTransformedCategoricals.h.
typedef BinaryVariable PLearn::SumVarianceOfLinearTransformedCategoricals::inherited [private] |
Reimplemented from PLearn::BinaryVariable.
Definition at line 62 of file SumVarianceOfLinearTransformedCategoricals.h.
PLearn::SumVarianceOfLinearTransformedCategoricals::SumVarianceOfLinearTransformedCategoricals | ( | ) |
Default constructor.
Definition at line 62 of file SumVarianceOfLinearTransformedCategoricals.cc.
: inherited(0,0,1,1) {}
string PLearn::SumVarianceOfLinearTransformedCategoricals::_classname_ | ( | ) | [static] |
SumVarianceOfLinearTransformedCategoricals.
Reimplemented from PLearn::BinaryVariable.
Definition at line 60 of file SumVarianceOfLinearTransformedCategoricals.cc.
OptionList & PLearn::SumVarianceOfLinearTransformedCategoricals::_getOptionList_ | ( | ) | [static] |
Reimplemented from PLearn::BinaryVariable.
Definition at line 60 of file SumVarianceOfLinearTransformedCategoricals.cc.
RemoteMethodMap & PLearn::SumVarianceOfLinearTransformedCategoricals::_getRemoteMethodMap_ | ( | ) | [static] |
Reimplemented from PLearn::BinaryVariable.
Definition at line 60 of file SumVarianceOfLinearTransformedCategoricals.cc.
Reimplemented from PLearn::BinaryVariable.
Definition at line 60 of file SumVarianceOfLinearTransformedCategoricals.cc.
Object * PLearn::SumVarianceOfLinearTransformedCategoricals::_new_instance_for_typemap_ | ( | ) | [static] |
Reimplemented from PLearn::Object.
Definition at line 60 of file SumVarianceOfLinearTransformedCategoricals.cc.
StaticInitializer SumVarianceOfLinearTransformedCategoricals::_static_initializer_ & PLearn::SumVarianceOfLinearTransformedCategoricals::_static_initialize_ | ( | ) | [static] |
Reimplemented from PLearn::BinaryVariable.
Definition at line 60 of file SumVarianceOfLinearTransformedCategoricals.cc.
void PLearn::SumVarianceOfLinearTransformedCategoricals::bprop | ( | ) | [virtual] |
Implements PLearn::Variable.
Definition at line 140 of file SumVarianceOfLinearTransformedCategoricals.cc.
References d, PLearn::TVec< T >::data(), PLearn::Variable::gradient, group_sum_wik_pk, groupsizes, i, PLearn::BinaryVariable::input1, PLearn::BinaryVariable::input2, PLearn::TVec< T >::length(), PLearn::TMat< T >::length(), PLearn::P(), and PLearn::TVec< T >::resize().
{ Mat P = input1->matValue; Mat Pgrad = input1->matGradient; Mat W = input2->matValue; Mat Wgrad = input2->matGradient; int d = W.length(); int l = P.length(); // int m = W.width(); // should equal sum of groupsizes real gr = gradient[0]; int ngroups = groupsizes.length(); const int* pgroupsize = groupsizes.data(); group_sum_wik_pk.resize(ngroups); real* p_group_sum_wik_pk = group_sum_wik_pk.data(); for(int t=0; t<l; t++) { const real* p = P[t]; real* gp = Pgrad[t]; for(int i=0; i<d; i++) { const real* Wi = W[i]; int k = 0; for(int groupnum=0; groupnum<ngroups; groupnum++) { int gs = pgroupsize[groupnum]; double sum_wik_pk = 0; while(gs--) { sum_wik_pk += Wi[k]*p[k]; k++; } p_group_sum_wik_pk[groupnum] = sum_wik_pk; } real* gWi = Wgrad[i]; k = 0; for(int groupnum=0; groupnum<ngroups; groupnum++) { int gs = pgroupsize[groupnum]; real grsum = p_group_sum_wik_pk[groupnum]; while(gs--) { real Wik = Wi[k]; gWi[k] += gr*2*p[k]*(Wik-grsum); gp[k] += gr*Wik*(Wik-2*grsum); k++; } } } } }
void PLearn::SumVarianceOfLinearTransformedCategoricals::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::BinaryVariable.
Definition at line 204 of file SumVarianceOfLinearTransformedCategoricals.cc.
References PLearn::BinaryVariable::build(), and build_().
{ inherited::build(); build_(); }
void PLearn::SumVarianceOfLinearTransformedCategoricals::build_ | ( | ) | [private] |
This does the actual building.
Reimplemented from PLearn::BinaryVariable.
Definition at line 244 of file SumVarianceOfLinearTransformedCategoricals.cc.
Referenced by build(), and SumVarianceOfLinearTransformedCategoricals().
{ // ### 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::SumVarianceOfLinearTransformedCategoricals::classname | ( | ) | const [virtual] |
Reimplemented from PLearn::Object.
Definition at line 60 of file SumVarianceOfLinearTransformedCategoricals.cc.
void PLearn::SumVarianceOfLinearTransformedCategoricals::declareOptions | ( | OptionList & | ol | ) | [static, protected] |
Declares the class options.
Reimplemented from PLearn::BinaryVariable.
Definition at line 226 of file SumVarianceOfLinearTransformedCategoricals.cc.
References PLearn::OptionBase::buildoption, PLearn::declareOption(), PLearn::BinaryVariable::declareOptions(), and groupsizes.
{ // ### 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, "groupsizes", &SumVarianceOfLinearTransformedCategoricals::groupsizes, OptionBase::buildoption, "defines the dimensions of the categorical variables."); // Now call the parent class' declareOptions inherited::declareOptions(ol); }
static const PPath& PLearn::SumVarianceOfLinearTransformedCategoricals::declaringFile | ( | ) | [inline, static] |
Reimplemented from PLearn::BinaryVariable.
Definition at line 105 of file SumVarianceOfLinearTransformedCategoricals.h.
:
//##### Protected Options ###############################################
SumVarianceOfLinearTransformedCategoricals * PLearn::SumVarianceOfLinearTransformedCategoricals::deepCopy | ( | CopiesMap & | copies | ) | const [virtual] |
Reimplemented from PLearn::BinaryVariable.
Definition at line 60 of file SumVarianceOfLinearTransformedCategoricals.cc.
void PLearn::SumVarianceOfLinearTransformedCategoricals::fprop | ( | ) | [virtual] |
compute output given input
Implements PLearn::Variable.
Definition at line 95 of file SumVarianceOfLinearTransformedCategoricals.cc.
References d, PLearn::TVec< T >::data(), groupsizes, i, PLearn::BinaryVariable::input1, PLearn::BinaryVariable::input2, PLearn::TVec< T >::length(), PLearn::TMat< T >::length(), PLearn::P(), PLERROR, PLearn::Variable::value, and PLearn::Var::width().
{ if(input1.width()!=input2.width()) PLERROR("Incompatible sizes: width of P (input1) must equal width of W (input2)"); Mat P = input1->matValue; Mat W = input2->matValue; int d = W.length(); int l = P.length(); // int m = W.width(); // should equal sum of groupsizes double simplesum = 0; double sqsum = 0; int ngroups = groupsizes.length(); const int* pgroupsize = groupsizes.data(); for(int t=0; t<l; t++) { const real* p = P[t]; for(int i=0; i<d; i++) { const real* Wi = W[i]; int k = 0; for(int groupnum=0; groupnum<ngroups; groupnum++) { double tmpsqsum = 0; int gs = pgroupsize[groupnum]; while(gs--) { real Wik = Wi[k]; real pk = p[k]; real Wik_pk = Wik*pk; simplesum += Wik*Wik_pk; tmpsqsum += Wik_pk; k++; } sqsum += tmpsqsum*tmpsqsum; } } } value[0] = simplesum-sqsum; }
OptionList & PLearn::SumVarianceOfLinearTransformedCategoricals::getOptionList | ( | ) | const [virtual] |
Reimplemented from PLearn::Object.
Definition at line 60 of file SumVarianceOfLinearTransformedCategoricals.cc.
OptionMap & PLearn::SumVarianceOfLinearTransformedCategoricals::getOptionMap | ( | ) | const [virtual] |
Reimplemented from PLearn::Object.
Definition at line 60 of file SumVarianceOfLinearTransformedCategoricals.cc.
RemoteMethodMap & PLearn::SumVarianceOfLinearTransformedCategoricals::getRemoteMethodMap | ( | ) | const [virtual] |
Reimplemented from PLearn::Object.
Definition at line 60 of file SumVarianceOfLinearTransformedCategoricals.cc.
void PLearn::SumVarianceOfLinearTransformedCategoricals::makeDeepCopyFromShallowCopy | ( | CopiesMap & | copies | ) | [virtual] |
Transforms a shallow copy into a deep copy.
Reimplemented from PLearn::BinaryVariable.
Definition at line 210 of file SumVarianceOfLinearTransformedCategoricals.cc.
References PLearn::deepCopyField(), group_sum_wik_pk, groupsizes, and PLearn::BinaryVariable::makeDeepCopyFromShallowCopy().
{ inherited::makeDeepCopyFromShallowCopy(copies); // ### Call deepCopyField on all "pointer-like" fields // ### that you wish to be deepCopied rather than // ### shallow-copied. // ### ex: // deepCopyField(trainvec, copies); deepCopyField(groupsizes, copies); deepCopyField(group_sum_wik_pk, copies); // ### If you want to deepCopy a Var field: // varDeepCopyField(somevariable, copies); }
void PLearn::SumVarianceOfLinearTransformedCategoricals::recomputeSize | ( | int & | l, |
int & | w | ||
) | const [virtual] |
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 88 of file SumVarianceOfLinearTransformedCategoricals.cc.
{ l = 1; w = 1; }
Reimplemented from PLearn::BinaryVariable.
Definition at line 105 of file SumVarianceOfLinearTransformedCategoricals.h.
Definition at line 138 of file SumVarianceOfLinearTransformedCategoricals.h.
Referenced by bprop(), and makeDeepCopyFromShallowCopy().
### declare public option fields (such as build options) here Start your comments with Doxygen-compatible comments such as //!
Definition at line 69 of file SumVarianceOfLinearTransformedCategoricals.h.
Referenced by bprop(), declareOptions(), fprop(), and makeDeepCopyFromShallowCopy().