pyhctsa.operations.model_fit.fit_subsegments¶
-
pyhctsa.operations.model_fit.fit_subsegments(y, model=
'ss', order=2, subset_how='rand', sample_p=(20, 0.1), random_seed='default')¶ Robustness of model parameters across different segments of a time series.
The spread of parameters obtained (including in-sample goodness of fit statistics) provides some indication of stationarity. Values of goodness of fit provide some indication of model suitability. Inherits strongly from
compare_test_sets()(hctsa’sMF_FitSubsegments).- Parameters:¶
- y : array-like¶
The input time series.
- model : str, optional¶
The model to fit in each segment of the time series:
- ’arsbc’: fits an AR model of the best order (1 to 10) by the Schwarz
Bayesian criterion (ARFIT algorithm, zero mean). Outputs are how the optimal order and the SBC vary across segments (
orders_*,sbcs_*). Theorderinput is not used.
- ’ar’: fits an AR model of a specified order by forward-backward least
squares. Outputs are how Akaike’s final prediction error (
fpe_*) and the fitted AR parameters (a_k_*, as in the polynomial 1 + a_1 z^-1 + …, the negative of the usual coefficients) vary across segments.
- ’arcrosspred’: splits the series into
sample_pnon-overlapping segments (requires
subset_how='uniform'and a scalar-likesample_p, a segment count), fits an AR model of the given order to each, and uses every segment’s model to predict, one step ahead, every segment (including itself). The result is a matrix of cross-prediction root-mean-square errors (row: predicting model, column: predicted segment), of which the spread and off-diagonal statistics are returned. NaN if any segment is shorter than5 * (order + 1)or an AR fit fails.
- ’arcrosspred’: splits the series into
- ’ss’: fits a state-space model of the given order by subspace identification
(
n4sid; the order can be'best'). Outputs are how Akaike’s final prediction error (fpe_*) varies across segments.
- ’arma’: fits an ARMA model by prediction-error minimization (
armax;order is
[p, q]). Outputs are how the FPE (fpe_*) and the fitted AR (p_k_*) and MA (q_k_*) coefficients vary across segments. (Deregistered in hctsa, as it is much like ‘ar’ and slow.)
- ’arma’: fits an ARMA model by prediction-error minimization (
Default is
'ss'.- order : int or two-vector, optional¶
The order of the model to fit (used for ‘ar’, ‘ss’, or ‘arma’ models; a two-element vector
[p, q]for ‘arma’). Default is 2.- subset_how : str, optional¶
How to choose segments from the time series, either:
’uniform’ (evenly spaced)
’spread’ (start points from the golden-ratio sequence
frac(j*phi): deterministic and evenly spread, without the aliasing a regular spacing has with periodic series)’rand’ (at random).
Default is
'rand'.- sample_p : list, tuple or int, optional¶
A two-vector specifying how many segments to take and of what length. Of the form [n_samples, length], where length can be a proportion of the time-series length. For example, [20, 0.1] takes 20 segments of 10% the time-series length. For
model='arcrosspred', an integer (or length-1 list): the number of non-overlapping segments to partition the series into. Default is [20, 0.1].- random_seed : int, 'default', 'none' or None, optional¶
The seed of the random segment starts (
subset_how='rand'), as hctsa’sBF_RandomSeed: a number,'default'orNonefor seed 0, or'none'for a seed drawn from NumPy’s global state. The draws come from the portable generator (pyhctsa.robust.bf_random()), so they are hctsa’s. Default is'default'.
- Returns:¶
Dictionary of statistics on the spread and mean of fitted model parameters and goodness of fit across segments. For
'ar','ss'and'arma',fpe_std,fpe_mean,fpe_max,fpe_min,fpe_range(of the final prediction error); for'ar'a_k_std,a_k_mean,a_k_max,a_k_minfor each lagk, and for'arma'the same forp_k_*andq_k_*. For'arcrosspred':std,range,iqr(over all entries of the cross-prediction error matrix),stdoffdiag,rangeoffdiag,iqroffdiag(over the positive off-diagonal entries),stdmean,rangemean,stdmedian,rangemedian(across predicted segments, of the mean and of the median error),rangerange,stdrange,rangestd,stdstd(across predicted segments, of the range or standard deviation of the errors) andmineig(smallest real part of the eigenvalues of the matrix).- Return type:¶
dict