PLearn 0.1
|
#include <VMatKernel.h>
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 OptionList & | getOptionList () const |
virtual OptionMap & | getOptionMap () const |
virtual RemoteMethodMap & | getRemoteMethodMap () const |
virtual VMatKernel * | deepCopy (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 PPath & | declaringFile () |
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. |
Definition at line 53 of file VMatKernel.h.
typedef Kernel PLearn::VMatKernel::inherited [private] |
Reimplemented from PLearn::Kernel.
Definition at line 58 of file VMatKernel.h.
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_(); }
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.
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; }
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(); }
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); }
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.
Compute K(x1,x2).
Implements PLearn::Kernel.
Definition at line 107 of file VMatKernel.cc.
References PLASSERT, and PLearn::TVec< T >::size().
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] ); }
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]); }
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().
{ inherited::makeDeepCopyFromShallowCopy(copies); deepCopyField(source, copies); deepCopyField(train_indices, copies); }
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); } }
Reimplemented from PLearn::Kernel.
Definition at line 124 of file VMatKernel.h.
Definition at line 78 of file VMatKernel.h.
Referenced by declareOptions().
Vec PLearn::VMatKernel::train_indices [protected] |
Definition at line 70 of file VMatKernel.h.
Referenced by declareOptions().