TimeSeries sub-package

The TimeSeriesSRC.TimeSeries sub-package contains the TimesSeries convenience class that wraps the lower-level basefunctions.

class TimeSeriesSRC.TimeSeries.TSAnalysis.TimesSeries[source]

Bases: object

Class contains all the functions for Times Series Analysis

Prediction Model Toolbox. Version 0.1.0 2022 Translation from MatLab to Python

Analysis functions.

gpac - Compute the GPAC for a given autocorrelation function. impest - Estimate impulse response between two time series. parcor - Compute the partial autocorrelation function. partoacf -

Pre and Post Processing.

sdiff - Difference a time series.

Utility functions.

chisqrdf - Calculate Chi square cumulative density function makerow - Convert matrix so that it contains more columns than rows. XCORR - Calculate autocorrelation function

makerow(y)[source]

Convert an array so that it has more columns than rows.

Parameters:

y (array-like) – Input vector or matrix.

Returns:

yr – Transposed array if necessary so that yr.shape[1] >= yr.shape[0].

Return type:

ndarray

See also

func_makerow

Underlying function.

xcorr(a, b, maxlags, flag)[source]

Compute the cross-correlation (or autocorrelation) between two sequences.

Parameters:
  • a (array-like, shape (1, N)) – First sequence.

  • b (array-like, shape (1, N)) – Second sequence. Pass the same array as a for autocorrelation.

  • maxlags (int) – Maximum lag to compute; output spans lags -maxlags to +maxlags.

  • flag ({'biased', 'unbiased', 'none'}) – Normalisation flag.

Returns:

c – Cross-correlation values from lag -maxlags to +maxlags.

Return type:

ndarray, shape (1, 2*maxlags+1)

See also

func_xcorr

Underlying function.

partoacf(phi, theta, lagmax, var_a)[source]

Compute the theoretical ACF from ARMA polynomial coefficients.

Parameters:
  • phi (array-like) – AR coefficients \(\phi_1, \ldots, \phi_p\).

  • theta (array-like) – MA coefficients \(\theta_1, \ldots, \theta_q\).

  • lagmax (int) – Number of ACF lags to compute.

  • var_a (float) – Innovation (white-noise) variance \(\sigma_a^2\).

Returns:

  • acf (ndarray, shape (1, lagmax+1)) – Theoretical ACF from lag 0 to lagmax.

  • imp (ndarray) – Impulse-response coefficients of the ARMA filter.

See also

func_partoacf

Underlying function.

parcor(acf, nump)[source]

Compute the partial autocorrelation function (PACF) from an ACF.

Parameters:
  • acf (array-like, shape (1, 2*L+1)) – Biased ACF (as returned by xcorr()).

  • nump (int) – Number of PACF lags to compute (lags 1 to nump).

Returns:

  • pacf (ndarray, shape (1, nump)) – Partial autocorrelation values at lags 1 through nump.

  • phi (ndarray) – Final Levinson–Durbin coefficient vector.

  • sigma (ndarray) – Prediction-error variances at each stage.

See also

func_parcor

Underlying function.

gpac(acf, nrows, ncols)[source]

Compute the Generalised Partial Autocorrelation (GPAC) table.

Parameters:
  • acf (array-like, shape (1, 2*L+1)) – Biased ACF (as returned by xcorr()).

  • nrows (int) – Number of GPAC rows (numerator orders 1 to nrows).

  • ncols (int) – Number of GPAC columns (denominator orders 1 to ncols).

Returns:

gpac_array – GPAC table; entries near zero suggest the corresponding (row, column) ARMA order.

Return type:

ndarray, shape (nrows, ncols)

See also

func_gpac

Underlying function.

plotgpac

Display the GPAC table as a colour-coded grid.

sdiff(y, d, p)[source]

Apply seasonal or regular differencing to a time series.

Parameters:
  • y (array-like, shape (1, N)) – Input time series.

  • d (int) – Differencing order (number of times to difference).

  • p (int) – Differencing period; use p=1 for regular differencing, p=s for seasonal differencing at period s.

Returns:

yd – Differenced series of length N - d*p.

Return type:

ndarray

See also

func_sdiff

Underlying function.

chisqrdf(q, n)[source]

Compute the chi-square cumulative distribution function.

Parameters:
  • q (float) – Chi-square statistic (non-negative).

  • n (int) – Degrees of freedom.

Returns:

pr – Probability \(P(\chi^2_n \leq q)\).

Return type:

float

See also

func_chisqrdf

Underlying function.

plotgpac(gpac, title)[source]

Display the GPAC table as a colour-coded grid plot.

Parameters:
  • gpac (ndarray, shape (nrows, ncols)) – GPAC table as returned by gpac().

  • title (str) – Figure title string.

See also

func_plotgpac

Underlying function.

gpac

Compute the GPAC table.

impest(u, y, k)[source]

Estimate the impulse response between an input and an output series.

Parameters:
  • u (array-like, shape (1, N)) – Input (excitation) time series.

  • y (array-like, shape (1, N)) – Output (response) time series.

  • k (int) – Number of impulse-response coefficients to estimate.

Returns:

g – Estimated impulse-response coefficients \(g_0, g_1, \ldots, g_{k-1}\).

Return type:

ndarray, shape (1, k)

See also

func_impest

Underlying function.

multiAnal

Full multi-variable analysis including impulse response.

uniAnal(y, na=20, nump=10, nrg=5, ncg=0, diff=[0], per=[], perdsp=1)[source]

Compute and plot the ACF, PACF, and GPAC for a univariate time series.

Parameters:
  • y (array-like) – 1-D time series.

  • na (int, optional) – Maximum lag for ACF; lags range from -na to +na. Default 20.

  • nump (int, optional) – Number of PACF lags to compute (lags 1 to nump). Default 10.

  • nrg (int, optional) – Number of GPAC rows (numerator orders). Default 5.

  • ncg (int, optional) – Number of GPAC columns (denominator orders); 0 sets it equal to nrg. Default 0.

  • diff (list of int, optional) – Differencing orders. Default [0].

  • per (list of int, optional) – Seasonal periods (one fewer element than diff). Default [].

  • perdsp (int, optional) – Display period — ACF/PACF sampled at every perdsp-th lag. Default 1.

Returns:

  • yacf (ndarray, shape (1, 2*na+1)) – Biased ACF from lag -na to +na.

  • ypacf (ndarray, shape (1, nump)) – Partial ACF from lag 1 to nump.

  • ygpac (ndarray, shape (nrg, ncg)) – GPAC table.

See also

func_uniAnal

Underlying function.

multiAnal

Input-output analysis for transfer-function identification.

multiAnal(u, y, nng=5, ndg=5, nnh=5, ndh=5, lg=20, lh=20)[source]

Compute the impulse response and correlation analysis for MISO data.

Parameters:
  • u (array-like, shape (n_inputs, N)) – Input time series.

  • y (array-like, shape (1, N)) – Output time series.

  • nng (int, optional) – GPAC rows for the transfer-function numerator. Default 5.

  • ndg (int, optional) – GPAC columns for the transfer-function numerator. Default 5.

  • nnh (int, optional) – GPAC rows for the noise model. Default 5.

  • ndh (int, optional) – GPAC columns for the noise model. Default 5.

  • lg (int, optional) – Maximum lag for the transfer-function impulse response. Default 20.

  • lh (int, optional) – Maximum lag for the noise-model ACF. Default 20.

Returns:

  • g (ndarray) – Estimated transfer-function impulse-response coefficients.

  • rv (ndarray) – Residual variance at each lag.

  • g_gpac (ndarray) – GPAC table for the transfer function.

  • h_gpac (ndarray) – GPAC table for the noise model.

See also

func_multiAnal

Underlying function.

uniAnal

Univariate analysis (single series).

gcombvec(a1, *argv)[source]

Generate all combinations of the columns of input arrays.

Parameters:
  • a1 (ndarray) – First array whose columns are combined.

  • *argv (ndarray) – Additional arrays; their columns are combined with those of a1.

Returns:

y – Matrix where each column is one combination of input columns.

Return type:

ndarray

See also

func_gcombvec

Underlying function.

func_selpmod

Uses gcombvec for model-order grid search.