TARNNResult.predict#

TARNNResult.predict(features, threshold_values)[source]#

Conditional means, routing each row to its regime’s learner.

Takes the threshold variable explicitly rather than deriving it from features. For a self-exciting model with delay <= order it could be read off a column, but not when the delay exceeds the order and not at all when the threshold variable is external – so requiring it keeps one code path that is correct in every configuration.

Parameters:
  • features (NDArray[double]) – Shape (n, order), columns ordered [y_{t-1}, ..., y_{t-order}].

  • threshold_values (NDArray[double]) – Length n, the threshold variable already lagged by delay.

Return type:

NDArray[double]

Returns:

An array of length n.

Raises:

DimensionError – If the feature matrix has the wrong shape, or threshold_values does not match its row count.

Example

The in-sample fit reproduced from the lag matrix and the stored threshold variable:

>>> import numpy as np
>>> from cultivars.engine._core._matrices import _lag_matrix
>>> rng = np.random.default_rng(0)
>>> y = rng.standard_normal(300)
>>> res = TARNN(y, order=1).fit()
>>> means = res.predict(_lag_matrix(y, 1), res.threshold_values)
>>> bool(np.allclose(means, res.fittedvalues))
True
>>> res.predict(_lag_matrix(y, 1), res.threshold_values[:5])
Traceback (most recent call last):
    ...
cultivars.exceptions.DimensionError: threshold_values must have shape (299,); got (5,).