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

Multiclass classification error. More...

#include <ClassErrorCostModule.h>

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

List of all members.

Public Member Functions

 ClassErrorCostModule ()
 Default constructor.
virtual void fprop (const Vec &input, const Vec &target, Vec &cost) const
 Given the input and the target, compute a vector of costs (possibly resize it appropriately)
virtual void fprop (const Mat &inputs, const Mat &targets, Mat &costs) const
 Overridden from parent class.
virtual void fprop (const Vec &input, const Vec &target, real &cost) const
 Given the input and the target, compute only the first cost (of which we will compute the gradient)
virtual void bpropUpdate (const Vec &input, const Vec &target, real cost)
 Nothing to do.
virtual void bbpropUpdate (const Vec &input, const Vec &target, real cost)
 Nothing to do.
virtual void bpropUpdate (const Mat &inputs, const Mat &targets, const Vec &costs)
virtual void forget ()
 Reset the parameters to the state they would be BEFORE starting training.
virtual void setLearningRate (real dynamic_learning_rate)
 Does nothing (there isn't a learning rate in this class)
virtual bool bpropDoesNothing ()
 In case bpropUpdate does not do anything, make it known.
virtual TVec< string > costNames ()
 Indicates the name of the computed costs.
virtual string classname () const
virtual OptionListgetOptionList () const
virtual OptionMapgetOptionMap () const
virtual RemoteMethodMapgetRemoteMethodMap () const
virtual ClassErrorCostModuledeepCopy (CopiesMap &copies) const
virtual void build ()
 Post-constructor.
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

Mat error_costs

Static Public Attributes

static StaticInitializer _static_initializer_

Static Protected Member Functions

static void declareOptions (OptionList &ol)
 Declares the class options.

Private Types

typedef CostModule inherited

Private Member Functions

void build_ ()
 This does the actual building.

Detailed Description

Multiclass classification error.

If input_size > 1, outputs 0 if target == argmax(input), 1 else If input_size == 1, outputs 0 if target is the closest integer to input[0], 1 else. There is no gradient to compute (it returns an error if you try), so if you use this module inside a CombiningCostsModule, put its weight to 0.

Definition at line 55 of file ClassErrorCostModule.h.


Member Typedef Documentation

Reimplemented from PLearn::CostModule.

Definition at line 57 of file ClassErrorCostModule.h.


Constructor & Destructor Documentation

PLearn::ClassErrorCostModule::ClassErrorCostModule ( )

Default constructor.

Definition at line 57 of file ClassErrorCostModule.cc.

References PLearn::OnlineLearningModule::output_size, and PLearn::CostModule::target_size.

                                          :
    error_costs(Mat())
{
    output_size = 1;
    target_size = 1;
}

Member Function Documentation

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

Reimplemented from PLearn::CostModule.

Definition at line 55 of file ClassErrorCostModule.cc.

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

Reimplemented from PLearn::CostModule.

Definition at line 55 of file ClassErrorCostModule.cc.

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

Reimplemented from PLearn::CostModule.

Definition at line 55 of file ClassErrorCostModule.cc.

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

Reimplemented from PLearn::CostModule.

Definition at line 55 of file ClassErrorCostModule.cc.

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

Reimplemented from PLearn::CostModule.

Definition at line 55 of file ClassErrorCostModule.cc.

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

Reimplemented from PLearn::CostModule.

Definition at line 55 of file ClassErrorCostModule.cc.

void PLearn::ClassErrorCostModule::bbpropUpdate ( const Vec input,
const Vec target,
real  cost 
) [virtual]

Nothing to do.

Reimplemented from PLearn::CostModule.

Definition at line 162 of file ClassErrorCostModule.cc.

{
}
bool PLearn::ClassErrorCostModule::bpropDoesNothing ( ) [virtual]

In case bpropUpdate does not do anything, make it known.

Reimplemented from PLearn::OnlineLearningModule.

Definition at line 198 of file ClassErrorCostModule.cc.

{
    return true;
}
void PLearn::ClassErrorCostModule::bpropUpdate ( const Vec input,
const Vec target,
real  cost 
) [virtual]

Nothing to do.

Reimplemented from PLearn::CostModule.

Definition at line 145 of file ClassErrorCostModule.cc.

{
}
virtual void PLearn::ClassErrorCostModule::bpropUpdate ( const Mat inputs,
const Mat targets,
const Vec costs 
) [inline, virtual]

Reimplemented from PLearn::CostModule.

Definition at line 94 of file ClassErrorCostModule.h.

    {}
void PLearn::ClassErrorCostModule::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::CostModule.

Definition at line 87 of file ClassErrorCostModule.cc.

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

Referenced by PLearn::TopDownAsymetricDeepNetwork::build_output_layer_and_cost(), PLearn::StackedFocusedAutoassociatorsNet::build_output_layer_and_cost(), and PLearn::DiscriminativeDeepBeliefNet::build_output_layer_and_cost().

Here is the call graph for this function:

Here is the caller graph for this function:

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

This does the actual building.

Reimplemented from PLearn::CostModule.

Definition at line 75 of file ClassErrorCostModule.cc.

References error_costs, PLearn::OnlineLearningModule::input_size, PLearn::TMat< T >::isEmpty(), PLearn::TMat< T >::length(), PLearn::OnlineLearningModule::output_size, PLASSERT, PLearn::CostModule::target_size, and PLearn::TMat< T >::width().

Referenced by build().

{
    PLASSERT( output_size == 1 );
    PLASSERT( target_size == 1 );
    PLASSERT(error_costs.width() == error_costs.length());
    if( !error_costs.isEmpty() && input_size > 1 )
        PLASSERT(error_costs.length() == input_size);   
}

Here is the call graph for this function:

Here is the caller graph for this function:

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

Reimplemented from PLearn::CostModule.

Definition at line 55 of file ClassErrorCostModule.cc.

Referenced by costNames().

Here is the caller graph for this function:

TVec< string > PLearn::ClassErrorCostModule::costNames ( ) [virtual]

Indicates the name of the computed costs.

Reimplemented from PLearn::CostModule.

Definition at line 187 of file ClassErrorCostModule.cc.

References classname(), and PLearn::OnlineLearningModule::name.

{
    if (name == "" || name == classname())
        return TVec<string>(1, "class_error");
    else
        return TVec<string>(1, name + ".class_error");
}

Here is the call graph for this function:

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

Declares the class options.

Reimplemented from PLearn::CostModule.

Definition at line 64 of file ClassErrorCostModule.cc.

References PLearn::OptionBase::buildoption, PLearn::declareOption(), PLearn::CostModule::declareOptions(), and error_costs.

{
     declareOption(ol, "error_costs", &ClassErrorCostModule::error_costs,
                   OptionBase::buildoption,
                   "A square matrix containing the cost for each type of error (default is 0/1 cost). "
                   "The two dimensions correspond to: (true class, prediction).");

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

Here is the call graph for this function:

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

Reimplemented from PLearn::CostModule.

Definition at line 124 of file ClassErrorCostModule.h.

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

Reimplemented from PLearn::CostModule.

Definition at line 55 of file ClassErrorCostModule.cc.

void PLearn::ClassErrorCostModule::forget ( ) [virtual]

Reset the parameters to the state they would be BEFORE starting training.

Note that this method is necessarily called from build().

Reimplemented from PLearn::CostModule.

Definition at line 180 of file ClassErrorCostModule.cc.

{
}
void PLearn::ClassErrorCostModule::fprop ( const Vec input,
const Vec target,
Vec cost 
) const [virtual]

Given the input and the target, compute a vector of costs (possibly resize it appropriately)

Reimplemented from PLearn::CostModule.

Definition at line 106 of file ClassErrorCostModule.cc.

References PLearn::OnlineLearningModule::output_size, and PLearn::TVec< T >::resize().

Referenced by fprop().

{
    cost.resize( output_size );
    fprop( input, target, cost[0] );
}

Here is the call graph for this function:

Here is the caller graph for this function:

void PLearn::ClassErrorCostModule::fprop ( const Mat inputs,
const Mat targets,
Mat costs 
) const [virtual]

Overridden from parent class.

Reimplemented from PLearn::CostModule.

Definition at line 134 of file ClassErrorCostModule.cc.

References fprop(), i, PLearn::TMat< T >::length(), PLearn::OnlineLearningModule::output_size, and PLearn::TMat< T >::resize().

{
    costs.resize( inputs.length(), output_size );
    for (int i = 0; i < inputs.length(); i++)
        fprop(inputs(i), targets(i), costs(i, 0));
}

Here is the call graph for this function:

void PLearn::ClassErrorCostModule::fprop ( const Vec input,
const Vec target,
real cost 
) const [virtual]

Given the input and the target, compute only the first cost (of which we will compute the gradient)

Reimplemented from PLearn::CostModule.

Definition at line 116 of file ClassErrorCostModule.cc.

References PLearn::argmax(), error_costs, PLearn::OnlineLearningModule::input_size, PLearn::TMat< T >::isEmpty(), PLASSERT, PLearn::TVec< T >::size(), and PLearn::CostModule::target_size.

{
    PLASSERT( input.size() == input_size );
    PLASSERT( target.size() == target_size );

    if( error_costs.isEmpty() )
        if( input_size == 1 ) // is target[0] the closest integer to input[0]?
            cost = ( round(input[0]) == round(target[0]) ) ? 0. : 1.;
        else // is target[0] equals to argmax(input)?
            cost = ( argmax(input) == int(round(target[0])) ) ? 0. : 1.;
    else
        if( input_size == 1 )
            cost = error_costs( int(round(target[0])), int(round(input[0])) );
        else 
            cost = error_costs( int(round(target[0])), argmax(input) );
}

Here is the call graph for this function:

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

Reimplemented from PLearn::CostModule.

Definition at line 55 of file ClassErrorCostModule.cc.

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

Reimplemented from PLearn::CostModule.

Definition at line 55 of file ClassErrorCostModule.cc.

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

Reimplemented from PLearn::CostModule.

Definition at line 55 of file ClassErrorCostModule.cc.

void PLearn::ClassErrorCostModule::makeDeepCopyFromShallowCopy ( CopiesMap copies) [virtual]

Transforms a shallow copy into a deep copy.

Reimplemented from PLearn::CostModule.

Definition at line 96 of file ClassErrorCostModule.cc.

References PLearn::deepCopyField(), error_costs, and PLearn::CostModule::makeDeepCopyFromShallowCopy().

Here is the call graph for this function:

virtual void PLearn::ClassErrorCostModule::setLearningRate ( real  dynamic_learning_rate) [inline, virtual]

Does nothing (there isn't a learning rate in this class)

Reimplemented from PLearn::OnlineLearningModule.

Definition at line 112 of file ClassErrorCostModule.h.

{}

Member Data Documentation

Reimplemented from PLearn::CostModule.

Definition at line 124 of file ClassErrorCostModule.h.

Definition at line 62 of file ClassErrorCostModule.h.

Referenced by build_(), declareOptions(), fprop(), and makeDeepCopyFromShallowCopy().


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