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:
objectClass 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_makerowUnderlying 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
afor autocorrelation.maxlags (int) – Maximum lag to compute; output spans lags
-maxlagsto+maxlags.flag ({'biased', 'unbiased', 'none'}) – Normalisation flag.
- Returns:
c – Cross-correlation values from lag
-maxlagsto+maxlags.- Return type:
ndarray, shape (1, 2*maxlags+1)
See also
func_xcorrUnderlying function.
- partoacf(phi, theta, lagmax, var_a)[source]
Compute the theoretical ACF from ARMA polynomial coefficients.
- Parameters:
- 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_partoacfUnderlying function.
- parcor(acf, nump)[source]
Compute the partial autocorrelation function (PACF) from an ACF.
- Parameters:
- 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_parcorUnderlying function.
- gpac(acf, nrows, ncols)[source]
Compute the Generalised Partial Autocorrelation (GPAC) table.
- Parameters:
- Returns:
gpac_array – GPAC table; entries near zero suggest the corresponding (row, column) ARMA order.
- Return type:
ndarray, shape (nrows, ncols)
- sdiff(y, d, p)[source]
Apply seasonal or regular differencing to a time series.
- Parameters:
- Returns:
yd – Differenced series of length
N - d*p.- Return type:
ndarray
See also
func_sdiffUnderlying function.
- chisqrdf(q, n)[source]
Compute the chi-square cumulative distribution function.
- Parameters:
- Returns:
pr – Probability \(P(\chi^2_n \leq q)\).
- Return type:
See also
func_chisqrdfUnderlying function.
- plotgpac(gpac, title)[source]
Display the GPAC table as a colour-coded grid plot.
- Parameters:
See also
func_plotgpacUnderlying function.
gpacCompute 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_impestUnderlying function.
multiAnalFull 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
-nato+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
-nato+na.ypacf (ndarray, shape (1, nump)) – Partial ACF from lag 1 to
nump.ygpac (ndarray, shape (nrg, ncg)) – GPAC table.
See also
func_uniAnalUnderlying function.
multiAnalInput-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_multiAnalUnderlying function.
uniAnalUnivariate 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_gcombvecUnderlying function.
func_selpmodUses
gcombvecfor model-order grid search.