superstats.transition.stochastic.kernel#
Kernel implementations for Gaussian-process transitions.
- class superstats.transition.stochastic.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(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:
- class superstats.transition.stochastic.kernel.LinearKernel(name=None)[source]#
Bases:
KernelLinear kernel. Requires hyperparameter variance.
- Parameters:
- name
str,optional Prefix for this kernel’s hyperparameter name. Leave unset for a single linear kernel, or when combining with a kernel of a different type. Required when combining two linear kernels.
- name
- Parameters:
name (str | None)
- 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.PeriodicKernel(name=None)[source]#
Bases:
KernelPeriodic kernel. Requires hyperparameters length_scale, period, amplitude.
Models functions that repeat themselves exactly. period sets the distance between repetitions; length_scale controls smoothness of the repeated shape, same interpretation as in RBFKernel.
- Parameters:
- name
str,optional Prefix for this kernel’s hyperparameter names. Leave unset for a single periodic kernel, or when combining with a kernel of a different type. Required when combining two periodic kernels.
- name
- Parameters:
name (str | None)
- 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.RBFKernel(name=None)[source]#
Bases:
KernelRBF kernel. Requires hyperparameters length_scale, amplitude.
- Parameters:
- name
str,optional Prefix for this kernel’s hyperparameter names. Leave unset for a single RBF kernel, or when combining with a kernel of a different type. Required when combining two RBF kernels, e.g. RBFKernel(name=”short”) + RBFKernel(name=”long”).
- name
- Parameters:
name (str | None)
- 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:
- superstats.transition.stochastic.kernel.build_abs_dist_mat(num_steps)[source]#
Absolute pairwise distances for num_steps evenly spaced points on [0, 1].
- Parameters:
- num_steps
int Number of points in the 1D grid.
- num_steps
- Returns:
- abs_dist
np.ndarrayofshape(num_steps,num_steps) Absolute distance between point i and point j at [i, j].
- abs_dist
- Parameters:
num_steps (int)
- Return type:
- superstats.transition.stochastic.kernel.build_sq_dist_mat(num_steps)[source]#
Squared pairwise distances for num_steps evenly spaced points on [0, 1].
- Parameters:
- num_steps
int Number of points in the 1D grid.
- num_steps
- Returns:
- sq_dist
np.ndarrayofshape(num_steps,num_steps) Squared distance between point i and point j at [i, j].
- sq_dist
- Parameters:
num_steps (int)
- Return type:
- superstats.transition.stochastic.kernel.get_linear_kernel(num_steps, variance)[source]#
Batched linear kernel construction.
- Parameters:
- num_steps
int Number of points in the 1D grid.
- variance
np.ndarrayofshape(batch_size,) Scale of the kernel per trajectory.
- num_steps
- Returns:
- kernel_mat
np.ndarrayofshape(batch_size,num_steps,num_steps)
- kernel_mat
- Parameters:
- Return type:
- superstats.transition.stochastic.kernel.get_periodic_kernel(num_steps, length_scale, period, amplitude)[source]#
Batched periodic kernel construction.
k(x, x_prime) = amplitude^2 * exp(-2 * sin^2(pi * |x - x_prime| / period) / length_scale^2)
- Parameters:
- num_steps
int Number of points in the 1D grid.
- length_scale
np.ndarrayofshape(batch_size,) Smoothness of the repeated shape; smaller values mean a more wiggly repeating pattern, larger values a smoother one.
- period
np.ndarrayofshape(batch_size,) Distance between repetitions, on the [0, 1] grid.
- amplitude
np.ndarrayofshape(batch_size,) Kernel variance / overall scale per trajectory.
- num_steps
- Returns:
- kernel_mat
np.ndarrayofshape(batch_size,num_steps,num_steps)
- kernel_mat
- Parameters:
- Return type:
- superstats.transition.stochastic.kernel.get_rbf_kernel(num_steps, length_scale, amplitude)[source]#
Batched RBF kernel construction.
- Parameters:
- num_steps
int Number of points in the 1D grid.
- length_scale
np.ndarrayofshape(batch_size,) Kernel width per trajectory; larger values mean smoother, slower-varying draws.
- amplitude
np.ndarrayofshape(batch_size,) Kernel variance / overall scale per trajectory.
- num_steps
- Returns:
- kernel_mat
np.ndarrayofshape(batch_size,num_steps,num_steps)
- kernel_mat
- Parameters:
- Return type:
- superstats.transition.stochastic.kernel.resolve_kernel(kernel)[source]#
Resolve a kernel name or instance to a Kernel.
Modules