PLearn 0.1
|
Multiclass classification error. More...
#include <ClassErrorCostModule.h>
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 OptionList & | getOptionList () const |
virtual OptionMap & | getOptionMap () const |
virtual RemoteMethodMap & | getRemoteMethodMap () const |
virtual ClassErrorCostModule * | deepCopy (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 PPath & | declaringFile () |
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. |
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.
typedef CostModule PLearn::ClassErrorCostModule::inherited [private] |
Reimplemented from PLearn::CostModule.
Definition at line 57 of file ClassErrorCostModule.h.
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; }
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.
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.
{ }
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().
{ inherited::build(); build_(); }
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); }
string PLearn::ClassErrorCostModule::classname | ( | ) | const [virtual] |
Reimplemented from PLearn::CostModule.
Definition at line 55 of file ClassErrorCostModule.cc.
Referenced by costNames().
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"); }
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); }
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] ); }
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)); }
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) ); }
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().
{ inherited::makeDeepCopyFromShallowCopy(copies); deepCopyField(error_costs, copies); }
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.
{}
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().