shark::GaussianTaskKernel< InputTypeT > Class Template Reference

Special "Gaussian-like" kernel function on tasks. More...

#include <shark/Models/Kernels/MultiTaskKernel.h>

+ Inheritance diagram for shark::GaussianTaskKernel< InputTypeT >:

Public Types

typedef InputTypeT InputType
 
typedef MultiTaskSample< InputTypeMultiTaskSampleType
 
typedef AbstractKernelFunction< InputTypeKernelType
 
- Public Types inherited from shark::AbstractKernelFunction< std::size_t >
enum  Feature
 enumerations of kerneland metric features (flags) More...
 
typedef base_type::InputType InputType
 Input type of the Kernel. More...
 
typedef base_type::BatchInputType BatchInputType
 batch input type of the kernel More...
 
typedef base_type::ConstInputReference ConstInputReference
 Const references to InputType. More...
 
typedef base_type::ConstBatchInputReference ConstBatchInputReference
 Const references to BatchInputType. More...
 
typedef TypedFlags< FeatureFeatures
 This statement declares the member m_features. See Core/Flags.h for details. More...
 
typedef TypedFeatureNotAvailableException< FeatureFeatureNotAvailableException
 
- Public Types inherited from shark::AbstractMetric< std::size_t >
typedef std::size_t InputType
 Input type of the Kernel. More...
 
typedef Batch< std::size_t >::type BatchInputType
 batch input type of the kernel More...
 
typedef ConstProxyReference< InputType const >::type ConstInputReference
 Const references to InputType. More...
 
typedef ConstProxyReference< BatchInputType const >::type ConstBatchInputReference
 Const references to BatchInputType. More...
 
- Public Types inherited from shark::IParameterizable<>
typedef RealVector ParameterVectorType
 

Public Member Functions

 GaussianTaskKernel (Data< MultiTaskSampleType > const &data, std::size_t tasks, KernelType &inputkernel, double gamma)
 Construction of a Gaussian kernel on tasks. More...
 
std::string name () const
 From INameable: return the class name. More...
 
RealVector parameterVector () const
 Return the parameter vector. More...
 
void setParameterVector (RealVector const &newParameters)
 Set the parameter vector. More...
 
std::size_t numberOfParameters () const
 Return the number of parameters. More...
 
std::size_t numberOfTasks () const
 
double gamma () const
 Kernel bandwidth parameter. More...
 
double sigma () const
 Kernel width parameter, equivalent to the bandwidth parameter. More...
 
void setGamma (double gamma)
 
void setWidth (double sigma)
 Set the kernel width (equivalent to setting the bandwidth). More...
 
void read (InArchive &ar)
 From ISerializable. More...
 
void write (OutArchive &ar) const
 From ISerializable. More...
 
- Public Member Functions inherited from shark::DiscreteKernel
 DiscreteKernel (RealMatrix const &matrix)
 Construction of the kernel from a positive definite, symmetric matrix. More...
 
std::size_t size () const
 Cardinality of the discrete space. More...
 
boost::shared_ptr< StatecreateState () const
 DiscreteKernels don't have a state so they return an EmptyState object. More...
 
double eval (ConstInputReference x1, ConstInputReference x2) const
 Evaluates the kernel function. More...
 
void eval (ConstBatchInputReference batchX1, ConstBatchInputReference batchX2, RealMatrix &result, State &state) const
 Evaluates the kernel function for every point combination of the two batches. More...
 
void eval (ConstBatchInputReference batchX1, ConstBatchInputReference batchX2, RealMatrix &result) const
 Evaluates the kernel function for every point combination of the two batches. More...
 
- Public Member Functions inherited from shark::AbstractKernelFunction< std::size_t >
 AbstractKernelFunction ()
 
const Featuresfeatures () const
 
virtual void updateFeatures ()
 
bool hasFirstParameterDerivative () const
 
bool hasFirstInputDerivative () const
 
bool isNormalized () const
 
bool supportsVariableInputSize () const
 
double operator() (ConstInputReference x1, ConstInputReference x2) const
 Convenience operator which evaluates the kernel function. More...
 
RealMatrix operator() (ConstBatchInputReference batchX1, ConstBatchInputReference batchX2) const
 Evaluates the subset of the KernelGram matrix which is defined by X1(rows) and X2 (columns). More...
 
virtual void weightedParameterDerivative (ConstBatchInputReference batchX1, ConstBatchInputReference batchX2, RealMatrix const &coefficients, State const &state, RealVector &gradient) const
 Computes the gradient of the parameters as a weighted sum over the gradient of all elements of the batch. More...
 
virtual void weightedInputDerivative (ConstBatchInputReference batchX1, ConstBatchInputReference batchX2, RealMatrix const &coefficientsX2, State const &state, BatchInputType &gradient) const
 Calculates the derivative of the inputs X1 (only x1!). More...
 
virtual double featureDistanceSqr (ConstInputReference x1, ConstInputReference x2) const
 Computes the squared distance in the kernel induced feature space. More...
 
virtual RealMatrix featureDistanceSqr (ConstBatchInputReference batchX1, ConstBatchInputReference batchX2) const
 Computes the squared distance in the kernel induced feature space. More...
 
- Public Member Functions inherited from shark::AbstractMetric< std::size_t >
 AbstractMetric ()
 
virtual ~AbstractMetric ()
 
virtual double featureDistanceSqr (ConstInputReference x1, ConstInputReference x2) const=0
 Computes the squared distance in the kernel induced feature space. More...
 
virtual RealMatrix featureDistanceSqr (ConstBatchInputReference batchX1, ConstBatchInputReference batchX2) const=0
 
double featureDistance (ConstInputReference x1, ConstInputReference x2) const
 Computes the distance in the kernel induced feature space. More...
 
- Public Member Functions inherited from shark::INameable
virtual ~INameable ()
 
- Public Member Functions inherited from shark::IParameterizable<>
virtual ~IParameterizable ()
 
- Public Member Functions inherited from shark::ISerializable
virtual ~ISerializable ()
 Virtual d'tor. More...
 
void load (InArchive &archive, unsigned int version)
 Versioned loading of components, calls read(...). More...
 
void save (OutArchive &archive, unsigned int version) const
 Versioned storing of components, calls write(...). More...
 
 BOOST_SERIALIZATION_SPLIT_MEMBER ()
 

Protected Member Functions

void computeMatrix ()
 Compute the Gram matrix of the task kernel. More...
 

Protected Attributes

Data< MultiTaskSampleType > const & m_data
 multi-task data More...
 
KernelTypempe_inputKernel
 kernel on inputs More...
 
double m_gamma
 bandwidth of the Gaussian task kernel More...
 
- Protected Attributes inherited from shark::DiscreteKernel
RealMatrix m_matrix
 kernel matrix More...
 
- Protected Attributes inherited from shark::AbstractKernelFunction< std::size_t >
Features m_features
 

Detailed Description

template<class InputTypeT>
class shark::GaussianTaskKernel< InputTypeT >

Special "Gaussian-like" kernel function on tasks.

See
Learning Marginal Predictors: Transfer to an Unlabeled Task. G. Blanchard, G. Lee, C. Scott.
This class computes a Gaussian kernel based on the distance of empirical distributions in feature space induced by yet another kernel. This is useful for multi-task and transfer learning. It reduces the definition of a kernel on tasks to that of a kernel on inputs, plus a single bandwidth parameter for the Gaussian kernel of distributions.
Given unlabaled data \( x_i, t_i \) where the x-component is an input and the t-component is a task index, the kernel on tasks t and t' is defined as

\[ k(t, t') = \exp \left( -\gamma \cdot \left\| \frac{1}{\ell_{t}\ell{t'}} \sum_{i | t_i = t}\sum_{j | t_j = t'} k'(x_i, x_j) \right\|^2 \right) \]

where k' is an arbitrary kernel on inputs.

Definition at line 129 of file MultiTaskKernel.h.

Member Typedef Documentation

◆ InputType

template<class InputTypeT>
typedef InputTypeT shark::GaussianTaskKernel< InputTypeT >::InputType

Definition at line 134 of file MultiTaskKernel.h.

◆ KernelType

template<class InputTypeT>
typedef AbstractKernelFunction<InputType> shark::GaussianTaskKernel< InputTypeT >::KernelType

Definition at line 136 of file MultiTaskKernel.h.

◆ MultiTaskSampleType

template<class InputTypeT>
typedef MultiTaskSample<InputType> shark::GaussianTaskKernel< InputTypeT >::MultiTaskSampleType

Definition at line 135 of file MultiTaskKernel.h.

Constructor & Destructor Documentation

◆ GaussianTaskKernel()

template<class InputTypeT>
shark::GaussianTaskKernel< InputTypeT >::GaussianTaskKernel ( Data< MultiTaskSampleType > const &  data,
std::size_t  tasks,
KernelType inputkernel,
double  gamma 
)
inline

Construction of a Gaussian kernel on tasks.

Parameters
dataunlabeled data from multiple tasks
tasksnumber of tasks in the problem
inputkernelkernel on inputs based on which task similarity is defined
gammaGaussian bandwidth parameter (also refer to the member functions setGamma and setSigma).

Definition at line 144 of file MultiTaskKernel.h.

Member Function Documentation

◆ computeMatrix()

template<class InputTypeT>
void shark::GaussianTaskKernel< InputTypeT >::computeMatrix ( )
inlineprotected

Compute the Gram matrix of the task kernel.

Here is the real meat. This function implements the kernel function defined in
Learning Marginal Predictors: Transfer to an Unlabeled Task. G. Blanchard, G. Lee, C. Scott.
In a first step the function computes the inner products of the task-wise empirical distributions, represented by their mean elements in the kernel-induced feature space. In a second step this information is used for the computation of squared distances between empirical distribution, which allows for the straightforward computation of a Gaussian kernel.

Definition at line 236 of file MultiTaskKernel.h.

◆ gamma()

template<class InputTypeT>
double shark::GaussianTaskKernel< InputTypeT >::gamma ( ) const
inline

Kernel bandwidth parameter.

Definition at line 179 of file MultiTaskKernel.h.

◆ name()

template<class InputTypeT>
std::string shark::GaussianTaskKernel< InputTypeT >::name ( ) const
inlinevirtual

From INameable: return the class name.

Reimplemented from shark::DiscreteKernel.

Definition at line 157 of file MultiTaskKernel.h.

◆ numberOfParameters()

template<class InputTypeT>
std::size_t shark::GaussianTaskKernel< InputTypeT >::numberOfParameters ( ) const
inlinevirtual

Return the number of parameters.

Reimplemented from shark::DiscreteKernel.

Definition at line 171 of file MultiTaskKernel.h.

◆ numberOfTasks()

template<class InputTypeT>
std::size_t shark::GaussianTaskKernel< InputTypeT >::numberOfTasks ( ) const
inline

Definition at line 175 of file MultiTaskKernel.h.

◆ parameterVector()

template<class InputTypeT>
RealVector shark::GaussianTaskKernel< InputTypeT >::parameterVector ( ) const
inlinevirtual

Return the parameter vector.

Reimplemented from shark::DiscreteKernel.

Definition at line 160 of file MultiTaskKernel.h.

◆ read()

template<class InputTypeT>
void shark::GaussianTaskKernel< InputTypeT >::read ( InArchive ar)
inlinevirtual

From ISerializable.

Reimplemented from shark::DiscreteKernel.

Definition at line 205 of file MultiTaskKernel.h.

◆ setGamma()

template<class InputTypeT>
void shark::GaussianTaskKernel< InputTypeT >::setGamma ( double  gamma)
inline

Definition at line 189 of file MultiTaskKernel.h.

References SHARK_ASSERT.

◆ setParameterVector()

template<class InputTypeT>
void shark::GaussianTaskKernel< InputTypeT >::setParameterVector ( RealVector const &  newParameters)
inlinevirtual

Set the parameter vector.

Reimplemented from shark::DiscreteKernel.

Definition at line 164 of file MultiTaskKernel.h.

◆ setWidth()

template<class InputTypeT>
void shark::GaussianTaskKernel< InputTypeT >::setWidth ( double  sigma)
inline

Set the kernel width (equivalent to setting the bandwidth).

The bandwidth gamma and the width sigma are connected: \( gamma = 1 / (2 \cdot sigma^2) \).

Definition at line 198 of file MultiTaskKernel.h.

References SHARK_ASSERT.

◆ sigma()

template<class InputTypeT>
double shark::GaussianTaskKernel< InputTypeT >::sigma ( ) const
inline

Kernel width parameter, equivalent to the bandwidth parameter.

The bandwidth gamma and the width sigma are connected: \( gamma = 1 / (2 \cdot sigma^2) \).

Definition at line 185 of file MultiTaskKernel.h.

◆ write()

template<class InputTypeT>
void shark::GaussianTaskKernel< InputTypeT >::write ( OutArchive ar) const
inlinevirtual

From ISerializable.

Reimplemented from shark::DiscreteKernel.

Definition at line 212 of file MultiTaskKernel.h.

Member Data Documentation

◆ m_data

template<class InputTypeT>
Data<MultiTaskSampleType > const& shark::GaussianTaskKernel< InputTypeT >::m_data
protected

multi-task data

Definition at line 281 of file MultiTaskKernel.h.

◆ m_gamma

template<class InputTypeT>
double shark::GaussianTaskKernel< InputTypeT >::m_gamma
protected

bandwidth of the Gaussian task kernel

Definition at line 283 of file MultiTaskKernel.h.

◆ mpe_inputKernel

template<class InputTypeT>
KernelType* shark::GaussianTaskKernel< InputTypeT >::mpe_inputKernel
protected

kernel on inputs

Definition at line 282 of file MultiTaskKernel.h.


The documentation for this class was generated from the following file: