kernel#

class gym_socks.algorithms.kernel.ConditionalEmbedding(regularization_param=None)[source]#

Conditional distribution embedding.

Computes the conditional distribution embedding using sample data.

This class is primarily used internally to compute the regularized matrix inverse and predict the values of a function.

\[m(x) = f^{\top} (G + \lambda M I)^{-1} K\]
Parameters

regularization_param (float) – The regularization parameter \(\lambda\).

fit(G, y)[source]#

Fit the model.

Computes the matrix inverse \(W = (G + \lambda M I)^{-1}\).

Parameters
  • G (numpy.ndarray) – The (kernel) gram matrix. Usually computed as kernel_fn(X_train).

  • y (numpy.ndarray) – The output values of the function.

Returns

self

predict(K)[source]#

Predict the values.

Computes the product \(y^{\top} W K\).

Parameters

K (numpy.ndarray) – The kernel matrix. Usually computed as kernel_fn(X_train, X_test).

Returns

An ndarray of predicted y values.

score(y_test, K, y_train)[source]#
Parameters
  • y_test (numpy.ndarray) –

  • K (numpy.ndarray) –

  • y_train (numpy.ndarray) –

class gym_socks.algorithms.kernel.GenerativeModel(regularization_param=None)[source]#

Generative model.

The generative model is a distribution over functions, meaning given a set of inputs, it outputs a random function that could fit the data. Unlike the ConditionalEmbedding class, the GenerativeModel class does not compute the best fit function that matches the mean of the data. Instead, it computes a function that is within a Hilbert space ball of the embedding.

In other words, if \(m \in \mathscr{H}\) is the conditional embedding, then the generative model produces a random function \(f \in \mathscr{H}\) such that \(\lVert m - f \rVert \leq \delta\), where \(\delta\) is the radius of the ball.

This is useful in generating functions or trajectories which are superficially similar to the true embedding.

Important

It is important to note that the generated functions are close to the empirical conditional embedding, not the true embedding. Therefore, it should not be expected that the generated functions obey the same confidence bounds as the conditional embedding.

Parameters

regularization_param (float) – The regularization parameter \(\lambda\).

sample(K, num_samples=1, radius=None)[source]#

Generate predicted functions.

Generates a function that is within radius of the conditional embedding in the RKHS norm.

Parameters
  • K (numpy.ndarray) – The kernel matrix. Usually computed as kernel_fn(X_train, X_test).

  • num_samples (int) – Number of samples to compute.

  • radius (Optional[float]) – The radius of the Hilbert space ball.

Returns

An ndarray of predicted y values.

score(y)[source]#
Parameters

y (numpy.ndarray) –