PLearn 0.1
|
#include <NegLogProbCostFunction.h>
Public Member Functions | |
NegLogProbCostFunction (bool do_normalize=false, bool do_smooth_map_outputs=false) | |
virtual string | classname () const |
virtual OptionList & | getOptionList () const |
virtual OptionMap & | getOptionMap () const |
virtual RemoteMethodMap & | getRemoteMethodMap () const |
virtual NegLogProbCostFunction * | 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 | normalize |
bool | smooth_map_outputs |
Static Public Attributes | |
static StaticInitializer | _static_initializer_ |
Static Protected Member Functions | |
static void | declareOptions (OptionList &ol) |
recognized options are "normalize" and "smooth_map_outputs" | |
Private Types | |
typedef Kernel | inherited |
The target is an integer between 0 and n_classes-1 corresponding to a class Y, and the output is a vector of length n_classes of non-negative estimated conditional probabilities P(Y=i|X) for class i (i=0 to n_classes-1), or if n_classes=2, the output could be a vector of length 1 containing P(Y=1|X). The cost is
Definition at line 62 of file NegLogProbCostFunction.h.
typedef Kernel PLearn::NegLogProbCostFunction::inherited [private] |
Reimplemented from PLearn::Kernel.
Definition at line 64 of file NegLogProbCostFunction.h.
PLearn::NegLogProbCostFunction::NegLogProbCostFunction | ( | bool | do_normalize = false , |
bool | do_smooth_map_outputs = false |
||
) | [inline] |
Definition at line 80 of file NegLogProbCostFunction.h.
: normalize(do_normalize), smooth_map_outputs(do_smooth_map_outputs) {}
string PLearn::NegLogProbCostFunction::_classname_ | ( | ) | [static] |
Reimplemented from PLearn::Kernel.
Definition at line 55 of file NegLogProbCostFunction.cc.
OptionList & PLearn::NegLogProbCostFunction::_getOptionList_ | ( | ) | [static] |
Reimplemented from PLearn::Kernel.
Definition at line 55 of file NegLogProbCostFunction.cc.
RemoteMethodMap & PLearn::NegLogProbCostFunction::_getRemoteMethodMap_ | ( | ) | [static] |
Reimplemented from PLearn::Kernel.
Definition at line 55 of file NegLogProbCostFunction.cc.
Reimplemented from PLearn::Kernel.
Definition at line 55 of file NegLogProbCostFunction.cc.
Object * PLearn::NegLogProbCostFunction::_new_instance_for_typemap_ | ( | ) | [static] |
Reimplemented from PLearn::Object.
Definition at line 55 of file NegLogProbCostFunction.cc.
StaticInitializer NegLogProbCostFunction::_static_initializer_ & PLearn::NegLogProbCostFunction::_static_initialize_ | ( | ) | [static] |
Reimplemented from PLearn::Kernel.
Definition at line 55 of file NegLogProbCostFunction.cc.
string PLearn::NegLogProbCostFunction::classname | ( | ) | const [virtual] |
Reimplemented from PLearn::Object.
Definition at line 55 of file NegLogProbCostFunction.cc.
void PLearn::NegLogProbCostFunction::declareOptions | ( | OptionList & | ol | ) | [static, protected] |
recognized options are "normalize" and "smooth_map_outputs"
Reimplemented from PLearn::Kernel.
Definition at line 133 of file NegLogProbCostFunction.cc.
References PLearn::OptionBase::buildoption, PLearn::declareOption(), normalize, and smooth_map_outputs.
{ declareOption(ol, "normalize", &NegLogProbCostFunction::normalize, OptionBase::buildoption, "TODO: Some comments"); declareOption(ol, "smooth_map_outputs", &NegLogProbCostFunction::smooth_map_outputs, OptionBase::buildoption, "TODO: Some comments"); inherited::declareOptions(ol); }
static const PPath& PLearn::NegLogProbCostFunction::declaringFile | ( | ) | [inline, static] |
Reimplemented from PLearn::Kernel.
Definition at line 83 of file NegLogProbCostFunction.h.
{ return "negative_log_probability"; }
NegLogProbCostFunction * PLearn::NegLogProbCostFunction::deepCopy | ( | CopiesMap & | copies | ) | const [virtual] |
Reimplemented from PLearn::Kernel.
Definition at line 55 of file NegLogProbCostFunction.cc.
** Subclasses must override this method **
returns K(x1,x2)
Implements PLearn::Kernel.
Definition at line 59 of file NegLogProbCostFunction.cc.
References PLearn::TVec< T >::data(), i, PLearn::TVec< T >::length(), PLearn::normalize(), PLERROR, PLearn::PLMPI::rank, PLearn::safeflog(), PLearn::PLMPI::size, smoothmap, and PLearn::sum().
{ real prob = 0.; int desired_class = int(target[0]); if (desired_class == -1) desired_class=0; if(output.length()==1) // we assume output[0] gives the probability of having class 1 { prob = output[0]; if(smooth_map_outputs) prob = smoothmap(prob); if(desired_class==0) prob = 1-prob; } else { if(!normalize) // we assume output gives a real probability for each class #if USING_MPI #define SEND_PROB_TAG 981 { // EACH CPU ONLY CARRIES THE CORRECT outputs IN THE INTERVAL // GIVEN BY [out_start,out_end). // THE RESULT WILL BE THAT CPU 0 WILL HAVE // THE PROBABILITY OF desired_class IN prob // (and the other CPUs will have some dummy value) if (PLMPI::size>1 && out_end>=0) { if (desired_class>=out_start && desired_class<out_end) { prob = output[desired_class]; if (PLMPI::rank>0) // send it to CPU 0 { MPI_Send(&prob,1,PLMPI_REAL,0,SEND_PROB_TAG,MPI_COMM_WORLD); } } else { if (PLMPI::rank==0) { MPI_Status status; MPI_Recv(&prob,1,PLMPI_REAL,MPI_ANY_SOURCE,SEND_PROB_TAG,MPI_COMM_WORLD,&status); } else { prob = 1; // dummy value (whose log exists) } } } else prob = output[desired_class]; } #else prob = output[desired_class]; #endif else // outputs may not sum to 1, so we'll normalize them { #if USING_MPI if (PLMPI::size>1 && out_end>=0) PLERROR("condprob used in parallel mode: normalize not implemented"); #endif real* outputdata = output.data(); if(smooth_map_outputs) // outputs may be slightly smaller than 0 or slightly larger than 1 { // so we'll smooth-map them to fit in range [0,1] before normalizing real outputsum = 0.0; for(int i=0; i<output.length(); i++) outputsum += smoothmap(outputdata[i]); prob = smoothmap(outputdata[desired_class])/outputsum; } else prob = output[desired_class]/sum(output, false); } } return -safeflog(prob); }
OptionList & PLearn::NegLogProbCostFunction::getOptionList | ( | ) | const [virtual] |
Reimplemented from PLearn::Object.
Definition at line 55 of file NegLogProbCostFunction.cc.
OptionMap & PLearn::NegLogProbCostFunction::getOptionMap | ( | ) | const [virtual] |
Reimplemented from PLearn::Object.
Definition at line 55 of file NegLogProbCostFunction.cc.
RemoteMethodMap & PLearn::NegLogProbCostFunction::getRemoteMethodMap | ( | ) | const [virtual] |
Reimplemented from PLearn::Object.
Definition at line 55 of file NegLogProbCostFunction.cc.
virtual string PLearn::NegLogProbCostFunction::info | ( | ) | const [inline, virtual] |
Returns a bit more informative string about object (default returns classname())
Reimplemented from PLearn::Object.
Definition at line 85 of file NegLogProbCostFunction.h.
{ return "negative_log_probability"; }
Reimplemented from PLearn::Kernel.
Definition at line 83 of file NegLogProbCostFunction.h.
Definition at line 67 of file NegLogProbCostFunction.h.
Referenced by declareOptions().
Definition at line 68 of file NegLogProbCostFunction.h.
Referenced by declareOptions().