|
PLearn 0.1
|
Diagonal kernel from the output of a PLearner. More...
#include <PLearnerDiagonalKernel.h>


Public Member Functions | |
| PLearnerDiagonalKernel () | |
| 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 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 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 string | classname () const |
| virtual OptionList & | getOptionList () const |
| virtual OptionMap & | getOptionMap () const |
| virtual RemoteMethodMap & | getRemoteMethodMap () const |
| virtual PLearnerDiagonalKernel * | 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 | |
| PP< PLearner > | m_learner |
| Learner we are taking output from. | |
| real | m_isp_signal_sigma |
| Inverse softplus of the global noise variance. Default value = 0.0. | |
Static Public Attributes | |
| static StaticInitializer | _static_initializer_ |
Protected Member Functions | |
| void | computeGramMatrixDerivIspSignalSigma (Mat &KD) const |
| Compute derivative w.r.t. isp_signal_sigma for WHOLE MATRIX. | |
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. | |
Private Attributes | |
| Vec | m_output_buffer |
| Buffer for evaluation of computeOutput. | |
Diagonal kernel from the output of a PLearner.
The output of this kernel is given by:
k(x,x) = isp_signal_sigma * exp(learner->computeOutput(x))
and is 0 for x != y.
This is useful for representing heteroscedastic noise in Gaussian Processes, where the log-noise process is the output of another learner (e.g. another Gaussian Process).
Definition at line 61 of file PLearnerDiagonalKernel.h.
typedef KroneckerBaseKernel PLearn::PLearnerDiagonalKernel::inherited [private] |
Reimplemented from PLearn::KroneckerBaseKernel.
Definition at line 63 of file PLearnerDiagonalKernel.h.
| PLearn::PLearnerDiagonalKernel::PLearnerDiagonalKernel | ( | ) |
Default constructor.
Definition at line 61 of file PLearnerDiagonalKernel.cc.
: m_isp_signal_sigma(0.) { }
| string PLearn::PLearnerDiagonalKernel::_classname_ | ( | ) | [static] |
Reimplemented from PLearn::KroneckerBaseKernel.
Definition at line 58 of file PLearnerDiagonalKernel.cc.
| OptionList & PLearn::PLearnerDiagonalKernel::_getOptionList_ | ( | ) | [static] |
Reimplemented from PLearn::KroneckerBaseKernel.
Definition at line 58 of file PLearnerDiagonalKernel.cc.
| RemoteMethodMap & PLearn::PLearnerDiagonalKernel::_getRemoteMethodMap_ | ( | ) | [static] |
Reimplemented from PLearn::KroneckerBaseKernel.
Definition at line 58 of file PLearnerDiagonalKernel.cc.
Reimplemented from PLearn::KroneckerBaseKernel.
Definition at line 58 of file PLearnerDiagonalKernel.cc.
| Object * PLearn::PLearnerDiagonalKernel::_new_instance_for_typemap_ | ( | ) | [static] |
Reimplemented from PLearn::KroneckerBaseKernel.
Definition at line 58 of file PLearnerDiagonalKernel.cc.
| StaticInitializer PLearnerDiagonalKernel::_static_initializer_ & PLearn::PLearnerDiagonalKernel::_static_initialize_ | ( | ) | [static] |
Reimplemented from PLearn::KroneckerBaseKernel.
Definition at line 58 of file PLearnerDiagonalKernel.cc.
| void PLearn::PLearnerDiagonalKernel::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 89 of file PLearnerDiagonalKernel.cc.
References PLearn::KroneckerBaseKernel::build(), and build_().
{
// ### Nothing to add here, simply calls build_
inherited::build();
build_();
}

| void PLearn::PLearnerDiagonalKernel::build_ | ( | ) | [private] |
This does the actual building.
Reimplemented from PLearn::KroneckerBaseKernel.
Definition at line 99 of file PLearnerDiagonalKernel.cc.
References PLearn::PP< T >::isNull(), PLearn::KroneckerBaseKernel::m_default_value, m_learner, and PLERROR.
Referenced by build().
{
if (m_learner.isNull())
PLERROR("PLearnerDiagonalKernel::build: the option 'learner' must be specified");
// At build-time, we don't yet know the learner outputsize
// if (m_learner->outputsize() != 1)
// PLERROR("PLearnerDiagonalKernel::build: the learner must have an outputsize of 1; "
// "current outputsize is %d", m_learner->outputsize());
// Ensure that we multiply in Kronecker terms
inherited::m_default_value = 1.0;
}


| string PLearn::PLearnerDiagonalKernel::classname | ( | ) | const [virtual] |
Reimplemented from PLearn::KroneckerBaseKernel.
Definition at line 58 of file PLearnerDiagonalKernel.cc.
| void PLearn::PLearnerDiagonalKernel::computeGramMatrix | ( | Mat | K | ) | const [virtual] |
Compute the Gram Matrix.
Reimplemented from PLearn::KroneckerBaseKernel.
Definition at line 137 of file PLearnerDiagonalKernel.cc.
References PLearn::Kernel::cache_gram_matrix, PLearn::Kernel::evaluate_i_j(), PLearn::exp(), PLearn::TMat< T >::fill(), PLearn::Kernel::gram_matrix, PLearn::Kernel::gram_matrix_is_cached, i, PLearn::PP< T >::isNull(), PLearn::TMat< T >::length(), PLearn::MemoryCachedKernel::m_data_cache, m_isp_signal_sigma, m_learner, m_output_buffer, n, PLASSERT, PLearn::TMat< T >::resize(), PLearn::TVec< T >::resize(), PLearn::TMat< T >::size(), PLearn::softplus(), and PLearn::TMat< T >::width().
{
PLASSERT( K.size() == 0 || m_data_cache.size() > 0 ); // Ensure data cached OK
PLASSERT( ! m_learner.isNull() && m_learner->outputsize() == 1);
m_output_buffer.resize(m_learner->outputsize());
// Most elements are zero, except for the diagonal
K.fill(0.0);
real sigma = softplus(m_isp_signal_sigma);
int n = m_data_cache.length();
PLASSERT( K.length() == n && K.width() == n );
for (int i=0 ; i<n ; ++i) {
real gating_term = inherited::evaluate_i_j(i, i);
Vec input_i = m_data_cache(i);
m_learner->computeOutput(input_i, m_output_buffer);
real diag_term = exp(m_output_buffer[0]);
K(i,i) = sigma * gating_term * diag_term;
}
if (cache_gram_matrix) {
gram_matrix.resize(n,n);
gram_matrix << K;
gram_matrix_is_cached = true;
}
}

| void PLearn::PLearnerDiagonalKernel::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 170 of file PLearnerDiagonalKernel.cc.
References PLearn::Kernel::computeGramMatrixDerivative(), and computeGramMatrixDerivIspSignalSigma().
{
static const string ISS("isp_signal_sigma");
if (kernel_param == ISS) {
computeGramMatrixDerivIspSignalSigma(KD);
// computeGramMatrixDerivNV<
// PLearnerDiagonalKernel,
// &PLearnerDiagonalKernel::derivIspSignalSigma>(KD, this, -1);
}
else
inherited::computeGramMatrixDerivative(KD, kernel_param, epsilon);
}

| void PLearn::PLearnerDiagonalKernel::computeGramMatrixDerivIspSignalSigma | ( | Mat & | KD | ) | const [protected] |
Compute derivative w.r.t. isp_signal_sigma for WHOLE MATRIX.
Definition at line 198 of file PLearnerDiagonalKernel.cc.
References PLearn::Kernel::data, PLearn::Kernel::gram_matrix, PLearn::TMat< T >::length(), PLearn::VMat::length(), m_isp_signal_sigma, PLASSERT_MSG, PLearn::TMat< T >::resize(), PLearn::sigmoid(), PLearn::softplus(), and PLearn::TMat< T >::width().
Referenced by computeGramMatrixDerivative().
{
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_signal_sigma', the\n"
"Gram matrix must be precomputed and cached in PLearnerDiagonalKernel.");
KD << gram_matrix;
KD *= sigmoid(m_isp_signal_sigma)/softplus(m_isp_signal_sigma);
}


| void PLearn::PLearnerDiagonalKernel::declareOptions | ( | OptionList & | ol | ) | [static, protected] |
Declares the class options.
Reimplemented from PLearn::KroneckerBaseKernel.
Definition at line 68 of file PLearnerDiagonalKernel.cc.
References PLearn::OptionBase::buildoption, PLearn::declareOption(), PLearn::KroneckerBaseKernel::declareOptions(), m_isp_signal_sigma, and m_learner.
{
declareOption(
ol, "learner",
&PLearnerDiagonalKernel::m_learner,
OptionBase::buildoption,
"Learner we are taking output from.");
declareOption(
ol, "isp_signal_sigma",
&PLearnerDiagonalKernel::m_isp_signal_sigma,
OptionBase::buildoption,
"Inverse softplus of the global noise variance. Default value = 0.0.");
// Now call the parent class' declareOptions
inherited::declareOptions(ol);
}

| static const PPath& PLearn::PLearnerDiagonalKernel::declaringFile | ( | ) | [inline, static] |
Reimplemented from PLearn::KroneckerBaseKernel.
Definition at line 102 of file PLearnerDiagonalKernel.h.
:
| PLearnerDiagonalKernel * PLearn::PLearnerDiagonalKernel::deepCopy | ( | CopiesMap & | copies | ) | const [virtual] |
Reimplemented from PLearn::KroneckerBaseKernel.
Definition at line 58 of file PLearnerDiagonalKernel.cc.
Compute K(x1,x2).
Reimplemented from PLearn::KroneckerBaseKernel.
Definition at line 116 of file PLearnerDiagonalKernel.cc.
References PLearn::KroneckerBaseKernel::evaluate(), PLearn::exp(), PLearn::PP< T >::isNull(), m_isp_signal_sigma, m_learner, m_output_buffer, PLASSERT, PLearn::TVec< T >::resize(), PLearn::TVec< T >::size(), and PLearn::softplus().
{
PLASSERT( x1.size() == x2.size() );
PLASSERT( ! m_learner.isNull() && m_learner->outputsize() == 1);
m_output_buffer.resize(m_learner->outputsize());
if (x1 == x2) {
real gating_term = inherited::evaluate(x1,x2);
real sigma = softplus(m_isp_signal_sigma);
m_learner->computeOutput(x1, m_output_buffer);
real diag_term = exp(m_output_buffer[0]);
return sigma * gating_term * diag_term;
}
else
return 0.0;
}

| void PLearn::PLearnerDiagonalKernel::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 189 of file PLearnerDiagonalKernel.cc.
References PLearn::Kernel::k_xi_x, and x.
| OptionList & PLearn::PLearnerDiagonalKernel::getOptionList | ( | ) | const [virtual] |
Reimplemented from PLearn::KroneckerBaseKernel.
Definition at line 58 of file PLearnerDiagonalKernel.cc.
| OptionMap & PLearn::PLearnerDiagonalKernel::getOptionMap | ( | ) | const [virtual] |
Reimplemented from PLearn::KroneckerBaseKernel.
Definition at line 58 of file PLearnerDiagonalKernel.cc.
| RemoteMethodMap & PLearn::PLearnerDiagonalKernel::getRemoteMethodMap | ( | ) | const [virtual] |
Reimplemented from PLearn::KroneckerBaseKernel.
Definition at line 58 of file PLearnerDiagonalKernel.cc.
| void PLearn::PLearnerDiagonalKernel::makeDeepCopyFromShallowCopy | ( | CopiesMap & | copies | ) | [virtual] |
Transforms a shallow copy into a deep copy.
Reimplemented from PLearn::KroneckerBaseKernel.
Definition at line 213 of file PLearnerDiagonalKernel.cc.
References PLearn::deepCopyField(), m_learner, m_output_buffer, and PLearn::KroneckerBaseKernel::makeDeepCopyFromShallowCopy().
{
deepCopyField(m_learner, copies);
deepCopyField(m_output_buffer, copies);
inherited::makeDeepCopyFromShallowCopy(copies);
}

Reimplemented from PLearn::KroneckerBaseKernel.
Definition at line 102 of file PLearnerDiagonalKernel.h.
Inverse softplus of the global noise variance. Default value = 0.0.
Definition at line 72 of file PLearnerDiagonalKernel.h.
Referenced by computeGramMatrix(), computeGramMatrixDerivIspSignalSigma(), declareOptions(), and evaluate().
Learner we are taking output from.
Definition at line 69 of file PLearnerDiagonalKernel.h.
Referenced by build_(), computeGramMatrix(), declareOptions(), evaluate(), and makeDeepCopyFromShallowCopy().
Vec PLearn::PLearnerDiagonalKernel::m_output_buffer [mutable, private] |
Buffer for evaluation of computeOutput.
Definition at line 123 of file PLearnerDiagonalKernel.h.
Referenced by computeGramMatrix(), evaluate(), and makeDeepCopyFromShallowCopy().
1.7.4