PLearn 0.1
|
This class implements an Ln distance (defaults to L2 i.e. euclidean distance). More...
#include <WeightedDistance.h>
Public Member Functions | |
WeightedDistance () | |
WeightedDistance (Vec the_weights) | |
virtual string | classname () const |
virtual OptionList & | getOptionList () const |
virtual OptionMap & | getOptionMap () const |
virtual RemoteMethodMap & | getRemoteMethodMap () const |
virtual WeightedDistance * | deepCopy (CopiesMap &copies) const |
virtual string | info () const |
Returns a bit more informative string about object (default returns classname()) | |
virtual real | evaluate (const Vec &x1, const Vec &x2) const |
** Subclasses must override this method ** | |
virtual real | evaluate_i_j (int i, int j) const |
returns evaluate(data(i),data(j)) | |
virtual void | setDataForKernelMatrix (VMat the_data) |
This method precomputes the squared norm for all the data to later speed up evaluate methods, if n == 2. | |
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 | |
Vec | weights |
Static Public Attributes | |
static StaticInitializer | _static_initializer_ |
Static Protected Member Functions | |
static void | declareOptions (OptionList &ol) |
Declare options (data fields) for the class. | |
Private Types | |
typedef Kernel | inherited |
This class implements an Ln distance (defaults to L2 i.e. euclidean distance).
Definition at line 53 of file WeightedDistance.h.
typedef Kernel PLearn::WeightedDistance::inherited [private] |
Reimplemented from PLearn::Kernel.
Definition at line 58 of file WeightedDistance.h.
PLearn::WeightedDistance::WeightedDistance | ( | ) |
Definition at line 59 of file WeightedDistance.cc.
{ }
PLearn::WeightedDistance::WeightedDistance | ( | Vec | the_weights | ) |
Definition at line 63 of file WeightedDistance.cc.
: weights(the_weights) { }
string PLearn::WeightedDistance::_classname_ | ( | ) | [static] |
Reimplemented from PLearn::Kernel.
Definition at line 54 of file WeightedDistance.cc.
OptionList & PLearn::WeightedDistance::_getOptionList_ | ( | ) | [static] |
Reimplemented from PLearn::Kernel.
Definition at line 54 of file WeightedDistance.cc.
RemoteMethodMap & PLearn::WeightedDistance::_getRemoteMethodMap_ | ( | ) | [static] |
Reimplemented from PLearn::Kernel.
Definition at line 54 of file WeightedDistance.cc.
Reimplemented from PLearn::Kernel.
Definition at line 54 of file WeightedDistance.cc.
Object * PLearn::WeightedDistance::_new_instance_for_typemap_ | ( | ) | [static] |
Reimplemented from PLearn::Object.
Definition at line 54 of file WeightedDistance.cc.
StaticInitializer WeightedDistance::_static_initializer_ & PLearn::WeightedDistance::_static_initialize_ | ( | ) | [static] |
Reimplemented from PLearn::Kernel.
Definition at line 54 of file WeightedDistance.cc.
string PLearn::WeightedDistance::classname | ( | ) | const [virtual] |
Reimplemented from PLearn::Object.
Definition at line 54 of file WeightedDistance.cc.
void PLearn::WeightedDistance::declareOptions | ( | OptionList & | ol | ) | [static, protected] |
Declare options (data fields) for the class.
Redefine this in subclasses: call declareOption
(...) for each option, and then call inherited::declareOptions(options)
. Please call the inherited
method AT THE END to get the options listed in a consistent order (from most recently defined to least recently defined).
static void MyDerivedClass::declareOptions(OptionList& ol) { declareOption(ol, "inputsize", &MyObject::inputsize_, OptionBase::buildoption, "The size of the input; it must be provided"); declareOption(ol, "weights", &MyObject::weights, OptionBase::learntoption, "The learned model weights"); inherited::declareOptions(ol); }
ol | List of options that is progressively being constructed for the current class. |
Reimplemented from PLearn::Kernel.
Definition at line 71 of file WeightedDistance.cc.
References PLearn::OptionBase::buildoption, PLearn::declareOption(), PLearn::Kernel::declareOptions(), and weights.
{ declareOption(ol, "weights", &WeightedDistance::weights, OptionBase::buildoption, "The vector of weights to apply to the distance computation."); inherited::declareOptions(ol); }
static const PPath& PLearn::WeightedDistance::declaringFile | ( | ) | [inline, static] |
Reimplemented from PLearn::Kernel.
Definition at line 67 of file WeightedDistance.h.
{ return "WL2"; }
WeightedDistance * PLearn::WeightedDistance::deepCopy | ( | CopiesMap & | copies | ) | const [virtual] |
Reimplemented from PLearn::Kernel.
Definition at line 54 of file WeightedDistance.cc.
** Subclasses must override this method **
returns K(x1,x2)
Implements PLearn::Kernel.
Definition at line 83 of file WeightedDistance.cc.
References i, PLearn::TVec< T >::length(), PLERROR, PLearn::pow(), and weights.
{ if (weights.length() != x1.length()) PLERROR("In WeightedDistance: inconsistent length between weigths and x1"); if (weights.length() != x2.length()) PLERROR("In WeightedDistance: inconsistent length between weigths and x2"); real return_value = 0.0; for (int i = 0; i < weights.length(); i++) { return_value += weights[i] * pow(x1[i] - x2[i], 2); } return return_value; }
returns evaluate(data(i),data(j))
Reimplemented from PLearn::Kernel.
Definition at line 98 of file WeightedDistance.cc.
References PLERROR.
{ PLERROR("In WeightedDistance: evaluate_i_j not implemented"); return 0.0; }
OptionList & PLearn::WeightedDistance::getOptionList | ( | ) | const [virtual] |
Reimplemented from PLearn::Object.
Definition at line 54 of file WeightedDistance.cc.
OptionMap & PLearn::WeightedDistance::getOptionMap | ( | ) | const [virtual] |
Reimplemented from PLearn::Object.
Definition at line 54 of file WeightedDistance.cc.
RemoteMethodMap & PLearn::WeightedDistance::getRemoteMethodMap | ( | ) | const [virtual] |
Reimplemented from PLearn::Object.
Definition at line 54 of file WeightedDistance.cc.
virtual string PLearn::WeightedDistance::info | ( | ) | const [inline, virtual] |
Returns a bit more informative string about object (default returns classname())
Reimplemented from PLearn::Object.
Definition at line 69 of file WeightedDistance.h.
{ return "WL2"; }
void PLearn::WeightedDistance::setDataForKernelMatrix | ( | VMat | the_data | ) | [virtual] |
This method precomputes the squared norm for all the data to later speed up evaluate methods, if n == 2.
Reimplemented from PLearn::Kernel.
Definition at line 107 of file WeightedDistance.cc.
References PLERROR.
{ PLERROR("In WeightedDistance: setDataForKernelMatrix not implemented"); }
Reimplemented from PLearn::Kernel.
Definition at line 67 of file WeightedDistance.h.
Definition at line 62 of file WeightedDistance.h.
Referenced by declareOptions(), and evaluate().