superstats.transition.stochastic.kernel.kernel#

Kernel base classes and composition helpers.

Classes

CompositeKernel(left, right, op)

Elementwise sum or product of two kernels' covariance matrices.

Kernel([name])

Interface a kernel must satisfy to be used by GaussianProcess.

class superstats.transition.stochastic.kernel.kernel.CompositeKernel(left, right, op)[source]#

Bases: Kernel

Elementwise sum or product of two kernels’ covariance matrices.

Not constructed directly in normal use — created by + / * on Kernel instances, e.g. RBFKernel() + LinearKernel().

Parameters:
left, rightKernel

Kernels to combine. Must have disjoint hyperparam_names — combining two kernels of the same type requires giving at least one of them an explicit name.

op{“add”, “mul”}
Parameters:
build(num_steps, **hyperparams)[source]#

Construct the (batch_size, num_steps, num_steps) kernel matrix.

Parameters:
num_stepsint
**hyperparamsnp.ndarray

Must contain every name in self.hyperparam_names, each of shape (batch_size,). Extra keys (from sibling kernels in a composite) are ignored.

Returns:
kernel_matnp.ndarray of shape (batch_size, num_steps, num_steps)
Parameters:
Return type:

ndarray

class superstats.transition.stochastic.kernel.kernel.Kernel(name=None)[source]#

Bases: ABC

Interface a kernel must satisfy to be used by GaussianProcess.

Subclasses set _local_hyperparam_names (the hyperparameter names they need) and implement build. Use self.local_hyperparams(…) inside build to strip this kernel’s name prefix off the incoming hyperparams dict before passing values to the underlying kernel math.

By default (name=None), hyperparam_names are unprefixed, e.g. RBFKernel() exposes (“length_scale”, “amplitude”) — matching DEFAULT_HYPER_PRIORS directly, same as RandomWalk’s sigma/ delta. Pass name= to prefix them (“trend_length_scale”), which is required when combining two kernels that would otherwise expose the same hyperparameter names.

Kernels combine with + (sum) and * (elementwise product) into a CompositeKernel — both operations preserve positive-semidefiniteness, so any combination is itself a valid kernel.

Parameters:
namestr, optional

Prefix for this kernel’s hyperparameter names. Leave unset for a single kernel, or when combining kernels of different types. Required (and must be unique) when combining two kernels that share hyperparameter names, e.g. RBFKernel(name=”trend”) + RBFKernel(name=”local”).

Attributes:
hyperparam_namestuple of str

Hyperparameter names this kernel expects in build, e.g. (“length_scale”, “amplitude”) when unnamed, or (“trend_length_scale”, “trend_amplitude”) when name=”trend”. These become Transition.hyper_specs entries.

Parameters:

name (str | None)

abstract build(num_steps, **hyperparams)[source]#

Construct the (batch_size, num_steps, num_steps) kernel matrix.

Parameters:
num_stepsint
**hyperparamsnp.ndarray

Must contain every name in self.hyperparam_names, each of shape (batch_size,). Extra keys (from sibling kernels in a composite) are ignored.

Returns:
kernel_matnp.ndarray of shape (batch_size, num_steps, num_steps)
Parameters:
Return type:

ndarray

local_hyperparams(**hyperparams)[source]#

Strip this kernel’s name prefix off hyperparams.

Parameters:
**hyperparamsnp.ndarray

Must contain every name in self.hyperparam_names. Extra keys (from sibling kernels in a composite) are ignored.

Returns:
localdict - hyperparams re-keyed by the unprefixed names

in self._local_hyperparam_names

Parameters:

hyperparams (ndarray)

Return type:

Dict[str, ndarray]