Module kernels

operalib.kernels implements some Operator-Valued Kernel models.

class operalib.kernels.DecomposableKernel(A, scalar_kernel=<function rbf_kernel>, scalar_kernel_params=None)

Decomposable Operator-Valued Kernel.

Decomposable Operator-Valued Kernel of the form:

X, Y \mapsto K(X, Y) = k_s(X, Y) A

where A is a symmetric positive semidefinite operator acting on the outputs.

See also

DecomposableKernelMap
Decomposable Kernel map

Examples

>>> import operalib as ovk
>>> import numpy as np
>>> X = np.random.randn(100, 10)
>>> K = ovk.DecomposableKernel(np.eye(2))
>>> K(X, X) +NORMALIZE_WHITESPACE  # The kernel matrix as a linear
                                   # operator
<200x200 _CustomLinearOperator with dtype=float64>

Attributes

A ({array, LinearOperator}, shape = [n_targets, n_targets]) Linear operator acting on the outputs
scalar_kernel ({callable}) Callable which associate to the training points X the Gram matrix.
scalar_kernel_params ({mapping of string to any}) Additional parameters (keyword arguments) for kernel function passed as callable object.
p ({Int}) dimension of the targets (n_targets).

Methods

__call__(X[, Y]) Return the kernel map associated with the data X.
get_kernel_map(X) Return the kernel map associated with the data X.
__call__(X, Y=None)

Return the kernel map associated with the data X.

K_x: Y \mapsto K(X, Y) if Y is None K(X, Y) otherwise

Parameters:

X : {array-like, sparse matrix}, shape = [n_samples1, n_features]

Samples.

Y : {array-like, sparse matrix}, shape = [n_samples2, n_features],

default = None

Samples.

Returns:

K_x : DecomposableKernelMap, callable or LinearOperator

Returns K_x: Y mapsto K(X, Y) if Y is None; K(X, Y) otherwise.

__init__(A, scalar_kernel=<function rbf_kernel>, scalar_kernel_params=None)

Initialize the Decomposable Operator-Valued Kernel.

Parameters:

A : {array, LinearOperator}, shape = [n_targets, n_targets]

Linear operator acting on the outputs

scalar_kernel : {callable}

Callable which associate to the training points X the Gram matrix.

scalar_kernel_params : {mapping of string to any}, optional

Additional parameters (keyword arguments) for kernel function passed as callable object.

__weakref__

list of weak references to the object (if defined)

get_kernel_map(X)

Return the kernel map associated with the data X.

K_x: Y \mapsto K(X, Y)

Parameters:

X : {array-like, sparse matrix}, shape = [n_samples, n_features]

Samples.

Returns:

K_x : DecomposableKernelMap, callable

Returns K_x: Y mapsto K(X, Y).

operalib.kernel_maps implement some Operator-Valued Kernel maps associated to the operator-valued kernel models defined in operalib.kernels.

class operalib.kernel_maps.DecomposableKernelMap(X, A, scalar_kernel, scalar_kernel_params)

Decomposable Operator-Valued Kernel.

Decomposable Operator-Valued Kernel map of the form:

X \mapsto K_X(Y) = k_s(X, Y) A

where A is a symmetric positive semidefinite operator acting on the outputs. This class just fixes the support data X to the kernel. Hence it naturally inherit from Decomposable kernels

See also

DecomposableKernel
Decomposable Kernel

Attributes

n: {Int} Number of samples.
d: {Int} Number of features
X: {array-like, sparse matrix}, shape = [n_samples, n_features] Support samples.
Gs: {array-like, sparse matrix}, shape = [n, n] Gram matrix associated with the scalar kernel

Methods

__call__(Y) Return the Gram matrix associated with the data Y.
get_kernel_map(X) Return the kernel map associated with the data X.
__call__(Y)

Return the Gram matrix associated with the data Y.

K(X, Y)

Parameters:

Y : {array-like, sparse matrix}, shape = [n_samples1, n_features]

Samples.

Returns:

K(X, Y) : LinearOperator

Returns K(X, Y).

__init__(X, A, scalar_kernel, scalar_kernel_params)

Initialize the Decomposable Operator-Valued Kernel.

Parameters:

X: {array-like, sparse matrix}, shape = [n_samples1, n_features]

Support samples.

A : {array, LinearOperator}, shape = [n_targets, n_targets]

Linear operator acting on the outputs

scalar_kernel : {callable}

Callable which associate to the training points X the Gram matrix.

scalar_kernel_params : {mapping of string to any}, optional

Additional parameters (keyword arguments) for kernel function passed as callable object.

__mul__(Ky)

Syntaxic sugar.

If Kx is a compatible decomposable kernel, returns

K(X, Y) = K_X^T K_Y

Parameters:

Ky : {DecomposableKernelMap}

Compatible kernel Map (e.g. same kernel but different support data X).

Returns:

K(X, Y) : LinearOperator

Returns K(X, Y).