incline.GaussianProcess

class incline.GaussianProcess(kernel='rbf', amplitude=None, length_scale=None, noise_level=0.1, n_restarts=5, optimize=True, standardize=True)[source]

Gaussian process regression with an exact derivative posterior.

Variables:
  • kernel (str) – 'rbf', 'matern32' or 'matern52'. The Matern smoothness caps the derivative order: 3/2 is once differentiable, 5/2 twice.

  • amplitude (float | None) – Prior variance of the signal. Optimized from a starting value of 1 when None.

  • length_scale (float | None) – Initial length scale. Optimized from the data when None.

  • noise_level (float) – Noise variance. A starting value when optimize is on, the value used when it is off.

  • n_restarts (int) – Restarts for the hyperparameter optimizer.

  • optimize (bool) – Whether to fit the kernel hyperparameters by marginal likelihood. When False the kernel is used exactly as given.

  • standardize (bool) – Whether to rescale the response before fitting. Decides what units amplitude and noise_level are in.

Parameters:

Note

The three settings are separable and each does one thing: optimize decides whether the hyperparameters are learned, standardize decides what units they are expressed in, and amplitude is one of them.

With standardize=True the response is centered and scaled, so amplitude and noise_level are in units of the series’ own standard deviation. That is the right default when they are being learned, and it keeps the fit well conditioned.

With standardize=False the response is only centered, so both are in the data’s own units and a prior can be stated exactly. Centering is kept either way because the prior mean is zero and real series are not; a constant shift does not affect any derivative. Scaling is what obscured the units: it made a supplied noise_level mean something other than what was asked for, and measured against data drawn from a known prior, credible intervals covered 0.90 instead of 0.95.

Note

optimize exists because sklearn re-fits the hyperparameters on every call regardless of n_restarts_optimizer – that setting controls how many restarts an optimization gets, not whether one happens. Passing a length_scale therefore only chose a starting point, and the fitted scale came out the same whatever was asked for, which silently made with_scale() a no-op and a multi-scale sweep a single scale repeated. with_scale now turns optimization off so the scale it sets is the scale that gets used.

__init__(kernel='rbf', amplitude=None, length_scale=None, noise_level=0.1, n_restarts=5, optimize=True, standardize=True)
Parameters:
Return type:

None

Methods

__init__([kernel, amplitude, length_scale, ...])

analytic_operators(axis, order)

State the smoothing and derivative operators directly, if known.

evaluate(axis, y, order)

Posterior mean of the smooth and of its derivative.

fit(axis, y[, order, se, noise, ...])

Estimate the trend and, optionally, its uncertainty.

native_posterior(axis, y, order, ...)

Exact posterior standard deviation of the derivative.

operators(axis, order)

The smoothing and derivative operators for this configuration.

params()

Report the kernel and length scale.

scale_of(axis)

Length scale as a fraction of the span.

with_scale(scale, axis)

Fix the length scale to scale of the series span.

Attributes

amplitude

has_native_posterior

is_linear

Whether the derivative is a fixed linear map of the data.

kernel

length_scale

linear

n_restarts

name

noise_level

optimize

requires_regular_grid

standardize

supported_orders

name: ClassVar[str] = 'gp'
has_native_posterior: ClassVar[bool] = True
supported_orders: ClassVar[frozenset[int]] = frozenset({0, 1, 2})
kernel: str = 'rbf'
amplitude: float | None = None
length_scale: float | None = None
noise_level: float = 0.1
n_restarts: int = 5
optimize: bool = True
standardize: bool = True
evaluate(axis, y, order)[source]

Posterior mean of the smooth and of its derivative.

Parameters:
  • axis (TimeAxis)

  • y (npt.NDArray[np.float64])

  • order (int)

Return type:

Evaluation

native_posterior(axis, y, order, confidence_level)[source]

Exact posterior standard deviation of the derivative.

Parameters:
  • axis (TimeAxis)

  • y (npt.NDArray[np.float64])

  • order (int)

  • confidence_level (float)

Return type:

tuple[npt.NDArray[np.float64], None, None]

with_scale(scale, axis)[source]

Fix the length scale to scale of the series span.

Optimization is switched off, or the scale just set would immediately be optimized away and every scale in a sweep would return the same fit.

Parameters:
Return type:

Self

scale_of(axis)[source]

Length scale as a fraction of the span.

Parameters:

axis (TimeAxis)

Return type:

float

params()[source]

Report the kernel and length scale.

Return type:

dict[str, Any]