PLearn 0.1
Public Member Functions | Static Public Member Functions | Public Attributes | Static Public Attributes | Static Protected Member Functions | Protected Attributes | Private Types | Private Member Functions
PLearn::RankingFromKernel Class Reference

The first sentence should be a BRIEF DESCRIPTION of what the class does. More...

#include <RankingFromKernel.h>

Inheritance diagram for PLearn::RankingFromKernel:
Inheritance graph
[legend]
Collaboration diagram for PLearn::RankingFromKernel:
Collaboration graph
[legend]

List of all members.

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 OptionListgetOptionList () const
virtual OptionMapgetOptionMap () const
virtual RemoteMethodMapgetRemoteMethodMap () const
virtual RankingFromKerneldeepCopy (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 PPathdeclaringFile ()

Public Attributes

PP< KernellogKernel
 ### 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.

Detailed Description

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

Todo:
Write class to-do's here if there are any.
Deprecated:
Write deprecated stuff here if there is any. Indicate what else should be used instead.

Definition at line 62 of file RankingFromKernel.h.


Member Typedef Documentation

Reimplemented from PLearn::PLearner.

Definition at line 64 of file RankingFromKernel.h.


Constructor & Destructor Documentation

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)
}

Member Function Documentation

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.

bool PLearn::RankingFromKernel::_isa_ ( const Object o) [static]

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.

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];
}                                

Here is the call graph for this function:

void PLearn::RankingFromKernel::computeOutput ( const Vec input,
Vec output 
) const [virtual]

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);
}

Here is the call graph for this function:

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);
}

Here is the call graph for this function:

static const PPath& PLearn::RankingFromKernel::declaringFile ( ) [inline, static]

Reimplemented from PLearn::PLearner.

Definition at line 141 of file RankingFromKernel.h.

:

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:

  • initialize a random number generator with the seed option
  • initialize the learner's parameters, using this random generator
  • stage = 0

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;
}

Here is the call graph for this function:

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;
}

Here is the call graph for this function:

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");
}

Member Data Documentation

Reimplemented from PLearn::PLearner.

Definition at line 141 of file RankingFromKernel.h.

Definition at line 156 of file RankingFromKernel.h.

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.


The documentation for this class was generated from the following files:
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines