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

This class implements an Ln distance (defaults to L2 i.e. euclidean distance). More...

#include <WeightedDistance.h>

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

List of all members.

Public Member Functions

 WeightedDistance ()
 WeightedDistance (Vec the_weights)
virtual string classname () const
virtual OptionListgetOptionList () const
virtual OptionMapgetOptionMap () const
virtual RemoteMethodMapgetRemoteMethodMap () const
virtual WeightedDistancedeepCopy (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 PPathdeclaringFile ()

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

Detailed Description

This class implements an Ln distance (defaults to L2 i.e. euclidean distance).

Definition at line 53 of file WeightedDistance.h.


Member Typedef Documentation

Reimplemented from PLearn::Kernel.

Definition at line 58 of file WeightedDistance.h.


Constructor & Destructor Documentation

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)
{
}

Member Function Documentation

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.

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

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);
  }
Parameters:
olList 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);
}

Here is the call graph for this function:

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.

real PLearn::WeightedDistance::evaluate ( const Vec x1,
const Vec x2 
) const [virtual]

** 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;
}

Here is the call graph for this function:

real PLearn::WeightedDistance::evaluate_i_j ( int  i,
int  j 
) const [virtual]

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())

Returns:
Information about the object

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");
}

Member Data Documentation

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().


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