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, BaseEstimator

Takagi–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_clustersint, default=3

Number of rules \(c\).

mfloat, 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 of int, optional

Columns of X used in the antecedents (scheduling variables); the consequents always use all columns. None: all inputs.

gammafloat, default=0.0
betafloat, default=1e15

Covariance (variance) regularization of the clustering engine, see GK, GG and ModifiedGG (beta is ignored by the latter).

tolfloat, default=1e-4
max_iterint, default=300
init{“random”, “kmeans++”} or ndarray, 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_initint, default=1

Number of restarts of the clustering engine.

restart_criterion{“likelihood”, “error”}, default=”likelihood”

How ModifiedGG ranks its restarts (ignored by the projected variants, whose engines keep the run with the lowest \(J\)).

random_stateint, RandomState instance or None, default=None
verboseint, default=0
Attributes:
clusterer_fitted ModifiedGG, GG or GK

The clustering engine.

centers_ndarray of shape (n_clusters, n_antecedent)

Centers \(v_{ij}\) of the antecedent sets.

sigmas_ndarray of shape (n_clusters, n_antecedent)

Standard deviations \(\sigma_{ij}\) of the antecedent sets.

rule_weights_ndarray of shape (n_clusters,)

\(w_i\) (from the cluster priors and variances for the modified GG engine, all one for the GK engine).

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

\(\boldsymbol\theta_i=[\mathbf{a}_i^T\,b_i]^T\).

coef_ndarray of shape (n_clusters, n_features) or (n_clusters, n_outputs, n_features)
intercept_ndarray of shape (n_clusters,) or (n_clusters, n_outputs)
membership_ndarray of shape (n_samples, n_clusters)

Fuzzy partition of the training data in the product space.

n_outputs_int
antecedent_features_ndarray of int
n_iter_int

Iterations of the clustering engine.

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.

[3] (1,2)
  1. Babuška, “Fuzzy Modeling for Control”, Kluwer, Boston, 1998.

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 of shape (n_samples, n_features)
yarray_like of shape (n_samples,) or (n_samples, n_outputs)

Required (None raises a ValueError).

Returns:
selfobject
local_predict(X)[source]#

Outputs of the local linear models, shape (n_samples, n_clusters[, n_outputs]).

predict(X)[source]#

Model output (fuzzy-mean aggregation of the local models), shape (n_samples[, n_outputs]).

rule_base(feature_names=None, output_names=None)[source]#

The rule base as a table: antecedent sets (center, sigma), rule weight and consequents.

Examples using fuzzyclust.models.TakagiSugeno#

Subtractive clustering: the number and location of clusters from density

Subtractive clustering: the number and location of clusters from density

Takagi–Sugeno model of a static nonlinearity: clusters become rules

Takagi–Sugeno model of a static nonlinearity: clusters become rules

Identification of a nonlinear dynamic system with free-run validation

Identification of a nonlinear dynamic system with free-run validation

MIMO Takagi–Sugeno model with local MIMO ARX consequents

MIMO Takagi–Sugeno model with local MIMO ARX consequents