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::KroneckerBaseKernel Class Reference

Base class for kernels that make use of Kronecker terms. More...

#include <KroneckerBaseKernel.h>

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

List of all members.

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 OptionListgetOptionList () const
virtual OptionMapgetOptionMap () const
virtual RemoteMethodMapgetRemoteMethodMap () const
virtual KroneckerBaseKerneldeepCopy (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 PPathdeclaringFile ()

Public Attributes

TVec< intm_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.

Detailed Description

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:

$ k(x,y) = \product_i delta_x[kr(i)],y[kr(i)] $

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.


Member Typedef Documentation


Constructor & Destructor Documentation

PLearn::KroneckerBaseKernel::KroneckerBaseKernel ( )

Default constructor.

Definition at line 73 of file KroneckerBaseKernel.cc.

    : m_default_value(0.)
{ }

Member Function Documentation

string PLearn::KroneckerBaseKernel::_classname_ ( ) [static]
OptionList & PLearn::KroneckerBaseKernel::_getOptionList_ ( ) [static]
RemoteMethodMap & PLearn::KroneckerBaseKernel::_getRemoteMethodMap_ ( ) [static]
bool PLearn::KroneckerBaseKernel::_isa_ ( const Object o) [static]
Object * PLearn::KroneckerBaseKernel::_new_instance_for_typemap_ ( ) [static]
StaticInitializer KroneckerBaseKernel::_static_initializer_ & PLearn::KroneckerBaseKernel::_static_initialize_ ( ) [static]
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_();
}

Here is the call graph for this function:

Here is the caller graph for this function:

void PLearn::KroneckerBaseKernel::build_ ( ) [private]
string PLearn::KroneckerBaseKernel::classname ( ) const [virtual]
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;
        }
    }
}

Here is the call graph for this function:

Here is the caller graph for this function:

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

Here is the call graph for this function:

Here is the caller graph for this function:

static const PPath& PLearn::KroneckerBaseKernel::declaringFile ( ) [inline, static]
KroneckerBaseKernel * PLearn::KroneckerBaseKernel::deepCopy ( CopiesMap copies) const [virtual]
real PLearn::KroneckerBaseKernel::evaluate ( const Vec x1,
const Vec x2 
) const [virtual]
OptionList & PLearn::KroneckerBaseKernel::getOptionList ( ) const [virtual]
OptionMap & PLearn::KroneckerBaseKernel::getOptionMap ( ) const [virtual]
RemoteMethodMap & PLearn::KroneckerBaseKernel::getRemoteMethodMap ( ) const [virtual]
void PLearn::KroneckerBaseKernel::makeDeepCopyFromShallowCopy ( CopiesMap copies) [virtual]
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;
}

Here is the call graph for this function:

Here is the caller graph for this function:


Member Data Documentation

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


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