Kernel functionslink

Kernel functions are the key to producing kernel matrices and hence are the backbone of kernel methods and machines. These are represented by a fundamental [abstract base] class called ``BaseKernelFunction``, which defines several desirable properties, such as

  • ensures it induces a positive semi-definite kernel matrix

  • making it callable, accepting at least two inputs (data points)

  • a readable representation of the underlying function with a name.

This modularization of all the kernel functions separate from the KernelMatrix class enables us to support diverse and mixed data types. This also enables to support various formats and data structures beyond numpy arrays such as pyradigm.

We also provide a KernelFromCallable class which makes it even easier to define a kernel function just by specifying the underlying computation, without having to define a fully separate class.

In addition, the following classes are provided to enable compositional representation of multiple kernel functions for advanced applications: CompositeKernel, ProductKernel, SumKernel, AverageKernel, and WeightedAverageKernel.

kernelmethods aims to offer kernel functions that can operate on the following data types:

Below, we document the API for the important classes related to kernel functions, such as :

  • BaseKernelFunction

  • KernelFromCallable

  • and composites as noted above.

BaseKernelFunctionlink

code class kernelmethods.BaseKernelFunction(name)[source]link

Bases: abc.ABC

Abstract base class for kernel functions.

Enforces each derived kernel: 1. to be callable, with two inputs 2. to have a name and a str representation 3. provides a method to check whether the derived kernel func is a valid kernel

i.e. kernel matrix derived on a random sample is positive semi-definite (PSD)

  1. and that it is symmetric (via tests) as required.

code is_psd()[source]link

Tests whether kernel matrix produced via this function is PSD

KernelFromCallablelink

code class kernelmethods.base.KernelFromCallable(input_func, name=None, **func_params)[source]link

Bases: kernelmethods.base.BaseKernelFunction

Class to create a custom kernel from a given callable.

Parameters
  • input_func (callable) – A callable that can accept atleast 2 args Must not be builtin or C function. If func is a C or builtin func, wrap it in a python def

  • name (str) – A name to identify this kernel in a human readable way

  • func_params (dict) – Parameters to func

code is_psd()link

Tests whether kernel matrix produced via this function is PSD

Composite kernel functionslink

code class kernelmethods.base.CompositeKernel(km_set, name='Composite')[source]link

Bases: abc.ABC

Class to combine a set of kernels into a composite kernel.

Parameters
  • km_set (KernelSet) – KernelSet on which the composite kernel will be applied to

  • name (str) – Identifier for the composite kernel

code property composite_KMlink

Returns the result of composite operation

code abstract fit()[source]link

Abstract methods that needs to be defined later.

code property fulllink

Returns the result of compsoite operation.

Alias for composite_KM to match the KernelMatrix interface.

code class kernelmethods.base.ProductKernel(km_set, name='ProductKernel')[source]link

Bases: kernelmethods.base.CompositeKernel

Class to define and compute a Product kernel from a KernelSet

Parameters
  • km_set (KernelSet) – KernelSet from which the product kernel will be computed from

  • name (str) – Identifier for the composite kernel

code property composite_KMlink

Returns the result of composite operation

code fit()[source]link

Computes the product kernel.

code property fulllink

Returns the result of compsoite operation.

Alias for composite_KM to match the KernelMatrix interface.

code class kernelmethods.base.SumKernel(km_set, name='SumKernel')[source]link

Bases: kernelmethods.base.CompositeKernel

Class to define and compute a weighted sum kernel from a KernelSet

Parameters
  • km_set (KernelSet) – KernelSet from which the summ kernel will be computed from

  • name (str) – Identifier for the composite kernel

code property composite_KMlink

Returns the result of composite operation

code fit(kernel_weights=None)[source]link

Computes the sum kernel

code property fulllink

Returns the result of compsoite operation.

Alias for composite_KM to match the KernelMatrix interface.

code class kernelmethods.base.AverageKernel(km_set, name='AverageKernel')[source]link

Bases: kernelmethods.base.CompositeKernel

Class to define and compute an Average kernel from a KernelSet

Parameters
  • km_set (KernelSet) – KernelSet from which the average kernel will be computed

  • name (str) – Identifier for the composite kernel

code property composite_KMlink

Returns the result of composite operation

code fit()[source]link

Computes the average kernel

code property fulllink

Returns the result of compsoite operation.

Alias for composite_KM to match the KernelMatrix interface.

code class kernelmethods.base.WeightedAverageKernel(km_set, weights, name='WeightedAverageKernel')[source]link

Bases: kernelmethods.base.CompositeKernel

Class to define and compute a weighted verage kernel from a KernelSet

Parameters
  • km_set (KernelSet) – KernelSet from which the average kernel will be computed

  • name (str) – Identifier for the composite kernel

code property composite_KMlink

Returns the result of composite operation

code fit()[source]link

Computes the weighted average kernel

code property fulllink

Returns the result of compsoite operation.

Alias for composite_KM to match the KernelMatrix interface.