geometric_kernels.feature_maps

(Approximate) finite-dimensional feature maps for geometric kernels.

A brief introduction into the theory can be found on this page.

Submodules

Package Contents

class geometric_kernels.feature_maps.DeterministicFeatureMapCompact(space, num_levels)[source]

Bases: geometric_kernels.feature_maps.base.FeatureMap

Deterministic feature map for DiscreteSpectrumSpaces for which the actual eigenpairs are explicitly available.

Parameters:
__call__(X, params, normalize=None, **kwargs)[source]
Parameters:
  • X (lab.Numeric) – [N, …] points in the space to evaluate the map on.

  • params (beartype.typing.Dict[str, lab.Numeric]) – Parameters of the kernel (length scale and smoothness).

  • normalize (beartype.typing.Optional[bool]) – Normalize to have unit average variance (if omitted or None, follows the standard behavior of MaternKarhunenLoeveKernel).

  • **kwargs – Unused.

Returns:

Tuple(None, features) where features is an [N, O] array, N is the number of inputs and O is the dimension of the feature map.

Return type:

beartype.typing.Tuple[None, lab.Numeric]

Note

The first element of the returned tuple is the simple None and should be ignored. It is only there to support the abstract interface: for some other subclasses of FeatureMap, this first element may be an updated random key.

class geometric_kernels.feature_maps.FeatureMap[source]

Bases: abc.ABC

Abstract base class for all feature maps.

abstract __call__(*args, **kwargs)[source]

FeatureMaps are callable.

class geometric_kernels.feature_maps.RandomPhaseFeatureMapCompact(space, num_levels, num_random_phases=3000)[source]

Bases: geometric_kernels.feature_maps.base.FeatureMap

Random phase feature map for DiscreteSpectrumSpaces for which the addition theorem-like basis functions are explicitly available while actual eigenpairs may be implicit.

Parameters:
__call__(X, params, *, key, normalize=None, **kwargs)[source]
Parameters:
  • X (lab.Numeric) – [N, …] points in the space to evaluate the map on.

  • params (beartype.typing.Dict[str, lab.Numeric]) – Parameters of the kernel (length scale and smoothness).

  • key (lab.RandomState) –

    Random state, either np.random.RandomState, tf.random.Generator, torch.Generator or jax.tensor (which represents a random state).

    Note

    For any backend other than jax, passing the same key twice does not guarantee that the feature map will be the same each time. This is because these backends’ random state has… a state. To evaluate the same (including randomness) feature map on different inputs, you can either save/restore state manually each time or use the helper function make_deterministic() which does this for you.

  • normalize (beartype.typing.Optional[bool]) – Normalize to have unit average variance (if omitted or None, follows the standard behavior of kernels.MaternKarhunenLoeveKernel).

  • **kwargs – Unused.

Returns:

Tuple(key, features) where features is an [N, O] array, N is the number of inputs and O is the dimension of the feature map; key is the updated random key for jax, or the similar random state (generator) for any other backends.

Return type:

beartype.typing.Tuple[lab.RandomState, lab.Numeric]

class geometric_kernels.feature_maps.RandomPhaseFeatureMapNoncompact(space, num_random_phases=3000, shifted_laplacian=True)[source]

Bases: geometric_kernels.feature_maps.base.FeatureMap

Basic random phase feature map for NoncompactSymmetricSpaces (importance sampling based).

This feature map should not be used if a space-specific alternative exists.

Parameters:
  • space (geometric_kernels.spaces.NoncompactSymmetricSpace) – A NoncompactSymmetricSpace space.

  • num_random_phases (int) – Number of random phases to use.

  • shifted_laplacian (bool) –

    If True, assumes that the kernels are defined in terms of the shifted Laplacian. This often makes Matérn kernels more flexible by widening the effective range of the length scale parameter.

    Defaults to True.

__call__(X, params, *, key, normalize=True, **kwargs)[source]
Parameters:
  • X (lab.Numeric) – [N, …] points in the space to evaluate the map on.

  • params (beartype.typing.Dict[str, lab.Numeric]) – Parameters of the feature map (length scale and smoothness).

  • key (lab.RandomState) –

    Random state, either np.random.RandomState, tf.random.Generator, torch.Generator or jax.tensor (which represents a random state).

    Note

    For any backend other than jax, passing the same key twice does not guarantee that the feature map will be the same each time. This is because these backends’ random state has… a state. To evaluate the same (including randomness) feature map on different inputs, you can either save/restore state manually each time or use the helper function make_deterministic() which does this for you.

  • normalize (beartype.typing.Optional[bool]) – Normalize to have unit average variance (True by default).

  • **kwargs – Unused.

Returns:

Tuple(key, features) where features is an [N, O] array, N is the number of inputs and O is the dimension of the feature map; key is the updated random key for jax, or the similar random state (generator) for any other backends.

Return type:

beartype.typing.Tuple[lab.RandomState, lab.Numeric]

class geometric_kernels.feature_maps.RejectionSamplingFeatureMapHyperbolic(space, num_random_phases=3000, shifted_laplacian=True)[source]

Bases: geometric_kernels.feature_maps.base.FeatureMap

Random phase feature map for the Hyperbolic space based on the rejection sampling algorithm.

Parameters:
  • space (geometric_kernels.spaces.Hyperbolic) – A Hyperbolic space.

  • num_random_phases (int) – Number of random phases to use.

  • shifted_laplacian (bool) –

    If True, assumes that the kernels are defined in terms of the shifted Laplacian. This often makes Matérn kernels more flexible by widening the effective range of the length scale parameter.

    Defaults to True.

__call__(X, params, *, key, normalize=True, **kwargs)[source]
Parameters:
  • X (lab.Numeric) – [N, D] points in the space to evaluate the map on.

  • params (beartype.typing.Dict[str, lab.Numeric]) – Parameters of the feature map (length scale and smoothness).

  • key (lab.RandomState) –

    Random state, either np.random.RandomState, tf.random.Generator, torch.Generator or jax.tensor (which represents a random state).

    Note

    For any backend other than jax, passing the same key twice does not guarantee that the feature map will be the same each time. This is because these backends’ random state has… a state. To evaluate the same (including randomness) feature map on different inputs, you can either save/restore state manually each time or use the helper function make_deterministic() which does this for you.

  • normalize (beartype.typing.Optional[bool]) – Normalize to have unit average variance (True by default).

  • **kwargs – Unused.

Returns:

Tuple(key, features) where features is an [N, O] array, N is the number of inputs and O is the dimension of the feature map; key is the updated random key for jax, or the similar random state (generator) for any other backends.

Return type:

beartype.typing.Tuple[lab.RandomState, lab.Numeric]

class geometric_kernels.feature_maps.RejectionSamplingFeatureMapSPD(space, num_random_phases=3000, shifted_laplacian=True)[source]

Bases: geometric_kernels.feature_maps.base.FeatureMap

Random phase feature map for the SymmetricPositiveDefiniteMatrices space based on the rejection sampling algorithm.

Parameters:
__call__(X, params, *, key, normalize=True, **kwargs)[source]
Parameters:
  • X (lab.Numeric) – [N, D, D] points in the space to evaluate the map on.

  • params (beartype.typing.Dict[str, lab.Numeric]) – Parameters of the feature map (length scale and smoothness).

  • key (lab.RandomState) –

    Random state, either np.random.RandomState, tf.random.Generator, torch.Generator or jax.tensor (which represents a random state).

    Note

    For any backend other than jax, passing the same key twice does not guarantee that the feature map will be the same each time. This is because these backends’ random state has… a state. To evaluate the same (including randomness) feature map on different inputs, you can either save/restore state manually each time or use the helper function make_deterministic() which does this for you.

  • normalize (beartype.typing.Optional[bool]) – Normalize to have unit average variance (True by default).

  • **kwargs – Unused.

Returns:

Tuple(key, features) where features is an [N, O] array, N is the number of inputs and O is the dimension of the feature map; key is the updated random key for jax, or the similar random state (generator) for any other backends.

Return type:

beartype.typing.Tuple[lab.RandomState, lab.Numeric]