ARNNResult#

class cultivars.univariate.mean_function.ARNNResult(*, endog, fittedvalues, resid, llf, nobs, n_params, order, sigma2, engine, engine_config, predictor)[source]#

A fitted neural autoregression.

The model \(y_t = f(y_{t-1}, \ldots, y_{t-p}) + \varepsilon_t\) with \(f\) a learned function and \(\varepsilon_t \sim N(0, \sigma^2)\), the variance concentrated out of a penalized least-squares fit. There is no coefficient vector; the record carries the fitted function as a callable, the fit statistics, and the engine that produced it, since with a plug-in backend the engine is part of the specification.

Variables:

predictor (MeanPredictor) – The learned conditional-mean map, callable through predict().

Note

The inherited fields are endog, fittedvalues, resid, llf, nobs, n_params, order, sigma2, engine and engine_config; the inherited properties r_squared, ssr and parameters_per_observation read them. fittedvalues and resid are aligned with the last nobs = len(endog) - order observations. llf is a concentrated Gaussian likelihood at a penalized fit, so the information criteria compare capacity within one engine configuration and not against a linear model; r_squared is the headline number.

See also

Example

A one-lag map \(0.8 \tanh(2 y_{t-1})\) recovered on a grid:

>>> import numpy as np
>>> from cultivars_engine._core._matrices import _lag_matrix
>>> rng = np.random.default_rng(0)
>>> y = np.zeros(500)
>>> for t in range(1, 500):
...     y[t] = 0.8 * np.tanh(2.0 * y[t - 1]) + 0.3 * rng.standard_normal()
>>> res = ARNN(y, order=1).fit()
>>> res.nobs, res.n_learner_parameters, res.engine
(499, 25, 'NumpyMLPEngine')
>>> bool(np.allclose(res.predict(_lag_matrix(y, 1)), res.fittedvalues))
True
>>> grid = np.array([[-1.0], [0.0], [1.0]])
>>> bool(np.max(np.abs(res.predict(grid) - 0.8 * np.tanh(2.0 * grid[:, 0]))) < 0.15)
True

Attributes#

predictor

The trained network; use predict() rather than calling it.

endog

The full input series.

engine

Class name of the training backend.

engine_config

Full repr of the backend, so the fit is reproducible.

fittedvalues

In-sample conditional means over the effective sample.

information_criteria

AIC, BIC, and HQIC derived from the likelihood and parameter count.

llf

Concentrated Gaussian log-likelihood at the fitted mean.

n_learner_parameters

Weights and biases in the single fitted network.

n_params

Learner parameters plus the concentrated variance, and the threshold where one is estimated.

nobs

Effective sample size after trimming for lags and delay.

order

Number of lagged levels fed to the learner.

parameters_per_observation

Nominal learner parameters divided by the effective sample size.

r_squared

Share of the effective sample's variance the fitted mean explains.

resid

Residuals against those means.

sigma2

Concentrated innovation variance, ssr / nobs.

ssr

Sum of squared residuals over the effective sample.

Methods#

compare(*others[, criterion])

Rank this result against others by an information criterion.

likelihood_ratio_test(unrestricted)

Refuse the test: a network's weights are unidentified under a linear null.

nonlinear_state_space(measurement_variance)

The learned mean as a noisily observed state space.

predict(features)

Conditional means for a matrix of lagged levels.

summary()

The estimation summary, renderable as text, HTML, or a dataframe.

to_dict()

The aligned per-observation outputs as plain numpy arrays.

to_pandas(*[, index])

The aligned per-observation outputs as a pandas.DataFrame.

to_polars()

The aligned per-observation outputs as a polars.DataFrame.