PLearn 0.1
|
The first sentence should be a BRIEF DESCRIPTION of what the class does. More...
#include <RankingFromKernel.h>
Public Member Functions | |
RankingFromKernel () | |
Default constructor. | |
virtual int | outputsize () const |
Returns the size of this learner's output, (which typically may depend on its inputsize(), targetsize() and set options). | |
virtual void | forget () |
(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!). | |
virtual void | train () |
The role of the train method is to bring the learner up to stage==nstages, updating the train_stats collector with training costs measured on-line in the process. | |
virtual void | computeOutput (const Vec &input, Vec &output) const |
Computes the output from the input. | |
virtual void | computeCostsFromOutputs (const Vec &input, const Vec &output, const Vec &target, Vec &costs) const |
Computes the costs from already computed output. | |
virtual TVec< std::string > | getTestCostNames () const |
Returns the names of the costs computed by computeCostsFromOutpus (and thus the test method). | |
virtual TVec< std::string > | getTrainCostNames () const |
Returns the names of the objective costs that the train method computes and for which it updates the VecStatsCollector train_stats. | |
virtual string | classname () const |
virtual OptionList & | getOptionList () const |
virtual OptionMap & | getOptionMap () const |
virtual RemoteMethodMap & | getRemoteMethodMap () const |
virtual RankingFromKernel * | deepCopy (CopiesMap &copies) const |
virtual void | build () |
Finish building the object; just call inherited::build followed by build_() | |
virtual void | makeDeepCopyFromShallowCopy (CopiesMap &copies) |
Transforms a shallow copy into a deep copy. | |
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 () |
Public Attributes | |
PP< Kernel > | logKernel |
### 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. | |
Protected Attributes | |
Vec | x |
Vec | target |
Vec | log_act |
Vec | log_inact |
Private Types | |
typedef PLearner | inherited |
Private Member Functions | |
void | build_ () |
This does the actual building. |
The first sentence should be a BRIEF DESCRIPTION of what the class does.
Place the rest of the class programmer documentation here. Doxygen supports Javadoc-style comments. See http://www.doxygen.org/manual.html
Definition at line 62 of file RankingFromKernel.h.
typedef PLearner PLearn::RankingFromKernel::inherited [private] |
Reimplemented from PLearn::PLearner.
Definition at line 64 of file RankingFromKernel.h.
PLearn::RankingFromKernel::RankingFromKernel | ( | ) |
Default constructor.
Definition at line 55 of file RankingFromKernel.cc.
{ // ... // ### You may (or not) want to call build_() to finish building the object // ### (doing so assumes the parent classes' build_() have been called too // ### in the parent classes' constructors, something that you must ensure) }
string PLearn::RankingFromKernel::_classname_ | ( | ) | [static] |
Reimplemented from PLearn::PLearner.
Definition at line 53 of file RankingFromKernel.cc.
OptionList & PLearn::RankingFromKernel::_getOptionList_ | ( | ) | [static] |
Reimplemented from PLearn::PLearner.
Definition at line 53 of file RankingFromKernel.cc.
RemoteMethodMap & PLearn::RankingFromKernel::_getRemoteMethodMap_ | ( | ) | [static] |
Reimplemented from PLearn::PLearner.
Definition at line 53 of file RankingFromKernel.cc.
Reimplemented from PLearn::PLearner.
Definition at line 53 of file RankingFromKernel.cc.
Object * PLearn::RankingFromKernel::_new_instance_for_typemap_ | ( | ) | [static] |
Reimplemented from PLearn::Object.
Definition at line 53 of file RankingFromKernel.cc.
StaticInitializer RankingFromKernel::_static_initializer_ & PLearn::RankingFromKernel::_static_initialize_ | ( | ) | [static] |
Reimplemented from PLearn::PLearner.
Definition at line 53 of file RankingFromKernel.cc.
void PLearn::RankingFromKernel::build | ( | ) | [virtual] |
Finish building the object; just call inherited::build followed by build_()
Reimplemented from PLearn::PLearner.
Definition at line 93 of file RankingFromKernel.cc.
{ inherited::build(); build_(); }
void PLearn::RankingFromKernel::build_ | ( | ) | [private] |
This does the actual building.
Reimplemented from PLearn::PLearner.
Definition at line 81 of file RankingFromKernel.cc.
{ // ### 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::RankingFromKernel::classname | ( | ) | const [virtual] |
Reimplemented from PLearn::Object.
Definition at line 53 of file RankingFromKernel.cc.
void PLearn::RankingFromKernel::computeCostsFromOutputs | ( | const Vec & | input, |
const Vec & | output, | ||
const Vec & | target, | ||
Vec & | costs | ||
) | const [virtual] |
Computes the costs from already computed output.
Implements PLearn::PLearner.
Definition at line 196 of file RankingFromKernel.cc.
References PLearn::fast_exact_is_equal(), and PLearn::TVec< T >::resize().
{ costs.resize(nTestCosts()); if(fast_exact_is_equal(target[0],1)) costs[0] = output[0]; else costs[0] = -output[0]; }
Computes the output from the input.
Reimplemented from PLearn::PLearner.
Definition at line 171 of file RankingFromKernel.cc.
References PLearn::exp(), PLearn::fast_exact_is_equal(), i, PLearn::logadd(), PLearn::TVec< T >::resize(), and x.
{ // Compute the output from the input. // int nout = outputsize(); // output.resize(nout); // ... int i; real log_k,log_result, weight; log_act.resize(0); log_inact.resize(0); for (i=0; i < train_set->length();i++){ train_set->getExample(i,x, target, weight); log_k = logKernel->evaluate(input,x); if ( fast_exact_is_equal(target[0],1)) { log_act.append(log_k); }else{ log_inact.append(log_k); } } log_result = logadd(log_act) - logadd(log_inact); output.resize(1); output[0] = exp(log_result); }
void PLearn::RankingFromKernel::declareOptions | ( | OptionList & | ol | ) | [static, protected] |
Declares the class options.
Reimplemented from PLearn::PLearner.
Definition at line 65 of file RankingFromKernel.cc.
References PLearn::OptionBase::buildoption, PLearn::declareOption(), and logKernel.
{ // ### 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. Another possible flag to be combined with // ### is OptionBase::nosave // ### ex: declareOption(ol, "logKernel", &RankingFromKernel::logKernel, OptionBase::buildoption, "A kernel taking an input and returning the log of its result."); // Now call the parent class' declareOptions inherited::declareOptions(ol); }
static const PPath& PLearn::RankingFromKernel::declaringFile | ( | ) | [inline, static] |
RankingFromKernel * PLearn::RankingFromKernel::deepCopy | ( | CopiesMap & | copies | ) | const [virtual] |
Reimplemented from PLearn::PLearner.
Definition at line 53 of file RankingFromKernel.cc.
void PLearn::RankingFromKernel::forget | ( | ) | [virtual] |
(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!).
(Re-)initialize 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:
Reimplemented from PLearn::PLearner.
Definition at line 122 of file RankingFromKernel.cc.
{ }
OptionList & PLearn::RankingFromKernel::getOptionList | ( | ) | const [virtual] |
Reimplemented from PLearn::Object.
Definition at line 53 of file RankingFromKernel.cc.
OptionMap & PLearn::RankingFromKernel::getOptionMap | ( | ) | const [virtual] |
Reimplemented from PLearn::Object.
Definition at line 53 of file RankingFromKernel.cc.
RemoteMethodMap & PLearn::RankingFromKernel::getRemoteMethodMap | ( | ) | const [virtual] |
Reimplemented from PLearn::Object.
Definition at line 53 of file RankingFromKernel.cc.
TVec< string > PLearn::RankingFromKernel::getTestCostNames | ( | ) | const [virtual] |
Returns the names of the costs computed by computeCostsFromOutpus (and thus the test method).
Implements PLearn::PLearner.
Definition at line 206 of file RankingFromKernel.cc.
References PLearn::TVec< T >::append(), and PLearn::TVec< T >::isEmpty().
{ static TVec<string> cost; if (cost.isEmpty()) cost.append("lift_output"); return cost; }
TVec< string > PLearn::RankingFromKernel::getTrainCostNames | ( | ) | const [virtual] |
Returns 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 214 of file RankingFromKernel.cc.
References PLearn::TVec< T >::resize().
{ // Return the names of the objective costs that the train method computes and // for which it updates the VecStatsCollector train_stats // (these may or may not be exactly the same as what's returned by getTestCostNames). // ... static TVec<string> costs; costs.resize(0); return costs; }
void PLearn::RankingFromKernel::makeDeepCopyFromShallowCopy | ( | CopiesMap & | copies | ) | [virtual] |
Transforms a shallow copy into a deep copy.
Reimplemented from PLearn::PLearner.
Definition at line 100 of file RankingFromKernel.cc.
References PLERROR.
{ inherited::makeDeepCopyFromShallowCopy(copies); // ### Call deepCopyField on all "pointer-like" fields // ### that you wish to be deepCopied rather than // ### shallow-copied. // ### ex: // deepCopyField(trainvec, copies); // ### Remove this line when you have fully implemented this method. PLERROR("RankingFromKernel::makeDeepCopyFromShallowCopy not fully (correctly) implemented yet!"); }
int PLearn::RankingFromKernel::outputsize | ( | ) | const [virtual] |
Returns the size of this learner's output, (which typically may depend on its inputsize(), targetsize() and set options).
Implements PLearn::PLearner.
Definition at line 115 of file RankingFromKernel.cc.
{ // Compute and return the size of this learner's output (which typically // may depend on its inputsize(), targetsize() and set options). return 1; }
void PLearn::RankingFromKernel::train | ( | ) | [virtual] |
The role of the train method is to bring the learner up to stage==nstages, updating the train_stats collector with training costs measured on-line in the process.
Implements PLearn::PLearner.
Definition at line 134 of file RankingFromKernel.cc.
References PLERROR, and PLWARNING.
{ // The role of the train method is to bring the learner up to stage==nstages, // updating train_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 // This generic PLearner method does a number of standard stuff useful for // (almost) any learner, and return 'false' if no training should take // place. See PLearner.h for more details. if (!initTrain()) return; 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 } */ if (train_set->targetsize() != 1) PLERROR("This PLearner is not built for multi-target problems"); PLWARNING("Train not implemented"); }
Reimplemented from PLearn::PLearner.
Definition at line 141 of file RankingFromKernel.h.
Vec PLearn::RankingFromKernel::log_act [mutable, protected] |
Definition at line 156 of file RankingFromKernel.h.
Vec PLearn::RankingFromKernel::log_inact [mutable, protected] |
Definition at line 156 of file RankingFromKernel.h.
### declare public option fields (such as build options) here Start your comments with Doxygen-compatible comments such as //!
A kernel taking an input and returning the log of it's result.
Definition at line 73 of file RankingFromKernel.h.
Referenced by declareOptions().
Vec PLearn::RankingFromKernel::target [mutable, protected] |
Definition at line 152 of file RankingFromKernel.h.
Vec PLearn::RankingFromKernel::x [mutable, protected] |
Definition at line 152 of file RankingFromKernel.h.