PLearn 0.1
|
#include <ClassMarginCostFunction.h>
Public Member Functions | |
ClassMarginCostFunction (bool the_binary_target_is_01=false, bool out_is_positive=false) | |
virtual string | classname () const |
virtual OptionList & | getOptionList () const |
virtual OptionMap & | getOptionMap () const |
virtual RemoteMethodMap & | getRemoteMethodMap () const |
virtual ClassMarginCostFunction * | deepCopy (CopiesMap &copies) const |
virtual string | info () const |
Returns a bit more informative string about object (default returns classname()) | |
virtual real | evaluate (const Vec &output, const Vec &target) const |
** Subclasses must override this method ** | |
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 | |
bool | binary_target_is_01 |
bool | output_is_positive |
Static Public Attributes | |
static StaticInitializer | _static_initializer_ |
Static Protected Member Functions | |
static void | declareOptions (OptionList &ol) |
recognized option are "binary_target_is_01" and "output_is_positive" | |
Private Types | |
typedef Kernel | inherited |
* If output and target both have length 1, when binary classification with targets -1 and +1 and the sign of the output is considered, then margin is output[0]*target[0] If binary targets is {0,1} and outputs>0, then the margin is: (output[0]+1)*(target[0]+1)/4 However, if the flag output_is_positive is true then output is replaced by output[0]-0.5 in the above expressions. If output has length>1 and target has length 1, then output is understood as giving a score for each class while target is the index of the correct class (numbered from 0). Then margin is the difference between the score of the correct class and the highest score among the other classes. If both output and target have a length>1 then output is understood as giving a score for each class while the correct class is given by argmax(target). Then margin is the difference between the score of the correct class and the highest score among the other classes. In all cases, as this is a cost function, we return -margin.
Definition at line 70 of file ClassMarginCostFunction.h.
typedef Kernel PLearn::ClassMarginCostFunction::inherited [private] |
Reimplemented from PLearn::Kernel.
Definition at line 72 of file ClassMarginCostFunction.h.
PLearn::ClassMarginCostFunction::ClassMarginCostFunction | ( | bool | the_binary_target_is_01 = false , |
bool | out_is_positive = false |
||
) | [inline] |
Definition at line 77 of file ClassMarginCostFunction.h.
: binary_target_is_01(the_binary_target_is_01), output_is_positive(out_is_positive) {}
string PLearn::ClassMarginCostFunction::_classname_ | ( | ) | [static] |
Reimplemented from PLearn::Kernel.
Definition at line 49 of file ClassMarginCostFunction.cc.
OptionList & PLearn::ClassMarginCostFunction::_getOptionList_ | ( | ) | [static] |
Reimplemented from PLearn::Kernel.
Definition at line 49 of file ClassMarginCostFunction.cc.
RemoteMethodMap & PLearn::ClassMarginCostFunction::_getRemoteMethodMap_ | ( | ) | [static] |
Reimplemented from PLearn::Kernel.
Definition at line 49 of file ClassMarginCostFunction.cc.
Reimplemented from PLearn::Kernel.
Definition at line 49 of file ClassMarginCostFunction.cc.
Object * PLearn::ClassMarginCostFunction::_new_instance_for_typemap_ | ( | ) | [static] |
Reimplemented from PLearn::Object.
Definition at line 49 of file ClassMarginCostFunction.cc.
StaticInitializer ClassMarginCostFunction::_static_initializer_ & PLearn::ClassMarginCostFunction::_static_initialize_ | ( | ) | [static] |
Reimplemented from PLearn::Kernel.
Definition at line 49 of file ClassMarginCostFunction.cc.
string PLearn::ClassMarginCostFunction::classname | ( | ) | const [virtual] |
Reimplemented from PLearn::Object.
Definition at line 49 of file ClassMarginCostFunction.cc.
void PLearn::ClassMarginCostFunction::declareOptions | ( | OptionList & | ol | ) | [static, protected] |
recognized option are "binary_target_is_01" and "output_is_positive"
Reimplemented from PLearn::Kernel.
Definition at line 82 of file ClassMarginCostFunction.cc.
References binary_target_is_01, PLearn::OptionBase::buildoption, PLearn::declareOption(), and output_is_positive.
{ declareOption(ol, "binary_target_is_01", &ClassMarginCostFunction::binary_target_is_01, OptionBase::buildoption, ""); declareOption(ol, "output_is_positive", &ClassMarginCostFunction::output_is_positive, OptionBase::buildoption, ""); inherited::declareOptions(ol); }
static const PPath& PLearn::ClassMarginCostFunction::declaringFile | ( | ) | [inline, static] |
Reimplemented from PLearn::Kernel.
Definition at line 82 of file ClassMarginCostFunction.h.
{ return "class_margin"; }
ClassMarginCostFunction * PLearn::ClassMarginCostFunction::deepCopy | ( | CopiesMap & | copies | ) | const [virtual] |
Reimplemented from PLearn::Kernel.
Definition at line 49 of file ClassMarginCostFunction.cc.
** Subclasses must override this method **
returns K(x1,x2)
Implements PLearn::Kernel.
Definition at line 51 of file ClassMarginCostFunction.cc.
References PLearn::argmax(), PLearn::TVec< T >::length(), and PLearn::max().
{ real margin; if (output.length()==1) { real out = output[0]; if (output_is_positive) out = 2*out-1; margin = binary_target_is_01 ? out*(target[0]-0.5)*4.0 : out*target[0]; } else // we assume output gives a score for each class { int trueclass; if (target.length()==1) { trueclass = int(target[0]); if (!binary_target_is_01) trueclass = (trueclass+1)/2; } else trueclass = argmax(target); real trueclass_score = output[trueclass]; output[trueclass] = -FLT_MAX; real otherclass_score = max(output); output[trueclass] = trueclass_score; margin = trueclass_score-otherclass_score; } return -margin; }
OptionList & PLearn::ClassMarginCostFunction::getOptionList | ( | ) | const [virtual] |
Reimplemented from PLearn::Object.
Definition at line 49 of file ClassMarginCostFunction.cc.
OptionMap & PLearn::ClassMarginCostFunction::getOptionMap | ( | ) | const [virtual] |
Reimplemented from PLearn::Object.
Definition at line 49 of file ClassMarginCostFunction.cc.
RemoteMethodMap & PLearn::ClassMarginCostFunction::getRemoteMethodMap | ( | ) | const [virtual] |
Reimplemented from PLearn::Object.
Definition at line 49 of file ClassMarginCostFunction.cc.
virtual string PLearn::ClassMarginCostFunction::info | ( | ) | const [inline, virtual] |
Returns a bit more informative string about object (default returns classname())
Reimplemented from PLearn::Object.
Definition at line 84 of file ClassMarginCostFunction.h.
{ return "class_margin"; }
Reimplemented from PLearn::Kernel.
Definition at line 82 of file ClassMarginCostFunction.h.
Definition at line 75 of file ClassMarginCostFunction.h.
Referenced by declareOptions().
Definition at line 76 of file ClassMarginCostFunction.h.
Referenced by declareOptions().