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:
BaseEstimatorOperating-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:
- dim
int, default=3 Embedding dimension \(d_e\).
- delay
int, default=1 Lag \(\tau\) in samples.
- n_clusters
int, default=10 Number of local linear models \(c\) (the paper used 20).
- m
float, 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; withdelay=1the copied components make the error covariance singular, so the regularizationbetais then essential.- gamma
float, default=0.0 Shrinkage of the fuzzy covariance matrices (see
GK).- beta
float, default=1e8 Condition-number bound of \(\mathbf{F}_i\) and \(\mathbf{P}_i\).
- tol
float, default=1e-4 - max_iter
int, default=300 - init{“fcm”, “random”}
orndarray, default=”fcm” Initial partition: from a fuzzy c-means run on the delay vectors, a random partition, or a given membership matrix.
- random_state
int,RandomStateinstanceorNone, default=None - verbose
int, default=0
- dim
- Attributes:
- embedding_
ndarrayofshape(N,dim) Delay vectors used for identification.
- targets_
ndarrayofshape(N,)or(N,dim) - membership_
ndarrayofshape(N,n_clusters) - cluster_centers_
ndarrayofshape(n_clusters,dim) Centers \(\mathbf{v}_i\) of the operating regimes.
- covariances_
ndarrayofshape(n_clusters,dim,dim) Fuzzy covariance matrices \(\mathbf{F}_i\).
- local_models_
ndarrayofshape(n_clusters,dim+ 1,n_outputs) Parameters \(\boldsymbol{\theta}_i=[\mathbf{A}_i\ \mathbf{b}_i]^T\) (last row is the offset).
- error_covariances_
ndarrayofshape(n_clusters,n_outputs,n_outputs) Covariances \(\mathbf{P}_i\) of the local prediction errors.
- priors_
ndarrayofshape(n_clusters,) - eigenvalues_
ndarrayofshape(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_
- embedding_
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
- 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
ythe model is iterated \(h\) steps and compared with the true sample \(h\) steps ahead (all starting points are simulated in parallel).- Returns:
pandas.Seriesindexedbythehorizon.
- 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:
ndarrayofshape(n_samples,)fortarget="scalar"or(n_samples,dim)for"full".
- predict_proba(Y)[source]#
Alias of
regime_membership()(the nameFuzzySammonexpects).
- predict_series(y)[source]#
One-step predictions along a series.
- Returns:
- y_hat, y_true
ndarraysofshape(T-delay* (dim- 1) - 1,) Predicted and true next samples, aligned.
- y_hat, y_true
- regime_membership(Y)[source]#
Normalized Gaussian degrees of fulfilment \(\beta_i(\mathbf{y})\) (eq. (8)).
- Parameters:
- Yarray_like
ofshape(n_samples,dim)
- Yarray_like
- Returns:
- beta
ndarrayofshape(n_samples,n_clusters)
- beta
- simulate(y_history, n_steps)[source]#
Free-run simulation: predict
n_stepssamples beyond the given history.- Parameters:
- y_historyarray_like
ofshape(T,) At least
delay * (dim - 1) + 1past samples.- n_steps
int
- y_historyarray_like
- Returns:
ndarrayofshape(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
FuzzySammonpreserves when the clusters of the reconstructed state space are visualized.- Returns:
- D
ndarrayofshape(n_samples,n_clusters)
- D
Examples using fuzzyclust.timeseries.ChaoticPredictor#
State-space reconstruction and prediction of a chaotic time series