PLearn 0.1
|
#include <ComputePurenneError.h>
Public Member Functions | |
ComputePurenneError () | |
virtual | ~ComputePurenneError () |
virtual string | classname () const |
virtual OptionList & | getOptionList () const |
virtual OptionMap & | getOptionMap () const |
virtual RemoteMethodMap & | getRemoteMethodMap () const |
virtual ComputePurenneError * | deepCopy (CopiesMap &copies) const |
virtual void | makeDeepCopyFromShallowCopy (CopiesMap &copies) |
Transforms a shallow copy into a deep copy. | |
virtual void | build () |
Finish building the object; just call inherited::build followed by build_() | |
virtual void | train () |
*** SUBCLASS WRITING: *** | |
virtual void | forget () |
*** SUBCLASS WRITING: *** | |
virtual int | outputsize () const |
SUBCLASS WRITING: override this so that it returns the size of this learner's output, as a function of its inputsize(), targetsize() and set options. | |
virtual TVec< string > | getTrainCostNames () const |
*** SUBCLASS WRITING: *** | |
virtual TVec< string > | getTestCostNames () const |
*** SUBCLASS WRITING: *** | |
virtual void | computeOutput (const Vec &input, Vec &output) const |
*** SUBCLASS WRITING: *** | |
virtual void | computeOutputAndCosts (const Vec &input, const Vec &target, Vec &output, Vec &costs) const |
Default calls computeOutput and computeCostsFromOutputs. | |
virtual void | computeCostsFromOutputs (const Vec &input, const Vec &output, const Vec &target, Vec &costs) const |
*** SUBCLASS WRITING: *** | |
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) |
Declares this class' options. | |
Static Public Attributes | |
static StaticInitializer | _static_initializer_ |
Private Types | |
typedef PLearner | inherited |
Private Member Functions | |
void | build_ () |
**** SUBCLASS WRITING: **** |
Definition at line 53 of file ComputePurenneError.h.
typedef PLearner PLearn::ComputePurenneError::inherited [private] |
Reimplemented from PLearn::PLearner.
Definition at line 55 of file ComputePurenneError.h.
PLearn::ComputePurenneError::ComputePurenneError | ( | ) |
Definition at line 52 of file ComputePurenneError.cc.
{ }
PLearn::ComputePurenneError::~ComputePurenneError | ( | ) | [virtual] |
Definition at line 56 of file ComputePurenneError.cc.
{ }
string PLearn::ComputePurenneError::_classname_ | ( | ) | [static] |
Reimplemented from PLearn::PLearner.
Definition at line 50 of file ComputePurenneError.cc.
OptionList & PLearn::ComputePurenneError::_getOptionList_ | ( | ) | [static] |
Reimplemented from PLearn::PLearner.
Definition at line 50 of file ComputePurenneError.cc.
RemoteMethodMap & PLearn::ComputePurenneError::_getRemoteMethodMap_ | ( | ) | [static] |
Reimplemented from PLearn::PLearner.
Definition at line 50 of file ComputePurenneError.cc.
Reimplemented from PLearn::PLearner.
Definition at line 50 of file ComputePurenneError.cc.
Object * PLearn::ComputePurenneError::_new_instance_for_typemap_ | ( | ) | [static] |
Reimplemented from PLearn::Object.
Definition at line 50 of file ComputePurenneError.cc.
StaticInitializer ComputePurenneError::_static_initializer_ & PLearn::ComputePurenneError::_static_initialize_ | ( | ) | [static] |
Reimplemented from PLearn::PLearner.
Definition at line 50 of file ComputePurenneError.cc.
void PLearn::ComputePurenneError::build | ( | ) | [virtual] |
Finish building the object; just call inherited::build followed by build_()
Reimplemented from PLearn::PLearner.
Definition at line 70 of file ComputePurenneError.cc.
{ inherited::build(); build_(); }
void PLearn::ComputePurenneError::build_ | ( | ) | [private] |
**** SUBCLASS WRITING: ****
This method should finish building of the object, according to set 'options', in *any* situation.
Typical situations include:
You can assume that the parent class' build_() has already been called.
A typical build method will want to know the inputsize(), targetsize() and outputsize(), and may also want to check whether train_set->hasWeights(). All these methods require a train_set to be set, so the first thing you may want to do, is check if(train_set), before doing any heavy building...
Note: build() is always called by setTrainingSet.
Reimplemented from PLearn::PLearner.
Definition at line 76 of file ComputePurenneError.cc.
{ }
string PLearn::ComputePurenneError::classname | ( | ) | const [virtual] |
Reimplemented from PLearn::Object.
Definition at line 50 of file ComputePurenneError.cc.
void PLearn::ComputePurenneError::computeCostsFromOutputs | ( | const Vec & | input, |
const Vec & | output, | ||
const Vec & | target, | ||
Vec & | costs | ||
) | const [virtual] |
*** SUBCLASS WRITING: ***
This should be defined in subclasses to compute the weighted costs from already computed output. The costs should correspond to the cost names returned by getTestCostNames().
NOTE: In exotic cases, the cost may also depend on some info in the input, that's why the method also gets so see it.
Implements PLearn::PLearner.
Definition at line 142 of file ComputePurenneError.cc.
References PLearn::pow().
{ costsv[0] = pow((outputv[0] - targetv[0]), 2); costsv[1] = outputv[1] == targetv[1] ? 0 : 1; costsv[2] = int(round(fabs(outputv[1] - targetv[1]))); costsv[3] = pow((outputv[1] - targetv[1]), 2); }
*** SUBCLASS WRITING: ***
This should be defined in subclasses to compute the output from the input.
Reimplemented from PLearn::PLearner.
Definition at line 130 of file ComputePurenneError.cc.
{ outputv[0] = inputv[0]; outputv[1] = inputv[1]; }
void PLearn::ComputePurenneError::computeOutputAndCosts | ( | const Vec & | input, |
const Vec & | target, | ||
Vec & | output, | ||
Vec & | costs | ||
) | const [virtual] |
Default calls computeOutput and computeCostsFromOutputs.
You may override this if you have a more efficient way to compute both output and weighted costs at the same time.
Reimplemented from PLearn::PLearner.
Definition at line 136 of file ComputePurenneError.cc.
{ computeOutput(inputv, outputv); computeCostsFromOutputs(inputv, outputv, targetv, costsv); }
void PLearn::ComputePurenneError::declareOptions | ( | OptionList & | ol | ) | [static] |
Declares this class' options.
Reimplemented from PLearn::PLearner.
Definition at line 60 of file ComputePurenneError.cc.
{ inherited::declareOptions(ol); }
static const PPath& PLearn::ComputePurenneError::declaringFile | ( | ) | [inline, static] |
Reimplemented from PLearn::PLearner.
Definition at line 61 of file ComputePurenneError.h.
: void build_();
ComputePurenneError * PLearn::ComputePurenneError::deepCopy | ( | CopiesMap & | copies | ) | const [virtual] |
Reimplemented from PLearn::PLearner.
Definition at line 50 of file ComputePurenneError.cc.
void PLearn::ComputePurenneError::forget | ( | ) | [virtual] |
*** SUBCLASS WRITING: ***
(Re-)initializes the PLearner in its fresh state (that state may depend on the 'seed' option) and sets 'stage' back to 0 (this is the stage of a fresh learner!)
A typical forget() method should do the following:
This method is typically called by the build_() method, after it has finished setting up the parameters, and if it deemed useful to set or reset the learner in its fresh state. (remember build may be called after modifying options that do not necessarily require the learner to restart from a fresh state...) forget is also called by the setTrainingSet method, after calling build(), so it will generally be called TWICE during setTrainingSet!
Reimplemented from PLearn::PLearner.
Definition at line 106 of file ComputePurenneError.cc.
{ }
OptionList & PLearn::ComputePurenneError::getOptionList | ( | ) | const [virtual] |
Reimplemented from PLearn::Object.
Definition at line 50 of file ComputePurenneError.cc.
OptionMap & PLearn::ComputePurenneError::getOptionMap | ( | ) | const [virtual] |
Reimplemented from PLearn::Object.
Definition at line 50 of file ComputePurenneError.cc.
RemoteMethodMap & PLearn::ComputePurenneError::getRemoteMethodMap | ( | ) | const [virtual] |
Reimplemented from PLearn::Object.
Definition at line 50 of file ComputePurenneError.cc.
TVec< string > PLearn::ComputePurenneError::getTestCostNames | ( | ) | const [virtual] |
*** SUBCLASS WRITING: ***
This should return the names of the costs computed by computeCostsFromOutputs.
Implements PLearn::PLearner.
Definition at line 125 of file ComputePurenneError.cc.
{ return getTrainCostNames(); }
TVec< string > PLearn::ComputePurenneError::getTrainCostNames | ( | ) | const [virtual] |
*** SUBCLASS WRITING: ***
This should return the names of the objective costs that the train method computes and for which it updates the VecStatsCollector train_stats.
Implements PLearn::PLearner.
Definition at line 115 of file ComputePurenneError.cc.
{ TVec<string> return_msg(4); return_msg[0] = "mse"; return_msg[1] = "class_error"; return_msg[2] = "linear_class_error"; return_msg[3] = "square_class_error"; return return_msg; }
void PLearn::ComputePurenneError::makeDeepCopyFromShallowCopy | ( | CopiesMap & | copies | ) | [virtual] |
Transforms a shallow copy into a deep copy.
Reimplemented from PLearn::PLearner.
Definition at line 65 of file ComputePurenneError.cc.
{ inherited::makeDeepCopyFromShallowCopy(copies); }
int PLearn::ComputePurenneError::outputsize | ( | ) | const [virtual] |
SUBCLASS WRITING: override this so that it returns the size of this learner's output, as a function of its inputsize(), targetsize() and set options.
Implements PLearn::PLearner.
Definition at line 110 of file ComputePurenneError.cc.
{
return 2;
}
void PLearn::ComputePurenneError::train | ( | ) | [virtual] |
*** SUBCLASS WRITING: ***
The role of the train method is to bring the learner up to stage==nstages, updating the stats with training costs measured on-line in the process.
TYPICAL CODE:
static Vec input; // static so we don't reallocate/deallocate memory each time... static Vec target; // (but be careful that static means shared!) input.resize(inputsize()); // the train_set's inputsize() target.resize(targetsize()); // the train_set's targetsize() real weight; if(!train_stats) // make a default stats collector, in case there's none train_stats = new VecStatsCollector(); if(nstages<stage) // asking to revert to a previous stage! forget(); // reset the learner to stage=0 while(stage<nstages) { // clear statistics of previous epoch train_stats->forget(); //... train for 1 stage, and update train_stats, // using train_set->getSample(input, target, weight); // and train_stats->update(train_costs) ++stage; train_stats->finalize(); // finalize statistics for this epoch }
Implements PLearn::PLearner.
Definition at line 80 of file ComputePurenneError.cc.
References PLearn::ProgressBar::update().
{ int row; Vec sample_input(train_set->inputsize()); Vec sample_target(train_set->targetsize()); real sample_weight; Vec sample_output(2); Vec sample_costs(4); ProgressBar* pb = NULL; if (report_progress) { pb = new ProgressBar("Purenne error: computing the train statistics: ", train_set->length()); } train_stats->forget(); for (row = 0; row < train_set->length(); row++) { train_set->getExample(row, sample_input, sample_target, sample_weight); computeOutput(sample_input, sample_output); computeCostsFromOutputs(sample_input, sample_output, sample_target, sample_costs); train_stats->update(sample_costs); if (report_progress) pb->update(row); } train_stats->finalize(); if (report_progress) delete pb; }
Reimplemented from PLearn::PLearner.
Definition at line 61 of file ComputePurenneError.h.