fuzzyclust.models.TakagiSugeno#
- class fuzzyclust.models.TakagiSugeno(n_clusters=3, m=2.0, antecedent='gaussian_axis_parallel', consequent='local', antecedent_features=None, gamma=0.0, beta=1000000000000000.0, tol=0.0001, max_iter=300, init='kmeans++', n_init=1, restart_criterion='likelihood', random_state=None, verbose=0)[source]#
Bases:
RegressorMixin,BaseEstimatorTakagi–Sugeno (TS) fuzzy model with rules extracted from fuzzy clusters.
The model consists of \(c\) rules
\[R_i:\ \text{If } x_1 \text{ is } A_{i1}(x_1) \text{ and } \dots \text{ and } x_n \text{ is } A_{in}(x_n) \text{ then } \hat y_i = \mathbf{a}_i^T\mathbf{x} + b_i,\ [w_i]\]with Gaussian antecedent sets \(A_{ij}(x_j)=\exp(-\tfrac12 (x_j-v_{ij})^2/\sigma_{ij}^2)\), aggregated by the fuzzy-mean formula with the firing strengths \(\beta_i(\mathbf{x})=w_i\prod_j A_{ij}(x_j)\):
\[\hat y(\mathbf{x}) = \frac{\sum_{i=1}^{c}\beta_i(\mathbf{x})\,(\mathbf{a}_i^T\mathbf{x}+b_i)} {\sum_{i=1}^{c}\beta_i(\mathbf{x})}.\]Three ways of obtaining the antecedents from clusters in the product space \(\mathbf{z}=[\mathbf{x}^T\,y]^T\) are offered:
"gaussian_axis_parallel": the modified Gath–Geva clustering of [1] (ModifiedGG). The clusters are axis-parallel Gaussians in the input space, so the antecedent sets are the clusters and no projection error arises; the rule weights \(w_i=\alpha_i\prod_j(2\pi\sigma^2_{ij})^{-1/2}\) come out of the clustering."gg_projected": Gath–Geva clustering of \(\mathbf{z}\) followed by the axis-orthogonal projection of the (oblique) Gaussian clusters, \(\sigma^2_{ij}=[\mathbf{F}^{xx}_i]_{jj}\), with the rule weights \(w_i=\alpha_i/\big((2\pi)^{n/2}\sqrt{\det\mathbf{F}^{xx}_i}\big)\) of [1] (eq. 17). This is the classical GG route to a TS model; the projection of an oblique ellipsoid introduces a decomposition error."gk_projected": Gustafson–Kessel clustering of \(\mathbf{z}\) and the same projection [3]; GK finds clusters of equal volume and has no priors, so all rule weights are one.
- Parameters:
- n_clusters
int, default=3 Number of rules \(c\).
- m
float, default=2.0 Fuzziness exponent of the clustering.
- antecedent{“gaussian_axis_parallel”, “gg_projected”, “gk_projected”}, default=”gaussian_axis_parallel”
Clustering engine and antecedent extraction (see above).
- consequent{“local”, “global”, “tls”}, default=”local”
Estimation of the local linear models.
"local": weighted least squares per rule with the cluster memberships as weights (the local models are local linearizations, interpretable, [1] eq. 22)."global": one least-squares problem for all consequents with the normalized firing strengths as regressor weights (best global prediction, local interpretation lost)."tls": total least squares from the eigenvector of the smallest eigenvalue of the product-space cluster covariance ([1] eq. 26, [3]), the hyperplane the cluster lies on.- antecedent_featuresarray_like
ofint,optional Columns of
Xused in the antecedents (scheduling variables); the consequents always use all columns.None: all inputs.- gamma
float, default=0.0 - beta
float, default=1e15 Covariance (variance) regularization of the clustering engine, see
GK,GGandModifiedGG(betais ignored by the latter).- tol
float, default=1e-4 - max_iter
int, default=300 - init{“random”, “kmeans++”}
orndarray, default=”kmeans++” Initialization of the clustering engine (an initial partition of shape
(n_samples, n_clusters)or initial centers are accepted; for the projected variants initial centers live in the product space).- n_init
int, default=1 Number of restarts of the clustering engine.
- restart_criterion{“likelihood”, “error”}, default=”likelihood”
How
ModifiedGGranks its restarts (ignored by the projected variants, whose engines keep the run with the lowest \(J\)).- random_state
int,RandomStateinstanceorNone, default=None - verbose
int, default=0
- n_clusters
- Attributes:
- clusterer_
fittedModifiedGG,GGorGK The clustering engine.
- centers_
ndarrayofshape(n_clusters,n_antecedent) Centers \(v_{ij}\) of the antecedent sets.
- sigmas_
ndarrayofshape(n_clusters,n_antecedent) Standard deviations \(\sigma_{ij}\) of the antecedent sets.
- rule_weights_
ndarrayofshape(n_clusters,) \(w_i\) (from the cluster priors and variances for the modified GG engine, all one for the GK engine).
- local_models_
ndarrayofshape(n_clusters,n_features+ 1,n_outputs) \(\boldsymbol\theta_i=[\mathbf{a}_i^T\,b_i]^T\).
- coef_
ndarrayofshape(n_clusters,n_features)or(n_clusters,n_outputs,n_features) - intercept_
ndarrayofshape(n_clusters,)or(n_clusters,n_outputs) - membership_
ndarrayofshape(n_samples,n_clusters) Fuzzy partition of the training data in the product space.
- n_outputs_
int - antecedent_features_
ndarrayofint - n_iter_
int Iterations of the clustering engine.
- clusterer_
References
[1] (1,2,3,4)J. Abonyi, R. Babuška, F. Szeifert, “Modified Gath–Geva fuzzy clustering for identification of Takagi–Sugeno fuzzy models”, IEEE Trans. Systems, Man and Cybernetics B, 32(5), 612–621, 2002.
[2]T. Takagi, M. Sugeno, “Fuzzy identification of systems and its applications to modeling and control”, IEEE Trans. Systems, Man and Cybernetics, 15(1), 116–132, 1985.
Examples
>>> from fuzzyclust.models import TakagiSugeno, make_sinc >>> X, y = make_sinc(n_samples=200, random_state=0) >>> ts = TakagiSugeno(n_clusters=4, random_state=0).fit(X, y) >>> round(ts.score(X, y), 2) > 0.9 True >>> ts.rule_base().shape[0] 4
- antecedent_membership(X)[source]#
Univariate antecedent memberships \(A_{ij}(x_j)\).
Returns an array of shape
(n_samples, n_clusters, n_antecedent).
- describe(feature_names=None, digits=3)[source]#
Linguistic listing of the rules (
If x1 is N(v, sigma) and ... then y = ...).
- firing_strengths(X, normalize=True)[source]#
Firing strengths \(\beta_i(\mathbf{x})=w_i\prod_j A_{ij}(x_j)\) (normalized by default).
- fit(X, y=None)[source]#
Identify the rule base from input–output data.
- Parameters:
- Xarray_like
ofshape(n_samples,n_features) - yarray_like
ofshape(n_samples,)or(n_samples,n_outputs) Required (
Noneraises aValueError).
- Xarray_like
- Returns:
- self
object
- self
- local_predict(X)[source]#
Outputs of the local linear models, shape
(n_samples, n_clusters[, n_outputs]).
Examples using fuzzyclust.models.TakagiSugeno#
Subtractive clustering: the number and location of clusters from density
Takagi–Sugeno model of a static nonlinearity: clusters become rules
Identification of a nonlinear dynamic system with free-run validation
MIMO Takagi–Sugeno model with local MIMO ARX consequents