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

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

#include <TransformOutputLearner.h>

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

List of all members.

Public Member Functions

 TransformOutputLearner ()
 Default constructor.
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 void computeOutputAndCosts (const Vec &input, const Vec &target, Vec &output, Vec &costs) const
 Forwarded to inner learner.
virtual void test (VMat testset, PP< VecStatsCollector > test_stats, VMat testoutputs, VMat testcosts) const
 The behavior of this method depends on the value of the 'forward_test' option.
virtual int outputsize () const
 Forwarded to inner learner.
virtual string classname () const
virtual OptionListgetOptionList () const
virtual OptionMapgetOptionMap () const
virtual RemoteMethodMapgetRemoteMethodMap () const
virtual TransformOutputLearnerdeepCopy (CopiesMap &copies) const
virtual void build ()
 Finish building the object; just call inherited::build followed by build_()

Static Public Member Functions

static string _classname_ ()
 Declares name and deepCopy methods.
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

int output_function
 ### 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 EmbeddedLearner inherited

Private Member Functions

void build_ ()
 This does the actual building.

Private Attributes

Vec tmp_output2
bool warning0
bool warning1

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 57 of file TransformOutputLearner.h.


Member Typedef Documentation

Reimplemented from PLearn::EmbeddedLearner.

Definition at line 59 of file TransformOutputLearner.h.


Constructor & Destructor Documentation

PLearn::TransformOutputLearner::TransformOutputLearner ( )

Default constructor.

Definition at line 50 of file TransformOutputLearner.cc.

References PLearn::EmbeddedLearner::forward_test.

    :inherited(),
     output_function(-1),
     warning0(true),
     warning1(true)
{
    forward_test=true;
}

Member Function Documentation

string PLearn::TransformOutputLearner::_classname_ ( ) [static]

Declares name and deepCopy methods.

Reimplemented from PLearn::EmbeddedLearner.

Definition at line 48 of file TransformOutputLearner.cc.

OptionList & PLearn::TransformOutputLearner::_getOptionList_ ( ) [static]

Reimplemented from PLearn::EmbeddedLearner.

Definition at line 48 of file TransformOutputLearner.cc.

RemoteMethodMap & PLearn::TransformOutputLearner::_getRemoteMethodMap_ ( ) [static]

Reimplemented from PLearn::EmbeddedLearner.

Definition at line 48 of file TransformOutputLearner.cc.

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

Reimplemented from PLearn::EmbeddedLearner.

Definition at line 48 of file TransformOutputLearner.cc.

Object * PLearn::TransformOutputLearner::_new_instance_for_typemap_ ( ) [static]

Reimplemented from PLearn::EmbeddedLearner.

Definition at line 48 of file TransformOutputLearner.cc.

StaticInitializer TransformOutputLearner::_static_initializer_ & PLearn::TransformOutputLearner::_static_initialize_ ( ) [static]

Reimplemented from PLearn::EmbeddedLearner.

Definition at line 48 of file TransformOutputLearner.cc.

void PLearn::TransformOutputLearner::build ( ) [virtual]

Finish building the object; just call inherited::build followed by build_()

Reimplemented from PLearn::EmbeddedLearner.

Definition at line 91 of file TransformOutputLearner.cc.

References PLearn::EmbeddedLearner::build(), and build_().

Here is the call graph for this function:

void PLearn::TransformOutputLearner::build_ ( ) [private]

This does the actual building.

Reimplemented from PLearn::EmbeddedLearner.

Definition at line 85 of file TransformOutputLearner.cc.

References PLearn::EmbeddedLearner::learner_, PLearn::TVec< T >::resize(), and tmp_output2.

Referenced by build().

{
    tmp_output2.resize(learner_->outputsize());
}

Here is the call graph for this function:

Here is the caller graph for this function:

string PLearn::TransformOutputLearner::classname ( ) const [virtual]

Reimplemented from PLearn::EmbeddedLearner.

Definition at line 48 of file TransformOutputLearner.cc.

void PLearn::TransformOutputLearner::computeCostsFromOutputs ( const Vec input,
const Vec output,
const Vec target,
Vec costs 
) const [virtual]

Computes the costs from already computed output.

Reimplemented from PLearn::EmbeddedLearner.

Definition at line 131 of file TransformOutputLearner.cc.

References PLearn::compute_log(), computeOutputAndCosts(), PLearn::EmbeddedLearner::learner_, output_function, PLASSERT, PLERROR, PLWARNING, tmp_output2, warning0, and warning1.

{
    PLASSERT( learner_ );
    if(output_function==0){
        if(warning0){
            PLWARNING("In TransformOutputLearner::computeCostsFromOutputs - you are loosing precision");
            warning0=false;
        }
        compute_log(output,tmp_output2);
        learner_->computeCostsFromOutputs(input,tmp_output2,target,costs);
    }else if(output_function==1 || output_function==2){
        if(warning1){
            PLWARNING("In TransformOutputLearner::computeCostsFromOutputs - we can't compute the costs from\n"
                      "outputs with output_function %d. We use TransformOutputLearner::computeOutputAndCosts.",output_function);
            warning1=false;
        }
        computeOutputAndCosts(input,target,tmp_output2,costs);
    }else
        PLERROR("In TransformOutputLearner::computeCostsFromOutputs - unknow output_function %d",output_function);
}

Here is the call graph for this function:

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

Computes the output from the input.

Reimplemented from PLearn::EmbeddedLearner.

Definition at line 97 of file TransformOutputLearner.cc.

References PLearn::argmax(), PLearn::exp(), PLearn::EmbeddedLearner::learner_, output_function, PLERROR, and tmp_output2.

{
    // Compute the output from the input.
    // int nout = outputsize();
    // output.resize(nout);
    // ...
    if(output_function==0){//logprob to prob
        learner_->computeOutput(input,output);
        exp(output,output);
    }else if(output_function==1){//logprob or prob to class
        learner_->computeOutput(input,tmp_output2);
        output[0]=argmax(tmp_output2);
    }else if(output_function==2){//Regression to class v1
        learner_->computeOutput(input,tmp_output2);
        output[0]=int(round(tmp_output2[0]));
//    }else if(output_function==2){//Regression to class v2
//         learner_->computeOutput(input, output);
//         if (multiclass_outputs.length() <= 0) return;
//         real closest_value=multiclass_outputs[0];
//         real margin_to_closest_value=abs(output[0] - multiclass_outputs[0]);
//         for (int value_ind = 1; value_ind < multiclass_outputs.length(); value_ind++)
//         {
//             real v=abs(output[0] - multiclass_outputs[value_ind]);
//             if (v < margin_to_closest_value)
//             {
//                 closest_value = multiclass_outputs[value_ind];
//                 margin_to_closest_value = v;
//             }
//         }
//         output[0] = closest_value;
    }else
        PLERROR("In TransformOutputLearner::computeOutput - unknow output_function %d",output_function);
}

Here is the call graph for this function:

void PLearn::TransformOutputLearner::computeOutputAndCosts ( const Vec input,
const Vec target,
Vec output,
Vec costs 
) const [virtual]

Forwarded to inner learner.

Reimplemented from PLearn::EmbeddedLearner.

Definition at line 152 of file TransformOutputLearner.cc.

References PLearn::argmax(), PLearn::exp(), PLearn::EmbeddedLearner::learner_, output_function, PLASSERT, PLERROR, and tmp_output2.

Referenced by computeCostsFromOutputs().

{
    PLASSERT( learner_ );
    if(output_function==0){//logprob to prob
        learner_->computeOutputAndCosts(input,target,output,costs);
        exp(output,output);
    }else if(output_function==1){//logprob or prob to class
        learner_->computeOutputAndCosts(input,target,tmp_output2,costs);
        output[0]=argmax(output);
    }else if(output_function==2){//Regression to class v1
        learner_->computeOutputAndCosts(input,target,tmp_output2,costs);
        output[0]=int(round(tmp_output2[0]));
    }else
        PLERROR("In TransformOutputLearner::computeOutputAndCosts - unknow output_function %d",output_function);
}

Here is the call graph for this function:

Here is the caller graph for this function:

void PLearn::TransformOutputLearner::declareOptions ( OptionList ol) [static, protected]

Declares the class options.

Reimplemented from PLearn::EmbeddedLearner.

Definition at line 59 of file TransformOutputLearner.cc.

References PLearn::OptionBase::buildoption, PLearn::declareOption(), PLearn::EmbeddedLearner::declareOptions(), and output_function.

{
    // ### 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)

    // ### ex:
    // declareOption(ol, "myoption", &TransformOutputLearner::myoption,
    //               OptionBase::buildoption,
    //               "Help text describing this option");
    // ...
    declareOption(ol, "output_function", &TransformOutputLearner::output_function,
                  OptionBase::buildoption,
                  "The operation to do on the output\n"
                  "0: We transform the sublearner log probability output to probability output\n"
                  "1: We transform the sublearner probability output of class to class output\n"
                  "2: We transform the sublearner regression output to class output.");

    // Now call the parent class' declareOptions
    inherited::declareOptions(ol);
}

Here is the call graph for this function:

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

Reimplemented from PLearn::EmbeddedLearner.

Definition at line 102 of file TransformOutputLearner.h.

:
    //#####  Protected Member Functions  ######################################
TransformOutputLearner * PLearn::TransformOutputLearner::deepCopy ( CopiesMap copies) const [virtual]

Reimplemented from PLearn::EmbeddedLearner.

Definition at line 48 of file TransformOutputLearner.cc.

OptionList & PLearn::TransformOutputLearner::getOptionList ( ) const [virtual]

Reimplemented from PLearn::EmbeddedLearner.

Definition at line 48 of file TransformOutputLearner.cc.

OptionMap & PLearn::TransformOutputLearner::getOptionMap ( ) const [virtual]

Reimplemented from PLearn::EmbeddedLearner.

Definition at line 48 of file TransformOutputLearner.cc.

RemoteMethodMap & PLearn::TransformOutputLearner::getRemoteMethodMap ( ) const [virtual]

Reimplemented from PLearn::EmbeddedLearner.

Definition at line 48 of file TransformOutputLearner.cc.

int PLearn::TransformOutputLearner::outputsize ( ) const [virtual]

Forwarded to inner learner.

Reimplemented from PLearn::EmbeddedLearner.

Definition at line 183 of file TransformOutputLearner.cc.

References PLearn::EmbeddedLearner::learner_, output_function, PLASSERT, and PLERROR.

{
    PLASSERT( learner_ );
    if(output_function==0)
        return learner_->outputsize();
    else if (output_function==1 || output_function==2)
        return 1;
    else
        PLERROR("In TransformOutputLearner::outputsize");
    return -1;
}
void PLearn::TransformOutputLearner::test ( VMat  testset,
PP< VecStatsCollector test_stats,
VMat  testoutputs,
VMat  testcosts 
) const [virtual]

The behavior of this method depends on the value of the 'forward_test' option.

If set to 'true', the call will be forwarded to the underlying learner. If set to 'false' (default), simply call inherited::test(..). This is to allow forwarding of this method in subclasses of EmbeddedLearner that need it, while most of them will not need it.

Reimplemented from PLearn::EmbeddedLearner.

Definition at line 169 of file TransformOutputLearner.cc.

References PLearn::exp(), i, PLearn::EmbeddedLearner::learner_, PLearn::VMat::length(), output_function, PLASSERT, and PLERROR.

{
    PLASSERT( learner_ );
    if(output_function==0){
        learner_->test(testset, test_stats, testoutputs, testcosts);
        for(int i = 0;i<testoutputs.length();i++){
            Vec v = testoutputs(i);
            exp(v,v);
        }
    }
    else
        PLERROR("In TransformOutputLearner::test");
}

Here is the call graph for this function:


Member Data Documentation

Reimplemented from PLearn::EmbeddedLearner.

Definition at line 102 of file TransformOutputLearner.h.

### declare public option fields (such as build options) here Start your comments with Doxygen-compatible comments such as //!

The operation to do on the output

Definition at line 68 of file TransformOutputLearner.h.

Referenced by computeCostsFromOutputs(), computeOutput(), computeOutputAndCosts(), declareOptions(), outputsize(), and test().

Definition at line 129 of file TransformOutputLearner.h.

Referenced by computeCostsFromOutputs().

Definition at line 130 of file TransformOutputLearner.h.

Referenced by computeCostsFromOutputs().


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