superstats.transition.stochastic.kernel.kernel#
Kernel base classes and composition helpers.
Classes
|
Elementwise sum or product of two kernels' covariance matrices. |
|
Interface a kernel must satisfy to be used by GaussianProcess. |
- class superstats.transition.stochastic.kernel.kernel.CompositeKernel(left, right, op)[source]#
Bases:
KernelElementwise 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, right
Kernel 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”}
- left, right
- Parameters:
- build(num_steps, **hyperparams)[source]#
Construct the (batch_size, num_steps, num_steps) kernel matrix.
- Parameters:
- num_steps
int - **hyperparams
np.ndarray Must contain every name in self.hyperparam_names, each of shape (batch_size,). Extra keys (from sibling kernels in a composite) are ignored.
- num_steps
- Returns:
- kernel_mat
np.ndarrayofshape(batch_size,num_steps,num_steps)
- kernel_mat
- Parameters:
- Return type:
- class superstats.transition.stochastic.kernel.kernel.Kernel(name=None)[source]#
Bases:
ABCInterface 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:
- name
str,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”).
- name
- Attributes:
- Parameters:
name (str | None)
- abstract build(num_steps, **hyperparams)[source]#
Construct the (batch_size, num_steps, num_steps) kernel matrix.
- Parameters:
- num_steps
int - **hyperparams
np.ndarray Must contain every name in self.hyperparam_names, each of shape (batch_size,). Extra keys (from sibling kernels in a composite) are ignored.
- num_steps
- Returns:
- kernel_mat
np.ndarrayofshape(batch_size,num_steps,num_steps)
- kernel_mat
- Parameters:
- Return type:
- local_hyperparams(**hyperparams)[source]#
Strip this kernel’s name prefix off hyperparams.
- Parameters:
- **hyperparams
np.ndarray Must contain every name in self.hyperparam_names. Extra keys (from sibling kernels in a composite) are ignored.
- **hyperparams
- Returns:
- local
dict- hyperparams re-keyedbytheunprefixednames in self._local_hyperparam_names
- local
- Parameters:
hyperparams (ndarray)
- Return type: