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

A kernel that precomputes the kernel matrix as soon as setDataForKernelMatrix is called. More...

#include <PrecomputedKernel.h>

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

List of all members.

Public Member Functions

 PrecomputedKernel ()
 PrecomputedKernel (Ker the_ker)
virtual void build ()
 Post-constructor.
virtual string classname () const
virtual OptionListgetOptionList () const
virtual OptionMapgetOptionMap () const
virtual RemoteMethodMapgetRemoteMethodMap () const
virtual PrecomputedKerneldeepCopy (CopiesMap &copies) const
virtual void makeDeepCopyFromShallowCopy (CopiesMap &copies)
 Does the necessary operations to transform a shallow copy (this) into a deep copy by deep-copying all the members that need to be.
virtual void setDataForKernelMatrix (VMat the_data)
 This method precomputes and stores all kernel values.
virtual void addDataForKernelMatrix (const Vec &newRow)
 This method is meant to be used any time the data matrix is appended a new row by an outer instance (e.g.
virtual real evaluate (const Vec &x1, const Vec &x2) const
 simply forwards to underlying kernel
virtual real evaluate_i_j (int i, int j) const
 returns evaluate(data(i),data(j))
virtual real evaluate_i_x (int i, const Vec &x, real squared_norm_of_x=-1) const
 returns evaluate(data(i),x)
virtual real evaluate_x_i (const Vec &x, int i, real squared_norm_of_x=-1) const
 returns evaluate(x,data(i))

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

Static Public Attributes

static StaticInitializer _static_initializer_

Static Protected Member Functions

static void declareOptions (OptionList &ol)
 Declare options (data fields) for the class.

Protected Attributes

Ker ker
 the real underlying kernel
TVec< VecprecomputedK
 the precomputed kernel matrix

Private Types

typedef Kernel inherited

Private Member Functions

void build_ ()
 Object-specific post-constructor.

Detailed Description

A kernel that precomputes the kernel matrix as soon as setDataForKernelMatrix is called.

Definition at line 54 of file PrecomputedKernel.h.


Member Typedef Documentation

Reimplemented from PLearn::Kernel.

Definition at line 56 of file PrecomputedKernel.h.


Constructor & Destructor Documentation

PLearn::PrecomputedKernel::PrecomputedKernel ( ) [inline]

Definition at line 70 of file PrecomputedKernel.h.

    {}
PLearn::PrecomputedKernel::PrecomputedKernel ( Ker  the_ker) [inline]

Definition at line 73 of file PrecomputedKernel.h.

                                  : 
        ker(the_ker) //, precomputedK(0) 
    {}

Member Function Documentation

string PLearn::PrecomputedKernel::_classname_ ( ) [static]

Reimplemented from PLearn::Kernel.

Definition at line 52 of file PrecomputedKernel.cc.

OptionList & PLearn::PrecomputedKernel::_getOptionList_ ( ) [static]

Reimplemented from PLearn::Kernel.

Definition at line 52 of file PrecomputedKernel.cc.

RemoteMethodMap & PLearn::PrecomputedKernel::_getRemoteMethodMap_ ( ) [static]

Reimplemented from PLearn::Kernel.

Definition at line 52 of file PrecomputedKernel.cc.

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

Reimplemented from PLearn::Kernel.

Definition at line 52 of file PrecomputedKernel.cc.

Object * PLearn::PrecomputedKernel::_new_instance_for_typemap_ ( ) [static]

Reimplemented from PLearn::Object.

Definition at line 52 of file PrecomputedKernel.cc.

StaticInitializer PrecomputedKernel::_static_initializer_ & PLearn::PrecomputedKernel::_static_initialize_ ( ) [static]

Reimplemented from PLearn::Kernel.

Definition at line 52 of file PrecomputedKernel.cc.

virtual void PLearn::PrecomputedKernel::addDataForKernelMatrix ( const Vec newRow) [inline, virtual]

This method is meant to be used any time the data matrix is appended a new row by an outer instance (e.g.

SequentialKernel). Through this method, the kernel must update any data dependent internal structure. The internal structures should have consistent length with the data matrix, assuming a sequential growing of the vmat.

Reimplemented from PLearn::Kernel.

Definition at line 86 of file PrecomputedKernel.h.

References PLERROR.

    { PLERROR("PrecomputedKernel does not manage size varying data vmat. Use SequentialKernel instead."); }
void PLearn::PrecomputedKernel::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::Kernel.

Definition at line 64 of file PrecomputedKernel.cc.

void PLearn::PrecomputedKernel::build_ ( ) [private]

Object-specific post-constructor.

This method should be redefined in subclasses and do the actual building of the object according to previously set option fields. Constructors can just set option fields, and then call build_. This method is NOT virtual, and will typically be called only from three places: a constructor, the public virtual build() method, and possibly the public virtual read method (which calls its parent's read). build_() can assume that its parent's build_() has already been called.

Reimplemented from PLearn::Kernel.

Definition at line 60 of file PrecomputedKernel.cc.

{}
string PLearn::PrecomputedKernel::classname ( ) const [virtual]

Reimplemented from PLearn::Object.

Definition at line 52 of file PrecomputedKernel.cc.

void PLearn::PrecomputedKernel::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 150 of file PrecomputedKernel.cc.

References PLearn::OptionBase::buildoption, PLearn::declareOption(), and ker.

Here is the call graph for this function:

static const PPath& PLearn::PrecomputedKernel::declaringFile ( ) [inline, static]

Reimplemented from PLearn::Kernel.

Definition at line 80 of file PrecomputedKernel.h.

{ PLERROR("PrecomputedKernel does not manage size varying data vmat. Use SequentialKernel instead."); }
PrecomputedKernel * PLearn::PrecomputedKernel::deepCopy ( CopiesMap copies) const [virtual]

Reimplemented from PLearn::Kernel.

Definition at line 52 of file PrecomputedKernel.cc.

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

simply forwards to underlying kernel

returns K(x1,x2)

Implements PLearn::Kernel.

Definition at line 126 of file PrecomputedKernel.cc.

{ return ker->evaluate(x1,x2); }
real PLearn::PrecomputedKernel::evaluate_i_j ( int  i,
int  j 
) const [virtual]

returns evaluate(data(i),data(j))

Reimplemented from PLearn::Kernel.

Definition at line 130 of file PrecomputedKernel.cc.

References i, j, and PLERROR.

{ 
#ifdef BOUNDCHECK
    if(precomputedK.isNull())
        PLERROR("In PrecomputedKernel::evaluate_i_j data must first be set with setDataForKernelMatrix");
    else if(i<0 || j<0 || i>=data.length() || j>=data.length())
        PLERROR("In PrecomputedKernel::evaluate_i_j i (%d) and j (%d) must be between 0 and data.length() (%d)",
                i, j, data.length());
#endif
    return precomputedK[i][j];//[i*data.length()+j];
}
real PLearn::PrecomputedKernel::evaluate_i_x ( int  i,
const Vec x,
real  squared_norm_of_x = -1 
) const [virtual]

returns evaluate(data(i),x)

Reimplemented from PLearn::Kernel.

Definition at line 143 of file PrecomputedKernel.cc.

{ return ker->evaluate_i_x(i,x,squared_norm_of_x); }
real PLearn::PrecomputedKernel::evaluate_x_i ( const Vec x,
int  i,
real  squared_norm_of_x = -1 
) const [virtual]

returns evaluate(x,data(i))

Reimplemented from PLearn::Kernel.

Definition at line 147 of file PrecomputedKernel.cc.

{ return ker->evaluate_x_i(x,i,squared_norm_of_x); }
OptionList & PLearn::PrecomputedKernel::getOptionList ( ) const [virtual]

Reimplemented from PLearn::Object.

Definition at line 52 of file PrecomputedKernel.cc.

OptionMap & PLearn::PrecomputedKernel::getOptionMap ( ) const [virtual]

Reimplemented from PLearn::Object.

Definition at line 52 of file PrecomputedKernel.cc.

RemoteMethodMap & PLearn::PrecomputedKernel::getRemoteMethodMap ( ) const [virtual]

Reimplemented from PLearn::Object.

Definition at line 52 of file PrecomputedKernel.cc.

void PLearn::PrecomputedKernel::makeDeepCopyFromShallowCopy ( CopiesMap copies) [virtual]

Does the necessary operations to transform a shallow copy (this) into a deep copy by deep-copying all the members that need to be.

This needs to be overridden by every class that adds "complex" data members to the class, such as Vec, Mat, PP<Something>, etc. Typical implementation:

  void CLASS_OF_THIS::makeDeepCopyFromShallowCopy(CopiesMap& copies)
  {
      inherited::makeDeepCopyFromShallowCopy(copies);
      deepCopyField(complex_data_member1, copies);
      deepCopyField(complex_data_member2, copies);
      ...
  }
Parameters:
copiesA map used by the deep-copy mechanism to keep track of already-copied objects.

Reimplemented from PLearn::Kernel.

Definition at line 72 of file PrecomputedKernel.cc.

References PLearn::deepCopyField().

Here is the call graph for this function:

void PLearn::PrecomputedKernel::setDataForKernelMatrix ( VMat  the_data) [virtual]

This method precomputes and stores all kernel values.

Reimplemented from PLearn::Kernel.

Definition at line 104 of file PrecomputedKernel.cc.

References i, j, and PLearn::Kernel::setDataForKernelMatrix().

{   
    Kernel::setDataForKernelMatrix(the_data);
    ker->setDataForKernelMatrix(the_data);
  
    int len = data.length();
    precomputedK.resize(len); //TVec of lines!!!
    for(int i=0; i < len; i++)
    {
        precomputedK[i].resize(len);
    
        for(int j=0; j < len; j++)
        {
            if(is_symmetric && j<i)
                precomputedK[i][j] = precomputedK[j][i];
            else
                precomputedK[i][j] = ker->evaluate_i_j(i,j);
        }
    }
}

Here is the call graph for this function:


Member Data Documentation

Reimplemented from PLearn::Kernel.

Definition at line 80 of file PrecomputedKernel.h.

the real underlying kernel

Definition at line 59 of file PrecomputedKernel.h.

Referenced by declareOptions().

the precomputed kernel matrix

Definition at line 60 of file PrecomputedKernel.h.


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