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

Kernel representing independent and identically-distributed observation noise. More...

#include <IIDNoiseKernel.h>

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

List of all members.

Public Member Functions

 IIDNoiseKernel ()
 Default constructor.
virtual real evaluate (const Vec &x1, const Vec &x2) const
 Compute K(x1,x2). This DOES include noise if x1 == x2.
virtual real evaluate_i_x (int i, const Vec &x, real) const
 Always zero by independence.
virtual void evaluate_all_i_x (const Vec &x, const Vec &k_xi_x, real squared_norm_of_x=-1, int istart=0) const
 Fill k_xi_x with K(x_i, x), for all i from istart to istart + k_xi_x.length() - 1.
virtual void computeGramMatrix (Mat K) const
 Compute the Gram Matrix.
virtual void computeGramMatrixDerivative (Mat &KD, const string &kernel_param, real epsilon=1e-6) const
 Directly compute the derivative with respect to hyperparameters (Faster than finite differences...)
virtual string classname () const
virtual OptionListgetOptionList () const
virtual OptionMapgetOptionMap () const
virtual RemoteMethodMapgetRemoteMethodMap () const
virtual IIDNoiseKerneldeepCopy (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

real m_isp_noise_sigma
 Inverse softplus of the global noise variance.
real m_isp_kronecker_sigma
 Inverse softplus of the noise variance term for the product of Kronecker deltas associated with kronecker_indexes, if specified.

Static Public Attributes

static StaticInitializer _static_initializer_

Protected Member Functions

void computeGramMatrixDerivKronecker (Mat &KD) const
 Compute the derivative of the Gram matrix with respect to the Kronecker sigma.

Static Protected Member Functions

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

Private Types

typedef KroneckerBaseKernel inherited

Private Member Functions

void build_ ()
 This does the actual building.

Detailed Description

Kernel representing independent and identically-distributed observation noise.

This Kernel is typically used as a base class for covariance functions used in gaussian processes (see GaussianProcessRegressor). It represents simple i.i.d. additive noise that applies to 'identical training cases' i and j:

k(D_i,D_j) = delta_i,j * sn

where D_i and D_j are elements from the current data set (established by the setDataForKernelMatrix function), delta_i,j is the Kronecker delta function, and sn is softplus(isp_noise_sigma), with softplus(x) = log(1+exp(x)). Note that 'identity' is not equivalent to 'vector equality': in particular, at test-time, this noise is NEVER added. Currently, two vectors are considered identical if and only if they are the SAME ROW of the current data set, and hence the noise term is added only at TRAIN-TIME across the diagonal of the Gram matrix (when the computeGramMatrix() function is called). This is why at test-time, no such noise term is added. The idea (see the book "Gaussian Processes for Machine Learning" by Rasmussen and Williams for details) is that observation noise only applies when A SPECIFIC OBSERVATION is drawn from the GP distribution: if we sample a new point at the same x, we will get a different realization for the noise, and hence the correlation between the two noise realizations is zero. This class can only be sure that two observations are "identical" when they are presented all at once through the data matrix.

The Kronecker terms computed by the base class are ADDDED to the noise computed by this kernel (at test-time also).

Definition at line 77 of file IIDNoiseKernel.h.


Member Typedef Documentation

Reimplemented from PLearn::KroneckerBaseKernel.

Definition at line 79 of file IIDNoiseKernel.h.


Constructor & Destructor Documentation

PLearn::IIDNoiseKernel::IIDNoiseKernel ( )

Default constructor.

Definition at line 78 of file IIDNoiseKernel.cc.

    : m_isp_noise_sigma(-100.0), /* very close to zero... */
      m_isp_kronecker_sigma(-100.0)
{ }

Member Function Documentation

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

Reimplemented from PLearn::KroneckerBaseKernel.

Definition at line 75 of file IIDNoiseKernel.cc.

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

Reimplemented from PLearn::KroneckerBaseKernel.

Definition at line 75 of file IIDNoiseKernel.cc.

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

Reimplemented from PLearn::KroneckerBaseKernel.

Definition at line 75 of file IIDNoiseKernel.cc.

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

Reimplemented from PLearn::KroneckerBaseKernel.

Definition at line 75 of file IIDNoiseKernel.cc.

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

Reimplemented from PLearn::KroneckerBaseKernel.

Definition at line 75 of file IIDNoiseKernel.cc.

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

Reimplemented from PLearn::KroneckerBaseKernel.

Definition at line 75 of file IIDNoiseKernel.cc.

void PLearn::IIDNoiseKernel::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::KroneckerBaseKernel.

Definition at line 107 of file IIDNoiseKernel.cc.

References PLearn::KroneckerBaseKernel::build(), and build_().

{
    // ### Nothing to add here, simply calls build_
    inherited::build();
    build_();
}

Here is the call graph for this function:

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

This does the actual building.

Reimplemented from PLearn::KroneckerBaseKernel.

Definition at line 117 of file IIDNoiseKernel.cc.

Referenced by build().

{ }

Here is the caller graph for this function:

string PLearn::IIDNoiseKernel::classname ( ) const [virtual]

Reimplemented from PLearn::KroneckerBaseKernel.

Definition at line 75 of file IIDNoiseKernel.cc.

void PLearn::IIDNoiseKernel::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::KroneckerBaseKernel.

Definition at line 164 of file IIDNoiseKernel.cc.

References PLearn::Kernel::cache_gram_matrix, PLearn::KroneckerBaseKernel::computeGramMatrix(), PLearn::Kernel::data, PLearn::Kernel::gram_matrix, PLearn::Kernel::gram_matrix_is_cached, i, PLearn::Kernel::is_symmetric, PLearn::VMat::length(), PLearn::TMat< T >::length(), m, m_isp_kronecker_sigma, m_isp_noise_sigma, PLearn::KroneckerBaseKernel::m_kronecker_indexes, PLearn::TMat< T >::mod(), PLERROR, PLearn::TMat< T >::resize(), PLearn::TVec< T >::size(), PLearn::softplus(), and PLearn::TMat< T >::width().

{
    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());
                
    // Compute Kronecker gram matrix. Multiply by kronecker sigma if there were
    // any Kronecker terms.
    inherited::computeGramMatrix(K);
    if (m_kronecker_indexes.size() > 0)
        K *= softplus(m_isp_kronecker_sigma);
    
    // Add iid noise contribution
    real noise_sigma = softplus(m_isp_noise_sigma);
    int  l   = data->length();
    int  m   = K.mod() + 1;               // Mind the +1 to go along diagonal
    real *Ki = K[0];
    
    for (int i=0 ; i<l ; ++i, Ki += m) {
        *Ki += noise_sigma;
    }

    if (cache_gram_matrix) {
        gram_matrix.resize(l,l);
        gram_matrix << K;
        gram_matrix_is_cached = true;
    }
}

Here is the call graph for this function:

void PLearn::IIDNoiseKernel::computeGramMatrixDerivative ( Mat KD,
const string &  kernel_param,
real  epsilon = 1e-6 
) const [virtual]

Directly compute the derivative with respect to hyperparameters (Faster than finite differences...)

Reimplemented from PLearn::Kernel.

Definition at line 209 of file IIDNoiseKernel.cc.

References PLearn::Kernel::computeGramMatrixDerivative(), computeGramMatrixDerivKronecker(), PLearn::Kernel::data, PLearn::TMat< T >::fill(), i, m_isp_noise_sigma, PLearn::Kernel::nExamples(), PLERROR, PLearn::TMat< T >::resize(), and PLearn::sigmoid().

{
    static const string INS("isp_noise_sigma");
    static const string IKS("isp_kronecker_sigma");

    if (kernel_param == INS) {
        if (!data)
            PLERROR("Kernel::computeGramMatrixDerivative should be called only after "
                    "setDataForKernelMatrix");

        int W = nExamples();
        KD.resize(W,W);
        KD.fill(0.0);
        real deriv = sigmoid(m_isp_noise_sigma);
        for (int i=0 ; i<W ; ++i)
            KD(i,i) = deriv;
    }
    else if (kernel_param == IKS) {
        computeGramMatrixDerivKronecker(KD);
    }
    else
        inherited::computeGramMatrixDerivative(KD, kernel_param, epsilon);
}

Here is the call graph for this function:

void PLearn::IIDNoiseKernel::computeGramMatrixDerivKronecker ( Mat KD) const [protected]

Compute the derivative of the Gram matrix with respect to the Kronecker sigma.

Definition at line 237 of file IIDNoiseKernel.cc.

References PLearn::Kernel::data, PLearn::Kernel::gram_matrix, i, PLearn::TMat< T >::length(), PLearn::VMat::length(), m_isp_kronecker_sigma, m_isp_noise_sigma, PLASSERT_MSG, PLearn::TMat< T >::resize(), PLearn::sigmoid(), PLearn::softplus(), and PLearn::TMat< T >::width().

Referenced by computeGramMatrixDerivative().

{
    // From the cached version of the Gram matrix, this function is easily
    // implemented: we first copy the Gram to the KD matrix, subtract the IID
    // noise contribution from the main diagonal, and multiply the remaining
    // matrix (made up of 0/1 elements) by the derivative of the kronecker
    // sigma hyperparameter.

    int l = data->length();
    KD.resize(l,l);
    PLASSERT_MSG(gram_matrix.width() == l && gram_matrix.length() == l,
                 "To compute the derivative with respect to 'isp_kronecker_sigma',\n"
                 "the Gram matrix must be precomputed and cached in IIDNoiseKernel.");
    
    KD << gram_matrix;
    real noise_sigma = softplus(m_isp_noise_sigma);
    for (int i=0 ; i<l ; ++i)
        KD(i,i) -= noise_sigma;

    KD *= sigmoid(m_isp_kronecker_sigma) / softplus(m_isp_kronecker_sigma);
}

Here is the call graph for this function:

Here is the caller graph for this function:

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

Declares the class options.

Reimplemented from PLearn::KroneckerBaseKernel.

Definition at line 86 of file IIDNoiseKernel.cc.

References PLearn::OptionBase::buildoption, PLearn::declareOption(), PLearn::KroneckerBaseKernel::declareOptions(), m_isp_kronecker_sigma, and m_isp_noise_sigma.

{
    declareOption(
        ol, "isp_noise_sigma", &IIDNoiseKernel::m_isp_noise_sigma,
        OptionBase::buildoption,
        "Inverse softplus of the global noise variance.  Default value=-100.0\n"
        "(very close to zero after we take softplus).");

    declareOption(
        ol, "isp_kronecker_sigma", &IIDNoiseKernel::m_isp_kronecker_sigma,
        OptionBase::buildoption,
        "Inverse softplus of the noise variance term for the product of\n"
        "Kronecker deltas associated with kronecker_indexes, if specified.");
    
    // Now call the parent class' declareOptions
    inherited::declareOptions(ol);
}

Here is the call graph for this function:

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

Reimplemented from PLearn::KroneckerBaseKernel.

Definition at line 124 of file IIDNoiseKernel.h.

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

Reimplemented from PLearn::KroneckerBaseKernel.

Definition at line 75 of file IIDNoiseKernel.cc.

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

Compute K(x1,x2). This DOES include noise if x1 == x2.

Reimplemented from PLearn::KroneckerBaseKernel.

Definition at line 123 of file IIDNoiseKernel.cc.

References PLearn::KroneckerBaseKernel::evaluate(), m_isp_kronecker_sigma, m_isp_noise_sigma, and PLearn::softplus().

{
    // Assume that if x1 and x2 are identical, they are actually the same
    // instance of a data point.  This should not be called to compare a train
    // point against a test point (use evaluate_i_x for this purpose).
    return (x1 == x2? softplus(m_isp_noise_sigma) : 0.0) +
        softplus(m_isp_kronecker_sigma) * inherited::evaluate(x1,x2);
}

Here is the call graph for this function:

void PLearn::IIDNoiseKernel::evaluate_all_i_x ( const Vec x,
const Vec k_xi_x,
real  squared_norm_of_x = -1,
int  istart = 0 
) const [virtual]

Fill k_xi_x with K(x_i, x), for all i from istart to istart + k_xi_x.length() - 1.

Reimplemented from PLearn::Kernel.

Definition at line 147 of file IIDNoiseKernel.cc.

References PLearn::Kernel::data, PLearn::MemoryCachedKernel::dataRow(), PLearn::KroneckerBaseKernel::evaluate(), PLearn::TVec< T >::fill(), i, j, PLearn::VMat::length(), m_isp_kronecker_sigma, PLearn::min(), PLearn::TVec< T >::size(), and PLearn::softplus().

{
    // Noise component is ZERO between a test and any train example
    k_xi_x.fill(0.0);
    real kronecker_sigma = softplus(m_isp_kronecker_sigma);
    int i_max = min(istart + k_xi_x.size(), data->length());
    int j = 0;
    for (int i=istart ; i<i_max ; ++i, ++j) {
        Vec* train_row = dataRow(i);
        k_xi_x[j] = kronecker_sigma * inherited::evaluate(*train_row, x);
    }
}

Here is the call graph for this function:

real PLearn::IIDNoiseKernel::evaluate_i_x ( int  i,
const Vec x,
real   
) const [virtual]

Always zero by independence.

Reimplemented from PLearn::Kernel.

Definition at line 135 of file IIDNoiseKernel.cc.

References PLearn::MemoryCachedKernel::dataRow(), PLearn::KroneckerBaseKernel::evaluate(), m_isp_kronecker_sigma, PLASSERT, and PLearn::softplus().

{
    // Noise component is ZERO between a test and any train example.
    // Just compute the Kronecker part is not necessarily zero
    Vec* train_row = dataRow(i);
    PLASSERT( train_row );
    return softplus(m_isp_kronecker_sigma) * inherited::evaluate(*train_row, x);
}

Here is the call graph for this function:

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

Reimplemented from PLearn::KroneckerBaseKernel.

Definition at line 75 of file IIDNoiseKernel.cc.

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

Reimplemented from PLearn::KroneckerBaseKernel.

Definition at line 75 of file IIDNoiseKernel.cc.

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

Reimplemented from PLearn::KroneckerBaseKernel.

Definition at line 75 of file IIDNoiseKernel.cc.

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

Transforms a shallow copy into a deep copy.

Reimplemented from PLearn::KroneckerBaseKernel.

Definition at line 201 of file IIDNoiseKernel.cc.

References PLearn::KroneckerBaseKernel::makeDeepCopyFromShallowCopy().

Here is the call graph for this function:


Member Data Documentation

Reimplemented from PLearn::KroneckerBaseKernel.

Definition at line 124 of file IIDNoiseKernel.h.

Inverse softplus of the noise variance term for the product of Kronecker deltas associated with kronecker_indexes, if specified.

Definition at line 90 of file IIDNoiseKernel.h.

Referenced by computeGramMatrix(), computeGramMatrixDerivKronecker(), declareOptions(), evaluate(), evaluate_all_i_x(), and evaluate_i_x().

Inverse softplus of the global noise variance.

Default value=-100.0 (very close to zero after we take softplus).

Definition at line 86 of file IIDNoiseKernel.h.

Referenced by computeGramMatrix(), computeGramMatrixDerivative(), computeGramMatrixDerivKronecker(), declareOptions(), and evaluate().


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