PLearn 0.1
|
Base class for kernels that make use of Kronecker terms. More...
#include <KroneckerBaseKernel.h>
Public Member Functions | |
KroneckerBaseKernel () | |
Default constructor. | |
virtual real | evaluate (const Vec &x1, const Vec &x2) const |
Compute K(x1,x2). | |
virtual void | computeGramMatrix (Mat K) const |
Compute the Gram Matrix. | |
virtual string | classname () const |
virtual OptionList & | getOptionList () const |
virtual OptionMap & | getOptionMap () const |
virtual RemoteMethodMap & | getRemoteMethodMap () const |
virtual KroneckerBaseKernel * | deepCopy (CopiesMap &copies) const |
virtual void | build () |
Post-constructor. | |
virtual void | makeDeepCopyFromShallowCopy (CopiesMap &copies) |
Transforms a shallow copy into a deep copy. | |
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 | |
TVec< int > | m_kronecker_indexes |
Element index in the input vectors that should be subject to additional Kronecker delta terms. | |
Static Public Attributes | |
static StaticInitializer | _static_initializer_ |
Static Protected Member Functions | |
static void | declareOptions (OptionList &ol) |
Declares the class options. | |
static real | softplusFloor (real &value, real floor=1e-6) |
Utility function for derived classes: return the softplus of its argument, but if the softplus would fall below the given floor, then return the floor AND MODIFY the original argument to represent the inverse softplus of the floor. | |
Protected Attributes | |
real | m_default_value |
Value to be used for kernel evaluation if there are no kronecker terms. | |
Private Types | |
typedef MemoryCachedKernel | inherited |
Private Member Functions | |
void | build_ () |
This does the actual building. |
Base class for kernels that make use of Kronecker terms.
This kernel allows the specification of product a of Kronecker delta terms when there is a match of VALUE in ONE DIMENSION. (This may be generalized in the future to allow match according to a subset of the input variables, but is not currently done for performance reasons). With these terms, the kernel function takes the form:
where kr(i) is the i-th element of 'kronecker_indexes' (representing an index into the input vectors). Derived classes can either integrate these terms additively (e.g. KroneckerBaseKernel) or multiplicatively (e.g. ARDBaseKernel and derived classes). Note that this class does not provide any hyperparameter associated with this product; an hyperparameter may be included by derived classes as required. (Currently, only IIDNoiseKernel needs one; in other kernels, this is absorbed by the global function noise hyperparameter).
The basic idea for Kronecker terms is to selectively build in parts of a covariance function based on matches in the value of some input variables. They are useful in conjunction with a "covariance function builder" such as SummationKernel.
Definition at line 72 of file KroneckerBaseKernel.h.
typedef MemoryCachedKernel PLearn::KroneckerBaseKernel::inherited [private] |
Reimplemented from PLearn::MemoryCachedKernel.
Reimplemented in PLearn::ARDBaseKernel, PLearn::IIDNoiseKernel, PLearn::LinearARDKernel, PLearn::Matern1ARDKernel, PLearn::NeuralNetworkARDKernel, PLearn::PLearnerDiagonalKernel, PLearn::RationalQuadraticARDKernel, and PLearn::SquaredExponentialARDKernel.
Definition at line 74 of file KroneckerBaseKernel.h.
PLearn::KroneckerBaseKernel::KroneckerBaseKernel | ( | ) |
Default constructor.
Definition at line 73 of file KroneckerBaseKernel.cc.
: m_default_value(0.) { }
string PLearn::KroneckerBaseKernel::_classname_ | ( | ) | [static] |
Reimplemented from PLearn::MemoryCachedKernel.
Reimplemented in PLearn::ARDBaseKernel, PLearn::IIDNoiseKernel, PLearn::LinearARDKernel, PLearn::Matern1ARDKernel, PLearn::NeuralNetworkARDKernel, PLearn::PLearnerDiagonalKernel, PLearn::RationalQuadraticARDKernel, and PLearn::SquaredExponentialARDKernel.
Definition at line 70 of file KroneckerBaseKernel.cc.
OptionList & PLearn::KroneckerBaseKernel::_getOptionList_ | ( | ) | [static] |
Reimplemented from PLearn::MemoryCachedKernel.
Reimplemented in PLearn::ARDBaseKernel, PLearn::IIDNoiseKernel, PLearn::LinearARDKernel, PLearn::Matern1ARDKernel, PLearn::NeuralNetworkARDKernel, PLearn::PLearnerDiagonalKernel, PLearn::RationalQuadraticARDKernel, and PLearn::SquaredExponentialARDKernel.
Definition at line 70 of file KroneckerBaseKernel.cc.
RemoteMethodMap & PLearn::KroneckerBaseKernel::_getRemoteMethodMap_ | ( | ) | [static] |
Reimplemented from PLearn::MemoryCachedKernel.
Reimplemented in PLearn::ARDBaseKernel, PLearn::IIDNoiseKernel, PLearn::LinearARDKernel, PLearn::Matern1ARDKernel, PLearn::NeuralNetworkARDKernel, PLearn::PLearnerDiagonalKernel, PLearn::RationalQuadraticARDKernel, and PLearn::SquaredExponentialARDKernel.
Definition at line 70 of file KroneckerBaseKernel.cc.
Reimplemented from PLearn::MemoryCachedKernel.
Reimplemented in PLearn::ARDBaseKernel, PLearn::IIDNoiseKernel, PLearn::LinearARDKernel, PLearn::Matern1ARDKernel, PLearn::NeuralNetworkARDKernel, PLearn::PLearnerDiagonalKernel, PLearn::RationalQuadraticARDKernel, and PLearn::SquaredExponentialARDKernel.
Definition at line 70 of file KroneckerBaseKernel.cc.
Object * PLearn::KroneckerBaseKernel::_new_instance_for_typemap_ | ( | ) | [static] |
Reimplemented from PLearn::Object.
Reimplemented in PLearn::ARDBaseKernel, PLearn::IIDNoiseKernel, PLearn::LinearARDKernel, PLearn::Matern1ARDKernel, PLearn::NeuralNetworkARDKernel, PLearn::PLearnerDiagonalKernel, PLearn::RationalQuadraticARDKernel, and PLearn::SquaredExponentialARDKernel.
Definition at line 70 of file KroneckerBaseKernel.cc.
StaticInitializer KroneckerBaseKernel::_static_initializer_ & PLearn::KroneckerBaseKernel::_static_initialize_ | ( | ) | [static] |
Reimplemented from PLearn::MemoryCachedKernel.
Reimplemented in PLearn::ARDBaseKernel, PLearn::IIDNoiseKernel, PLearn::LinearARDKernel, PLearn::Matern1ARDKernel, PLearn::NeuralNetworkARDKernel, PLearn::PLearnerDiagonalKernel, PLearn::RationalQuadraticARDKernel, and PLearn::SquaredExponentialARDKernel.
Definition at line 70 of file KroneckerBaseKernel.cc.
void PLearn::KroneckerBaseKernel::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::MemoryCachedKernel.
Reimplemented in PLearn::ARDBaseKernel, PLearn::IIDNoiseKernel, PLearn::LinearARDKernel, PLearn::Matern1ARDKernel, PLearn::NeuralNetworkARDKernel, PLearn::PLearnerDiagonalKernel, PLearn::RationalQuadraticARDKernel, and PLearn::SquaredExponentialARDKernel.
Definition at line 95 of file KroneckerBaseKernel.cc.
References PLearn::MemoryCachedKernel::build(), and build_().
Referenced by PLearn::PLearnerDiagonalKernel::build(), PLearn::IIDNoiseKernel::build(), and PLearn::ARDBaseKernel::build().
{ // ### Nothing to add here, simply calls build_ inherited::build(); build_(); }
void PLearn::KroneckerBaseKernel::build_ | ( | ) | [private] |
This does the actual building.
Reimplemented from PLearn::MemoryCachedKernel.
Reimplemented in PLearn::ARDBaseKernel, PLearn::IIDNoiseKernel, PLearn::LinearARDKernel, PLearn::Matern1ARDKernel, PLearn::NeuralNetworkARDKernel, PLearn::PLearnerDiagonalKernel, PLearn::RationalQuadraticARDKernel, and PLearn::SquaredExponentialARDKernel.
Definition at line 105 of file KroneckerBaseKernel.cc.
Referenced by build().
{ }
string PLearn::KroneckerBaseKernel::classname | ( | ) | const [virtual] |
Reimplemented from PLearn::Object.
Reimplemented in PLearn::ARDBaseKernel, PLearn::IIDNoiseKernel, PLearn::LinearARDKernel, PLearn::Matern1ARDKernel, PLearn::NeuralNetworkARDKernel, PLearn::PLearnerDiagonalKernel, PLearn::RationalQuadraticARDKernel, and PLearn::SquaredExponentialARDKernel.
Definition at line 70 of file KroneckerBaseKernel.cc.
void PLearn::KroneckerBaseKernel::computeGramMatrix | ( | Mat | K | ) | const [virtual] |
Compute the Gram Matrix.
Note that this version DOES NOT CACHE the results, since it is usually called by derived classes.
Reimplemented from PLearn::Kernel.
Reimplemented in PLearn::IIDNoiseKernel, PLearn::LinearARDKernel, PLearn::Matern1ARDKernel, PLearn::NeuralNetworkARDKernel, PLearn::PLearnerDiagonalKernel, PLearn::RationalQuadraticARDKernel, and PLearn::SquaredExponentialARDKernel.
Definition at line 127 of file KroneckerBaseKernel.cc.
References PLearn::TVec< T >::data(), PLearn::Kernel::data, PLearn::fast_is_equal(), i, PLearn::Kernel::is_symmetric, j, PLearn::VMat::length(), PLearn::TMat< T >::length(), m, PLearn::MemoryCachedKernel::m_data_cache, m_default_value, m_kronecker_indexes, PLearn::TMat< T >::mod(), PLASSERT, PLERROR, PLearn::product(), PLearn::TVec< T >::size(), PLearn::TMat< T >::size(), and PLearn::TMat< T >::width().
Referenced by PLearn::RationalQuadraticARDKernel::computeGramMatrix(), PLearn::Matern1ARDKernel::computeGramMatrix(), and PLearn::IIDNoiseKernel::computeGramMatrix().
{ if (!data) PLERROR("Kernel::computeGramMatrix: setDataForKernelMatrix not yet called"); if (!is_symmetric) PLERROR("Kernel::computeGramMatrix: not supported for non-symmetric kernels"); if (K.length() != data.length() || K.width() != data.length()) PLERROR("Kernel::computeGramMatrix: the argument matrix K should be\n" "of size %d x %d (currently of size %d x %d)", data.length(), data.length(), K.length(), K.width()); PLASSERT( K.size() == 0 || m_data_cache.size() > 0 ); // Ensure data cached OK // Prepare kronecker iteration int kronecker_num = m_kronecker_indexes.size(); int* kronecker_indexes = ( kronecker_num > 0? m_kronecker_indexes.data() : 0 ); // Compute Gram Matrix int l = data->length(); int m = K.mod(); int cache_mod = m_data_cache.mod(); real *data_start = &m_data_cache(0,0); real Kij = m_default_value; real *Ki, *Kji; real *xi = data_start; for (int i=0 ; i<l ; ++i, xi += cache_mod) { Ki = K[i]; Kji = &K[0][i]; real *xj = data_start; for (int j=0; j<=i; ++j, Kji += m, xj += cache_mod) { if (kronecker_num > 0) { real product = 1.0; int* cur_index = kronecker_indexes; // Go over Kronecker terms, skipping over an eventual omitted term for (int k=0 ; k<kronecker_num ; ++k, ++cur_index) if (! fast_is_equal(xi[*cur_index], xj[*cur_index])) { product = 0.0; break; } Kij = product; } *Ki++ = Kij; } } }
void PLearn::KroneckerBaseKernel::declareOptions | ( | OptionList & | ol | ) | [static, protected] |
Declares the class options.
Reimplemented from PLearn::MemoryCachedKernel.
Reimplemented in PLearn::ARDBaseKernel, PLearn::IIDNoiseKernel, PLearn::LinearARDKernel, PLearn::Matern1ARDKernel, PLearn::NeuralNetworkARDKernel, PLearn::PLearnerDiagonalKernel, PLearn::RationalQuadraticARDKernel, and PLearn::SquaredExponentialARDKernel.
Definition at line 80 of file KroneckerBaseKernel.cc.
References PLearn::OptionBase::buildoption, PLearn::declareOption(), PLearn::MemoryCachedKernel::declareOptions(), and m_kronecker_indexes.
Referenced by PLearn::PLearnerDiagonalKernel::declareOptions(), PLearn::IIDNoiseKernel::declareOptions(), and PLearn::ARDBaseKernel::declareOptions().
{ declareOption( ol, "kronecker_indexes", &KroneckerBaseKernel::m_kronecker_indexes, OptionBase::buildoption, "Element index in the input vectors that should be subject to additional\n" "Kronecker delta terms"); // Now call the parent class' declareOptions inherited::declareOptions(ol); }
static const PPath& PLearn::KroneckerBaseKernel::declaringFile | ( | ) | [inline, static] |
Reimplemented from PLearn::MemoryCachedKernel.
Reimplemented in PLearn::ARDBaseKernel, PLearn::IIDNoiseKernel, PLearn::LinearARDKernel, PLearn::Matern1ARDKernel, PLearn::NeuralNetworkARDKernel, PLearn::PLearnerDiagonalKernel, PLearn::RationalQuadraticARDKernel, and PLearn::SquaredExponentialARDKernel.
Definition at line 103 of file KroneckerBaseKernel.h.
:
KroneckerBaseKernel * PLearn::KroneckerBaseKernel::deepCopy | ( | CopiesMap & | copies | ) | const [virtual] |
Reimplemented from PLearn::MemoryCachedKernel.
Reimplemented in PLearn::ARDBaseKernel, PLearn::IIDNoiseKernel, PLearn::LinearARDKernel, PLearn::Matern1ARDKernel, PLearn::NeuralNetworkARDKernel, PLearn::PLearnerDiagonalKernel, PLearn::RationalQuadraticARDKernel, and PLearn::SquaredExponentialARDKernel.
Definition at line 70 of file KroneckerBaseKernel.cc.
Compute K(x1,x2).
Implements PLearn::Kernel.
Reimplemented in PLearn::IIDNoiseKernel, PLearn::LinearARDKernel, PLearn::Matern1ARDKernel, PLearn::NeuralNetworkARDKernel, PLearn::PLearnerDiagonalKernel, PLearn::RationalQuadraticARDKernel, and PLearn::SquaredExponentialARDKernel.
Definition at line 111 of file KroneckerBaseKernel.cc.
References PLearn::TVec< T >::data(), PLearn::fast_is_equal(), i, m_default_value, m_kronecker_indexes, n, and PLearn::TVec< T >::size().
Referenced by PLearn::RationalQuadraticARDKernel::evaluate(), PLearn::PLearnerDiagonalKernel::evaluate(), PLearn::Matern1ARDKernel::evaluate(), PLearn::IIDNoiseKernel::evaluate(), PLearn::RationalQuadraticARDKernel::evaluate_all_i_x(), PLearn::IIDNoiseKernel::evaluate_all_i_x(), and PLearn::IIDNoiseKernel::evaluate_i_x().
{ const int n = m_kronecker_indexes.size(); if (n > 0) { int* cur_index = m_kronecker_indexes.data(); for (int i=0 ; i<n ; ++i, ++cur_index) if (! fast_is_equal(x1[*cur_index], x2[*cur_index])) return 0.0; return 1.0; } return m_default_value; }
OptionList & PLearn::KroneckerBaseKernel::getOptionList | ( | ) | const [virtual] |
Reimplemented from PLearn::Object.
Reimplemented in PLearn::ARDBaseKernel, PLearn::IIDNoiseKernel, PLearn::LinearARDKernel, PLearn::Matern1ARDKernel, PLearn::NeuralNetworkARDKernel, PLearn::PLearnerDiagonalKernel, PLearn::RationalQuadraticARDKernel, and PLearn::SquaredExponentialARDKernel.
Definition at line 70 of file KroneckerBaseKernel.cc.
OptionMap & PLearn::KroneckerBaseKernel::getOptionMap | ( | ) | const [virtual] |
Reimplemented from PLearn::Object.
Reimplemented in PLearn::ARDBaseKernel, PLearn::IIDNoiseKernel, PLearn::LinearARDKernel, PLearn::Matern1ARDKernel, PLearn::NeuralNetworkARDKernel, PLearn::PLearnerDiagonalKernel, PLearn::RationalQuadraticARDKernel, and PLearn::SquaredExponentialARDKernel.
Definition at line 70 of file KroneckerBaseKernel.cc.
RemoteMethodMap & PLearn::KroneckerBaseKernel::getRemoteMethodMap | ( | ) | const [virtual] |
Reimplemented from PLearn::Object.
Reimplemented in PLearn::ARDBaseKernel, PLearn::IIDNoiseKernel, PLearn::LinearARDKernel, PLearn::Matern1ARDKernel, PLearn::NeuralNetworkARDKernel, PLearn::PLearnerDiagonalKernel, PLearn::RationalQuadraticARDKernel, and PLearn::SquaredExponentialARDKernel.
Definition at line 70 of file KroneckerBaseKernel.cc.
void PLearn::KroneckerBaseKernel::makeDeepCopyFromShallowCopy | ( | CopiesMap & | copies | ) | [virtual] |
Transforms a shallow copy into a deep copy.
Reimplemented from PLearn::MemoryCachedKernel.
Reimplemented in PLearn::ARDBaseKernel, PLearn::IIDNoiseKernel, PLearn::LinearARDKernel, PLearn::Matern1ARDKernel, PLearn::NeuralNetworkARDKernel, PLearn::PLearnerDiagonalKernel, PLearn::RationalQuadraticARDKernel, and PLearn::SquaredExponentialARDKernel.
Definition at line 195 of file KroneckerBaseKernel.cc.
References PLearn::deepCopyField(), m_kronecker_indexes, and PLearn::MemoryCachedKernel::makeDeepCopyFromShallowCopy().
Referenced by PLearn::PLearnerDiagonalKernel::makeDeepCopyFromShallowCopy(), PLearn::IIDNoiseKernel::makeDeepCopyFromShallowCopy(), and PLearn::ARDBaseKernel::makeDeepCopyFromShallowCopy().
{ inherited::makeDeepCopyFromShallowCopy(copies); deepCopyField(m_kronecker_indexes, copies); }
real PLearn::KroneckerBaseKernel::softplusFloor | ( | real & | value, |
real | floor = 1e-6 |
||
) | [static, protected] |
Utility function for derived classes: return the softplus of its argument, but if the softplus would fall below the given floor, then return the floor AND MODIFY the original argument to represent the inverse softplus of the floor.
This allows preventing some variables from getting too small during optimization.
Definition at line 182 of file KroneckerBaseKernel.cc.
References PLearn::exp(), pl_log, and PLearn::softplus().
Referenced by PLearn::Matern1ARDKernel::computeGramMatrix(), and PLearn::RationalQuadraticARDKernel::computeGramMatrix().
{ real sp = softplus(value); if (sp < floor) { value = pl_log(exp(floor)-1); // inverse soft-plus return floor; } return sp; }
Reimplemented from PLearn::MemoryCachedKernel.
Reimplemented in PLearn::ARDBaseKernel, PLearn::IIDNoiseKernel, PLearn::LinearARDKernel, PLearn::Matern1ARDKernel, PLearn::NeuralNetworkARDKernel, PLearn::PLearnerDiagonalKernel, PLearn::RationalQuadraticARDKernel, and PLearn::SquaredExponentialARDKernel.
Definition at line 103 of file KroneckerBaseKernel.h.
real PLearn::KroneckerBaseKernel::m_default_value [mutable, protected] |
Value to be used for kernel evaluation if there are no kronecker terms.
This is initialized to zero. A derived class may set it to (e.g.) 1.0 be be sure that the default value is filled to something that can be used multiplicatively, even when there are no Kronecker terms.
Definition at line 118 of file KroneckerBaseKernel.h.
Referenced by PLearn::Matern1ARDKernel::build_(), PLearn::RationalQuadraticARDKernel::build_(), PLearn::PLearnerDiagonalKernel::build_(), computeGramMatrix(), and evaluate().
Element index in the input vectors that should be subject to additional Kronecker delta terms.
Definition at line 81 of file KroneckerBaseKernel.h.
Referenced by computeGramMatrix(), PLearn::IIDNoiseKernel::computeGramMatrix(), declareOptions(), evaluate(), and makeDeepCopyFromShallowCopy().