PLearn 0.1
|
#include <RegressionTreeMulticlassLeaveFast.h>
Public Member Functions | |
RegressionTreeMulticlassLeaveFast () | |
virtual | ~RegressionTreeMulticlassLeaveFast () |
virtual string | classname () const |
virtual OptionList & | getOptionList () const |
virtual OptionMap & | getOptionMap () const |
virtual RemoteMethodMap & | getRemoteMethodMap () const |
virtual RegressionTreeMulticlassLeaveFast * | deepCopy (CopiesMap &copies) const |
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 void | build () |
Post-constructor. | |
void | initStats () |
void | addRow (int row) |
void | addRow (int row, real target, real weight) |
void | addRow (int row, Vec outputv, Vec errorv) |
void | addRow (int row, real target, real weight, Vec outputv, Vec errorv) |
void | removeRow (int row, real target, real weight) |
void | removeRow (int row, Vec outputv, Vec errorv) |
void | removeRow (int row, real target, real weight, Vec outputv, Vec errorv) |
void | getOutputAndError (Vec &output, Vec &error) const |
TVec< string > | getOutputNames () const |
void | printStats () |
virtual void | addLeave (PP< RegressionTreeLeave > leave) |
virtual void | removeLeave (PP< RegressionTreeLeave > leave) |
Static Public Member Functions | |
static string | _classname_ () |
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_ |
Private Types | |
typedef RegressionTreeLeave | inherited |
Private Member Functions | |
void | build_ () |
Object-specific post-constructor. | |
Private Attributes | |
int | nb_class |
string | objective_function |
Vec | multiclass_weights_sum |
Definition at line 50 of file RegressionTreeMulticlassLeaveFast.h.
typedef RegressionTreeLeave PLearn::RegressionTreeMulticlassLeaveFast::inherited [private] |
Reimplemented from PLearn::RegressionTreeLeave.
Definition at line 52 of file RegressionTreeMulticlassLeaveFast.h.
PLearn::RegressionTreeMulticlassLeaveFast::RegressionTreeMulticlassLeaveFast | ( | ) |
Definition at line 55 of file RegressionTreeMulticlassLeaveFast.cc.
References build().
: nb_class(-1), objective_function("l1") { build(); }
PLearn::RegressionTreeMulticlassLeaveFast::~RegressionTreeMulticlassLeaveFast | ( | ) | [virtual] |
Definition at line 62 of file RegressionTreeMulticlassLeaveFast.cc.
{ }
string PLearn::RegressionTreeMulticlassLeaveFast::_classname_ | ( | ) | [static] |
Reimplemented from PLearn::RegressionTreeLeave.
Definition at line 53 of file RegressionTreeMulticlassLeaveFast.cc.
OptionList & PLearn::RegressionTreeMulticlassLeaveFast::_getOptionList_ | ( | ) | [static] |
Reimplemented from PLearn::RegressionTreeLeave.
Definition at line 53 of file RegressionTreeMulticlassLeaveFast.cc.
RemoteMethodMap & PLearn::RegressionTreeMulticlassLeaveFast::_getRemoteMethodMap_ | ( | ) | [static] |
Reimplemented from PLearn::RegressionTreeLeave.
Definition at line 53 of file RegressionTreeMulticlassLeaveFast.cc.
Reimplemented from PLearn::RegressionTreeLeave.
Definition at line 53 of file RegressionTreeMulticlassLeaveFast.cc.
Object * PLearn::RegressionTreeMulticlassLeaveFast::_new_instance_for_typemap_ | ( | ) | [static] |
Reimplemented from PLearn::RegressionTreeLeave.
Definition at line 53 of file RegressionTreeMulticlassLeaveFast.cc.
StaticInitializer RegressionTreeMulticlassLeaveFast::_static_initializer_ & PLearn::RegressionTreeMulticlassLeaveFast::_static_initialize_ | ( | ) | [static] |
Reimplemented from PLearn::RegressionTreeLeave.
Definition at line 53 of file RegressionTreeMulticlassLeaveFast.cc.
void PLearn::RegressionTreeMulticlassLeaveFast::addLeave | ( | PP< RegressionTreeLeave > | leave | ) | [virtual] |
Reimplemented from PLearn::RegressionTreeLeave.
Definition at line 245 of file RegressionTreeMulticlassLeaveFast.cc.
References classname(), PLearn::RegressionTreeLeave::length_, multiclass_weights_sum, PLERROR, and PLearn::RegressionTreeLeave::weights_sum.
{ PP<RegressionTreeMulticlassLeaveFast> leave = (PP<RegressionTreeMulticlassLeaveFast>) leave_; if(leave->classname() == classname()){ length_ += leave->length_; weights_sum += leave->weights_sum; multiclass_weights_sum += leave->multiclass_weights_sum; }else PLERROR("In %s::addLeave the leave to add should have the same class. It have %s.", classname().c_str(), leave->classname().c_str()); }
void PLearn::RegressionTreeMulticlassLeaveFast::addRow | ( | int | row | ) | [virtual] |
Reimplemented from PLearn::RegressionTreeLeave.
Definition at line 128 of file RegressionTreeMulticlassLeaveFast.cc.
References PLearn::RegressionTreeLeave::train_set.
Referenced by addRow().
{ real weight = train_set->getWeight(row); real target = train_set->getTarget(row); RegressionTreeMulticlassLeaveFast::addRow(row, target, weight); }
void PLearn::RegressionTreeMulticlassLeaveFast::addRow | ( | int | row, |
real | target, | ||
real | weight | ||
) | [virtual] |
Reimplemented from PLearn::RegressionTreeLeave.
Definition at line 142 of file RegressionTreeMulticlassLeaveFast.cc.
References PLearn::RegressionTreeLeave::length_, multiclass_weights_sum, and PLearn::RegressionTreeLeave::weights_sum.
{ length_ += 1; weights_sum += weight; multiclass_weights_sum[int(target)] += weight; }
void PLearn::RegressionTreeMulticlassLeaveFast::addRow | ( | int | row, |
Vec | outputv, | ||
Vec | errorv | ||
) | [virtual] |
Reimplemented from PLearn::RegressionTreeLeave.
Definition at line 149 of file RegressionTreeMulticlassLeaveFast.cc.
References addRow(), and getOutputAndError().
{ RegressionTreeMulticlassLeaveFast::addRow(row); RegressionTreeMulticlassLeaveFast::getOutputAndError(outputv,errorv); }
void PLearn::RegressionTreeMulticlassLeaveFast::addRow | ( | int | row, |
real | target, | ||
real | weight, | ||
Vec | outputv, | ||
Vec | errorv | ||
) | [virtual] |
Reimplemented from PLearn::RegressionTreeLeave.
Definition at line 135 of file RegressionTreeMulticlassLeaveFast.cc.
References addRow(), and getOutputAndError().
{ RegressionTreeMulticlassLeaveFast::addRow(row, target, weight); RegressionTreeMulticlassLeaveFast::getOutputAndError(outputv,errorv); }
void PLearn::RegressionTreeMulticlassLeaveFast::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::RegressionTreeLeave.
Definition at line 99 of file RegressionTreeMulticlassLeaveFast.cc.
References PLearn::RegressionTreeLeave::build(), and build_().
Referenced by RegressionTreeMulticlassLeaveFast().
{ inherited::build(); build_(); }
void PLearn::RegressionTreeMulticlassLeaveFast::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::RegressionTreeLeave.
Definition at line 105 of file RegressionTreeMulticlassLeaveFast.cc.
Referenced by build().
{ }
string PLearn::RegressionTreeMulticlassLeaveFast::classname | ( | ) | const [virtual] |
Reimplemented from PLearn::RegressionTreeLeave.
Definition at line 53 of file RegressionTreeMulticlassLeaveFast.cc.
Referenced by addLeave(), and removeLeave().
void PLearn::RegressionTreeMulticlassLeaveFast::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::RegressionTreeLeave.
Definition at line 66 of file RegressionTreeMulticlassLeaveFast.cc.
References PLearn::OptionBase::buildoption, PLearn::declareOption(), PLearn::RegressionTreeLeave::declareOptions(), PLearn::OptionBase::learntoption, PLearn::RegressionTreeLeave::loss_function_factor, multiclass_weights_sum, nb_class, objective_function, and PLearn::redeclareOption().
{ inherited::declareOptions(ol); declareOption(ol, "nb_class", &RegressionTreeMulticlassLeaveFast::nb_class, OptionBase::buildoption, "The number of class. Should be numbered from 0 to nb_class -1.\n" ); declareOption(ol, "objective_function", &RegressionTreeMulticlassLeaveFast::objective_function, OptionBase::buildoption, "The function to be used to compute the leave error.\n" "Current supported values are l1 and l2 (default is l1)."); declareOption(ol, "multiclass_weights_sum", &RegressionTreeMulticlassLeaveFast::multiclass_weights_sum, OptionBase::learntoption, "A vector to count the weight sum of each possible output " "for the sample in this leave.\n"); redeclareOption(ol, "loss_function_factor", &RegressionTreeMulticlassLeaveFast::loss_function_factor, OptionBase::learntoption, "The loss fct factor. Depend of the objective_function.\n"); }
static const PPath& PLearn::RegressionTreeMulticlassLeaveFast::declaringFile | ( | ) | [inline, static] |
Reimplemented from PLearn::RegressionTreeLeave.
Definition at line 72 of file RegressionTreeMulticlassLeaveFast.h.
: void build_();
RegressionTreeMulticlassLeaveFast * PLearn::RegressionTreeMulticlassLeaveFast::deepCopy | ( | CopiesMap & | copies | ) | const [virtual] |
Reimplemented from PLearn::RegressionTreeLeave.
Definition at line 53 of file RegressionTreeMulticlassLeaveFast.cc.
OptionList & PLearn::RegressionTreeMulticlassLeaveFast::getOptionList | ( | ) | const [virtual] |
Reimplemented from PLearn::RegressionTreeLeave.
Definition at line 53 of file RegressionTreeMulticlassLeaveFast.cc.
OptionMap & PLearn::RegressionTreeMulticlassLeaveFast::getOptionMap | ( | ) | const [virtual] |
Reimplemented from PLearn::RegressionTreeLeave.
Definition at line 53 of file RegressionTreeMulticlassLeaveFast.cc.
void PLearn::RegressionTreeMulticlassLeaveFast::getOutputAndError | ( | Vec & | output, |
Vec & | error | ||
) | const [virtual] |
Reimplemented from PLearn::RegressionTreeLeave.
Definition at line 178 of file RegressionTreeMulticlassLeaveFast.cc.
References PLearn::abs(), PLearn::TVec< T >::clear(), PLearn::RegressionTreeLeave::length_, PLearn::RegressionTreeLeave::loss_function_factor, PLearn::RegressionTreeLeave::missing_leave, MISSING_VALUE, multiclass_weights_sum, nb_class, objective_function, PLearn::RegressionTreeLeave::output_confidence_target, PLERROR, PLearn::pow(), and PLearn::RegressionTreeLeave::weights_sum.
Referenced by addRow(), printStats(), and removeRow().
{ #ifdef BOUNDCHECK if(nb_class<=0) PLERROR("In RegressionTreeMulticlassLeaveFast::getOutputAndError() -" " nb_class must be set."); #endif if(length_==0){ output.clear(); output[0]=MISSING_VALUE; error.clear(); return; } int mc_winer = 0; real conf = 0; //index of the max. Is their an optimized version? for (int mc_ind = 1; mc_ind < nb_class; mc_ind++) { if (multiclass_weights_sum[mc_ind] > multiclass_weights_sum[mc_winer]) mc_winer = mc_ind; } output[0] = mc_winer; if (missing_leave) { error[0] = 0.0; error[1] = weights_sum; error[2] = 0.0; } else { conf = multiclass_weights_sum[mc_winer] / weights_sum; error[0] = 0.0; if (objective_function == "l1") { for (int mc_ind = 0; mc_ind < nb_class;mc_ind++) { error[0] += abs(mc_winer - mc_ind) * multiclass_weights_sum[mc_ind]; } } else { for (int mc_ind = 0; mc_ind < nb_class;mc_ind++) { error[0] += pow(mc_winer - mc_ind, 2.) * multiclass_weights_sum[mc_ind]; } } error[0] *= loss_function_factor * length_ / weights_sum; if (error[0] < 1E-10) error[0] = 0.0; if (error[0] > weights_sum * loss_function_factor) error[2] = weights_sum * loss_function_factor; else error[2] = error[0]; error[1] = (1.0 - conf) * length_; } if(output_confidence_target) output[1] = conf; }
TVec< string > PLearn::RegressionTreeMulticlassLeaveFast::getOutputNames | ( | ) | const [virtual] |
Reimplemented from PLearn::RegressionTreeLeave.
Definition at line 236 of file RegressionTreeMulticlassLeaveFast.cc.
References PLearn::TVec< T >::append(), and PLearn::RegressionTreeLeave::output_confidence_target.
{ TVec<string> ret; ret.append("class_pred"); if(output_confidence_target) ret.append("confidence"); return ret; }
RemoteMethodMap & PLearn::RegressionTreeMulticlassLeaveFast::getRemoteMethodMap | ( | ) | const [virtual] |
Reimplemented from PLearn::RegressionTreeLeave.
Definition at line 53 of file RegressionTreeMulticlassLeaveFast.cc.
void PLearn::RegressionTreeMulticlassLeaveFast::initStats | ( | ) | [virtual] |
Reimplemented from PLearn::RegressionTreeLeave.
Definition at line 109 of file RegressionTreeMulticlassLeaveFast.cc.
References PLearn::TVec< T >::fill(), PLearn::RegressionTreeLeave::length_, PLearn::RegressionTreeLeave::loss_function_factor, PLearn::RegressionTreeLeave::loss_function_weight, multiclass_weights_sum, nb_class, objective_function, PLearn::pow(), PLearn::TVec< T >::resize(), and PLearn::RegressionTreeLeave::weights_sum.
{ length_ = 0; weights_sum = 0.0; if (loss_function_weight != 0.0) { if(objective_function == "l1") loss_function_factor = 2.0 / loss_function_weight; else loss_function_factor = 2.0 / pow(loss_function_weight, 2); } else { loss_function_factor = 1.0; } multiclass_weights_sum.resize(nb_class); multiclass_weights_sum.fill(0); }
void PLearn::RegressionTreeMulticlassLeaveFast::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::RegressionTreeLeave.
Definition at line 92 of file RegressionTreeMulticlassLeaveFast.cc.
References PLearn::deepCopyField(), PLearn::RegressionTreeLeave::makeDeepCopyFromShallowCopy(), multiclass_weights_sum, and objective_function.
{ inherited::makeDeepCopyFromShallowCopy(copies); deepCopyField(objective_function, copies); deepCopyField(multiclass_weights_sum, copies); }
void PLearn::RegressionTreeMulticlassLeaveFast::printStats | ( | ) | [virtual] |
Reimplemented from PLearn::RegressionTreeLeave.
Definition at line 269 of file RegressionTreeMulticlassLeaveFast.cc.
References PLearn::endl(), getOutputAndError(), PLearn::RegressionTreeLeave::length_, multiclass_weights_sum, and PLearn::RegressionTreeLeave::weights_sum.
{ cout << " l " << length_; Vec output(2); Vec error(3); getOutputAndError(output,error); cout << " o0 " << output[0]; cout << " o1 " << output[1]; cout << " e0 " << error[0]; cout << " e1 " << error[1]; cout << " ws " << weights_sum; cout << endl; cout << " mws " << multiclass_weights_sum << endl; }
void PLearn::RegressionTreeMulticlassLeaveFast::removeLeave | ( | PP< RegressionTreeLeave > | leave | ) | [virtual] |
Reimplemented from PLearn::RegressionTreeLeave.
Definition at line 257 of file RegressionTreeMulticlassLeaveFast.cc.
References classname(), PLearn::RegressionTreeLeave::length_, multiclass_weights_sum, PLERROR, and PLearn::RegressionTreeLeave::weights_sum.
{ PP<RegressionTreeMulticlassLeaveFast> leave = (PP<RegressionTreeMulticlassLeaveFast>) leave_; if(leave->classname() == classname()){ length_ -= leave->length_; weights_sum -= leave->weights_sum; multiclass_weights_sum -= leave->multiclass_weights_sum; }else PLERROR("In %s::addLeave the leave to add should have the same class. It have %s.", classname().c_str(), leave->classname().c_str()); }
void PLearn::RegressionTreeMulticlassLeaveFast::removeRow | ( | int | row, |
Vec | outputv, | ||
Vec | errorv | ||
) | [virtual] |
Reimplemented from PLearn::RegressionTreeLeave.
Definition at line 155 of file RegressionTreeMulticlassLeaveFast.cc.
References removeRow(), and PLearn::RegressionTreeLeave::train_set.
{ real weight = train_set->getWeight(row); real target = train_set->getTarget(row); RegressionTreeMulticlassLeaveFast::removeRow(row,target,weight,outputv,errorv); }
void PLearn::RegressionTreeMulticlassLeaveFast::removeRow | ( | int | row, |
real | target, | ||
real | weight | ||
) | [virtual] |
Reimplemented from PLearn::RegressionTreeLeave.
Definition at line 168 of file RegressionTreeMulticlassLeaveFast.cc.
References PLearn::RegressionTreeLeave::length_, multiclass_weights_sum, PLASSERT, and PLearn::RegressionTreeLeave::weights_sum.
Referenced by removeRow().
{ length_ -= 1; weights_sum -= weight; PLASSERT(length_>=0); PLASSERT(weights_sum>=0); PLASSERT(length_>0 || weights_sum==0); multiclass_weights_sum[int(target)] -= weight; }
void PLearn::RegressionTreeMulticlassLeaveFast::removeRow | ( | int | row, |
real | target, | ||
real | weight, | ||
Vec | outputv, | ||
Vec | errorv | ||
) | [virtual] |
Reimplemented from PLearn::RegressionTreeLeave.
Definition at line 162 of file RegressionTreeMulticlassLeaveFast.cc.
References getOutputAndError(), and removeRow().
{ RegressionTreeMulticlassLeaveFast::removeRow(row,target,weight); RegressionTreeMulticlassLeaveFast::getOutputAndError(outputv,errorv); }
Reimplemented from PLearn::RegressionTreeLeave.
Definition at line 72 of file RegressionTreeMulticlassLeaveFast.h.
Definition at line 67 of file RegressionTreeMulticlassLeaveFast.h.
Referenced by addLeave(), addRow(), declareOptions(), getOutputAndError(), initStats(), makeDeepCopyFromShallowCopy(), printStats(), removeLeave(), and removeRow().
Definition at line 60 of file RegressionTreeMulticlassLeaveFast.h.
Referenced by declareOptions(), getOutputAndError(), and initStats().
string PLearn::RegressionTreeMulticlassLeaveFast::objective_function [private] |
Definition at line 61 of file RegressionTreeMulticlassLeaveFast.h.
Referenced by declareOptions(), getOutputAndError(), initStats(), and makeDeepCopyFromShallowCopy().