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

#include <VMatKernel.h>

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

List of all members.

Public Member Functions

 VMatKernel ()
 Default constructor.
virtual void build ()
 Simply calls inherited::build() then build_().
virtual void makeDeepCopyFromShallowCopy (CopiesMap &copies)
 Transforms a shallow copy into a deep copy.
virtual string classname () const
virtual OptionListgetOptionList () const
virtual OptionMapgetOptionMap () const
virtual RemoteMethodMapgetRemoteMethodMap () const
virtual VMatKerneldeepCopy (CopiesMap &copies) const
virtual real evaluate (const Vec &x1, const Vec &x2) const
 Compute K(x1,x2).
virtual real evaluate (real x1, real x2) const
virtual real evaluate (int x1, int x2) const
virtual void setDataForKernelMatrix (VMat the_data)
 Overridden methods.
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_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
 Compute K(xi,xj) on training samples.
virtual real evaluate_x_i (const Vec &x, int i, real squared_norm_of_x=-1) const
 returns evaluate(x,data(i)) [default version calls evaluate_i_x if kernel is_symmetric]
virtual void computeGramMatrix (Mat K) const
 Call evaluate_i_j to fill each of the entries (i,j) of symmetric matrix K.

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

VMat source

Static Public Attributes

static StaticInitializer _static_initializer_

Static Protected Member Functions

static void declareOptions (OptionList &ol)
 Declares this class' options.

Protected Attributes

Vec train_indices

Private Types

typedef Kernel inherited

Private Member Functions

void build_ ()
 This does the actual building.

Detailed Description

Definition at line 53 of file VMatKernel.h.


Member Typedef Documentation

Reimplemented from PLearn::Kernel.

Definition at line 58 of file VMatKernel.h.


Constructor & Destructor Documentation

PLearn::VMatKernel::VMatKernel ( )

Default constructor.

Definition at line 53 of file VMatKernel.cc.

{
    // ...

    // ### You may or may not want to call build_() to finish building the object
    // build_();
}

Member Function Documentation

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

Reimplemented from PLearn::Kernel.

Definition at line 65 of file VMatKernel.cc.

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

Reimplemented from PLearn::Kernel.

Definition at line 65 of file VMatKernel.cc.

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

Reimplemented from PLearn::Kernel.

Definition at line 65 of file VMatKernel.cc.

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

Reimplemented from PLearn::Kernel.

Definition at line 65 of file VMatKernel.cc.

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

Reimplemented from PLearn::Object.

Definition at line 65 of file VMatKernel.cc.

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

Reimplemented from PLearn::Kernel.

Definition at line 65 of file VMatKernel.cc.

void PLearn::VMatKernel::addDataForKernelMatrix ( const Vec newRow) [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 243 of file VMatKernel.cc.

References i, PLASSERT, and PLearn::TVec< T >::size().

{
    PLASSERT( newRow.size() == 1 );
    inherited::addDataForKernelMatrix( newRow );
    if( train_indices.length() == 0 )
    {
        PLASSERT( source );
        n_examples = source->width();
        train_indices.resize( n_examples );
        for(int i = 0; i < n_examples; i++)
            train_indices[i] = (real)i;
    }
    PLASSERT( newRow[0] > 0 );
    PLASSERT( !(source) || ( newRow[0] < source->width() ) );
    train_indices.resize( n_examples + 1 );
    train_indices[ n_examples ] = newRow[0];
    n_examples += 1;
}

Here is the call graph for this function:

void PLearn::VMatKernel::build ( ) [virtual]

Simply calls inherited::build() then build_().

Reimplemented from PLearn::Kernel.

Definition at line 87 of file VMatKernel.cc.

{
    // ### Nothing to add here, simply calls build_
    inherited::build();
    build_();
}
void PLearn::VMatKernel::build_ ( ) [private]

This does the actual building.

Reimplemented from PLearn::Kernel.

Definition at line 97 of file VMatKernel.cc.

References PLASSERT.

{
    PLASSERT( !(source) || ( source->length() == source->width() ) );
    if ( !specify_dataset )
        train_indices.resize(0);
}
string PLearn::VMatKernel::classname ( ) const [virtual]

Reimplemented from PLearn::Object.

Definition at line 65 of file VMatKernel.cc.

void PLearn::VMatKernel::computeGramMatrix ( Mat  K) const [virtual]

Call evaluate_i_j to fill each of the entries (i,j) of symmetric matrix K.

Reimplemented from PLearn::Kernel.

Definition at line 176 of file VMatKernel.cc.

References i, j, PLASSERT, and PLearn::TMat< T >::resize().

{
    PLASSERT( source );
    if( train_indices.length() > 0 )
    {
        K.resize(n_examples, n_examples);
        if( is_symmetric )
            for(int i = 0; i < n_examples; i++ )
            {
                K(i,i) = evaluate( train_indices[i], train_indices[i] );
                for(int j = 0; j < i; j++ )
                {
                    K(i,j) = evaluate( train_indices[i], train_indices[j] );
                    K(j,i) = K(i,j);
                }
            }
        else
            for(int i = 0; i < n_examples; i++ )
                for(int j = 0; j < n_examples; j++ )
                    K(i,j) = evaluate( train_indices[i], train_indices[j] );
    }
    else
        K << source->toMat();
}

Here is the call graph for this function:

void PLearn::VMatKernel::declareOptions ( OptionList ol) [static, protected]

Declares this class' options.

Reimplemented from PLearn::Kernel.

Definition at line 70 of file VMatKernel.cc.

References PLearn::OptionBase::buildoption, PLearn::declareOption(), PLearn::OptionBase::learntoption, source, and train_indices.

{
    declareOption(ol,"source",&VMatKernel::source,
                  OptionBase::buildoption,
        "Gram matrix");

    declareOption(ol,"train_indices",&VMatKernel::train_indices,
                  OptionBase::learntoption,
        "List of (real)indices corresponding to training samples");

    // Now call the parent class' declareOptions
    inherited::declareOptions(ol);
}

Here is the call graph for this function:

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

Reimplemented from PLearn::Kernel.

Definition at line 124 of file VMatKernel.h.

VMatKernel * PLearn::VMatKernel::deepCopy ( CopiesMap copies) const [virtual]

Reimplemented from PLearn::Kernel.

Definition at line 65 of file VMatKernel.cc.

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

Compute K(x1,x2).

Implements PLearn::Kernel.

Definition at line 107 of file VMatKernel.cc.

References PLASSERT, and PLearn::TVec< T >::size().

{
    PLASSERT( x1.size()==1 && x2.size()==1 );
    return evaluate( x1[0], x2[0] );
}

Here is the call graph for this function:

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

Definition at line 113 of file VMatKernel.cc.

References PLASSERT.

{
    PLASSERT( fabs(x1-(real)((int)x1)) < 0.1 );
    PLASSERT( fabs(x2-(real)((int)x2)) < 0.1 );
    return evaluate( int(x1), int(x2) );
}
real PLearn::VMatKernel::evaluate ( int  x1,
int  x2 
) const [virtual]

Definition at line 120 of file VMatKernel.cc.

References PLASSERT.

{
    PLASSERT( source );
    PLASSERT( x1 >= 0 );
    PLASSERT( x1 < source->length() );
    PLASSERT( x2 >= 0 );
    PLASSERT( x2 < source->width() );
    return source->get( x1, x2);
}
real PLearn::VMatKernel::evaluate_i_j ( int  i,
int  j 
) const [virtual]

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

Reimplemented from PLearn::Kernel.

Definition at line 133 of file VMatKernel.cc.

References PLASSERT.

{
    PLASSERT( source );
    if( train_indices.length() == 0 )
        return evaluate( i, j );
    PLASSERT( i >= 0 );
    PLASSERT( i < n_examples );
    PLASSERT( j >= 0 );
    PLASSERT( j < n_examples );
    return evaluate( train_indices[i], train_indices[j] );
}
real PLearn::VMatKernel::evaluate_i_x ( int  i,
const Vec x,
real  squared_norm_of_x = -1 
) const [virtual]

Compute K(xi,xj) on training samples.

Reimplemented from PLearn::Kernel.

Definition at line 148 of file VMatKernel.cc.

References PLASSERT, and PLearn::TVec< T >::size().

{
    if( train_indices.length() == 0 )
        return evaluate( i, (int)x[0] );
    PLASSERT( i >= 0 );
    PLASSERT( i < n_examples );
    PLASSERT( x.size() == 1 );
    return evaluate( train_indices[i], x[0] );
}

Here is the call graph for this function:

real PLearn::VMatKernel::evaluate_x_i ( const Vec x,
int  i,
real  squared_norm_of_x = -1 
) const [virtual]

returns evaluate(x,data(i)) [default version calls evaluate_i_x if kernel is_symmetric]

Reimplemented from PLearn::Kernel.

Definition at line 161 of file VMatKernel.cc.

References i, PLASSERT, and PLearn::TVec< T >::size().

{
//    if( is_symmetric )
//        return evaluate_i_x( i, x, squared_norm_of_x);
    if( train_indices.length() == 0 )
        return evaluate( (int)x[0], i);
    PLASSERT( i >= 0 );
    PLASSERT( i < n_examples );
    PLASSERT( x.size() == 1 );
    return evaluate( x[0], train_indices[i]);
}

Here is the call graph for this function:

OptionList & PLearn::VMatKernel::getOptionList ( ) const [virtual]

Reimplemented from PLearn::Object.

Definition at line 65 of file VMatKernel.cc.

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

Reimplemented from PLearn::Object.

Definition at line 65 of file VMatKernel.cc.

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

Reimplemented from PLearn::Object.

Definition at line 65 of file VMatKernel.cc.

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

Transforms a shallow copy into a deep copy.

Reimplemented from PLearn::Kernel.

Definition at line 205 of file VMatKernel.cc.

References PLearn::deepCopyField().

Here is the call graph for this function:

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

Overridden methods.

Reimplemented from PLearn::Kernel.

Definition at line 216 of file VMatKernel.cc.

References i, PLASSERT, PLWARNING, and PLearn::VMat::width().

{
    inherited::setDataForKernelMatrix(the_data);

    if( n_examples > 1 )
    {
        PLASSERT( data_inputsize == 1 );
        train_indices.resize(n_examples);
        for(int i = 0; i < n_examples; i++)
        {
            PLASSERT( the_data->get(i,0) >= 0 );
            PLASSERT( !(source) || ( the_data->get(i,0) < (real)source->width() ) );
            train_indices[i] = the_data->get(i,0);
        }
    }
    else
    {
        PLASSERT( source );
        PLWARNING("in VMatKernel::setDataForKernelMatrix: all values in the VMatKernel source are taken into acount for training");
        n_examples = source->width();
        train_indices.resize(0);
    }
}

Here is the call graph for this function:


Member Data Documentation

Reimplemented from PLearn::Kernel.

Definition at line 124 of file VMatKernel.h.

Definition at line 78 of file VMatKernel.h.

Referenced by declareOptions().

Definition at line 70 of file VMatKernel.h.

Referenced by declareOptions().


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