fuzzyclust.timeseries.ChaoticPredictor#

class fuzzyclust.timeseries.ChaoticPredictor(dim=3, delay=1, n_clusters=10, m=2.0, target='scalar', gamma=0.0, beta=100000000.0, tol=0.0001, max_iter=300, init='fcm', random_state=None, verbose=0)[source]#

Bases: BaseEstimator

Operating-regime model of a chaotic series in the reconstructed state space.

A scalar measurement \(y_k\) of a deterministic system is embedded into delay vectors \(\mathbf{y}_k=[y_k,y_{k-\tau},\dots,y_{k-\tau(d_e-1)}]^T\) (Takens). Abonyi, Feil, Németh, Árva and Babuška [1] then identify the map \(\mathbf{y}_{k+1}=\mathbf{f}_r(\mathbf{y}_k)\) as an operating-regime based model

\[\hat{\mathbf{y}}_{k+1}=\sum_{i=1}^{c}\beta_i(\mathbf{y}_k)\,(\mathbf{A}_i\mathbf{y}_k+\mathbf{b}_i), \qquad \beta_i(\mathbf{y})=\frac{\exp\big(-\frac12(\mathbf{y}-\mathbf{v}_i)^T\mathbf{F}_i^{-1}(\mathbf{y}-\mathbf{v}_i)\big)} {\sum_j\exp\big(-\frac12(\mathbf{y}-\mathbf{v}_j)^T\mathbf{F}_j^{-1}(\mathbf{y}-\mathbf{v}_j)\big)},\]

whose Gaussian operating regimes and local linear models are obtained simultaneously by a modified Gath–Geva clustering of the pairs \((\mathbf{y}_k,\mathbf{y}_{k+1})\). Three questions are answered by the same clustering: the embedding dimension (from the one-step prediction error as \(d_e\) grows), the local (intrinsic) dimension (from the smallest eigenvalues of the cluster covariances) and a model for prediction.

Parameters:
dimint, default=3

Embedding dimension \(d_e\).

delayint, default=1

Lag \(\tau\) in samples.

n_clustersint, default=10

Number of local linear models \(c\) (the paper used 20).

mfloat, default=2.0

Fuzziness exponent.

target{“scalar”, “full”}, default=”scalar”

"scalar" identifies the map to the next sample \(y_{k+1}\) only (the other components of \(\mathbf{y}_{k+1}\) are past samples and are copied exactly, which is what a free-run simulation needs). "full" identifies the MIMO map \(\mathbf{y}_k\mapsto\mathbf{y}_{k+1}\) as written in the paper; with delay=1 the copied components make the error covariance singular, so the regularization beta is then essential.

gammafloat, default=0.0

Shrinkage of the fuzzy covariance matrices (see GK).

betafloat, default=1e8

Condition-number bound of \(\mathbf{F}_i\) and \(\mathbf{P}_i\).

tolfloat, default=1e-4
max_iterint, default=300
init{“fcm”, “random”} or ndarray, default=”fcm”

Initial partition: from a fuzzy c-means run on the delay vectors, a random partition, or a given membership matrix.

random_stateint, RandomState instance or None, default=None
verboseint, default=0
Attributes:
embedding_ndarray of shape (N, dim)

Delay vectors used for identification.

targets_ndarray of shape (N,) or (N, dim)
membership_ndarray of shape (N, n_clusters)
cluster_centers_ndarray of shape (n_clusters, dim)

Centers \(\mathbf{v}_i\) of the operating regimes.

covariances_ndarray of shape (n_clusters, dim, dim)

Fuzzy covariance matrices \(\mathbf{F}_i\).

local_models_ndarray of shape (n_clusters, dim + 1, n_outputs)

Parameters \(\boldsymbol{\theta}_i=[\mathbf{A}_i\ \mathbf{b}_i]^T\) (last row is the offset).

error_covariances_ndarray of shape (n_clusters, n_outputs, n_outputs)

Covariances \(\mathbf{P}_i\) of the local prediction errors.

priors_ndarray of shape (n_clusters,)
eigenvalues_ndarray of shape (n_clusters, dim)

Eigenvalues of \(\mathbf{F}_i\) in ascending order.

local_dimension_index_float

\(J^{d_e}=\sum_i p(\eta_i)\lambda_{i,\min}\), the prior-weighted smallest eigenvalue (eq. (17) of [1]); it drops sharply once \(d_e\) exceeds the local dimension of the attractor.

objective_, objective_history_, n_iter_

Notes

The distance of the modified Gath–Geva clustering is the reciprocal of a probability with three factors (eq. (10) of [1]):

\[\frac{1}{D^2_{ik}} = p(\eta_i)\, \frac{\exp\big(-\frac12(\mathbf{y}_k-\mathbf{v}_i)^T\mathbf{F}_i^{-1}(\mathbf{y}_k-\mathbf{v}_i)\big)} {(2\pi)^{d_e/2}\sqrt{\det\mathbf{F}_i}}\, \frac{\exp\big(-\frac12\mathbf{e}_{ik}^T\mathbf{P}_i^{-1}\mathbf{e}_{ik}\big)} {(2\pi)^{p/2}\sqrt{\det\mathbf{P}_i}}, \qquad \mathbf{e}_{ik}=\mathbf{y}_{k+1}-f_i(\mathbf{y}_k,\boldsymbol{\theta}_i),\]

so a sample belongs to a regime if it lies in its Gaussian and is predicted well by its local model. The alternating optimization updates \(\mathbf{v}_i\) and \(\mathbf{F}_i\) as fuzzy mean and covariance of the delay vectors, the local models by weighted least squares \(\boldsymbol{\theta}_i=(\mathbf{Y}^T\mathbf{B}_i\mathbf{Y})^{-1}\mathbf{Y}^T\mathbf{B}_i\mathbf{Y}_{(+1)}\) with \(\mathbf{B}_i=\mathrm{diag}(\mu_{i1},\dots,\mu_{iN})\), the error covariances \(\mathbf{P}_i=\sum_k\mu_{ik}^m\mathbf{e}_{ik}\mathbf{e}_{ik}^T/\sum_k\mu_{ik}^m\), the priors \(p(\eta_i)=\frac1N\sum_k\mu_{ik}\), and the partition by \(\mu_{ik}=1/\sum_j(D_{ik}/D_{jk})^{2/(m-1)}\).

References

[1] (1,2,3)

J. Abonyi, B. Feil, S. Németh, P. Árva, R. Babuška, “State-space reconstruction and prediction of chaotic time series based on fuzzy clustering”, Proc. IEEE Int. Conf. Systems, Man and Cybernetics, 2004, 2374–2379.

[2]

F. Takens, “Detecting strange attractors in turbulence”, in: Dynamical Systems and Turbulence, Lecture Notes in Mathematics 898, Springer, 1981, 366–381.

Examples

>>> from fuzzyclust.timeseries import ChaoticPredictor, make_mackey_glass
>>> x = make_mackey_glass(n_samples=800)
>>> model = ChaoticPredictor(dim=4, delay=6, n_clusters=5, random_state=0).fit(x[:600])
>>> err = model.one_step_error(x[600:])
>>> bool(err < 1e-3)
True
fit(y, X=None)[source]#

Identify the model from a scalar series y (X is ignored).

multi_step_error(y, horizons=(1, 2, 5, 10))[source]#

Mean squared free-run prediction error as a function of the horizon.

From every possible starting point of y the model is iterated \(h\) steps and compared with the true sample \(h\) steps ahead (all starting points are simulated in parallel).

Returns:
pandas.Series indexed by the horizon.
one_step_error(y)[source]#

Mean squared one-step prediction error of the next sample along y.

predict(Y)[source]#

One-step prediction for delay vectors Y.

\[\hat{\mathbf{y}}_{k+1}=\sum_{i=1}^{c}\beta_i(\mathbf{y}_k)\,f_i(\mathbf{y}_k).\]
Returns:
ndarray of shape (n_samples,) for target="scalar" or (n_samples, dim) for "full".
predict_proba(Y)[source]#

Alias of regime_membership() (the name FuzzySammon expects).

predict_series(y)[source]#

One-step predictions along a series.

Returns:
y_hat, y_truendarrays of shape (T - delay * (dim - 1) - 1,)

Predicted and true next samples, aligned.

regime_membership(Y)[source]#

Normalized Gaussian degrees of fulfilment \(\beta_i(\mathbf{y})\) (eq. (8)).

Parameters:
Yarray_like of shape (n_samples, dim)
Returns:
betandarray of shape (n_samples, n_clusters)
simulate(y_history, n_steps)[source]#

Free-run simulation: predict n_steps samples beyond the given history.

Parameters:
y_historyarray_like of shape (T,)

At least delay * (dim - 1) + 1 past samples.

n_stepsint
Returns:
ndarray of shape (n_steps,)
transform(Y)[source]#

Mahalanobis distances of delay vectors to the operating regimes.

\[d_{ik}=\sqrt{(\mathbf{y}_k-\mathbf{v}_i)^T\mathbf{F}_i^{-1}(\mathbf{y}_k-\mathbf{v}_i)}.\]

These are the distances of the Gaussian factor of the prototype; they are what FuzzySammon preserves when the clusters of the reconstructed state space are visualized.

Returns:
Dndarray of shape (n_samples, n_clusters)

Examples using fuzzyclust.timeseries.ChaoticPredictor#

State-space reconstruction and prediction of a chaotic time series

State-space reconstruction and prediction of a chaotic time series