pygmi.clust.fuzzy_clust#

Fuzzy clustering is a set of clustering routines.

This makes use of fuzzy logic.

Classes#

FuzzyClust

Fuzzy clustering GUI class.

Functions#

fuzzyclust(data[, cltype, min_cluster, max_cluster, ...])

Fuzzy Clustering.

fuzzy_means(data, no_clust, init, centfix, maxit, ...)

Fuzzy clustering.

fuzzy_dist(cent, data, uuu, expo, cltype, cov_constr)

Fuzzy distance calculation.

xie_beni(data, expo, uuu, center, edist)

Calculate the Xie-Beni index.

Module Contents#

class pygmi.clust.fuzzy_clust.FuzzyClust(parent=None)#

Bases: pygmi.misc.BasicModule

Fuzzy clustering GUI class.

Parameters:

parent – Reference to the parent routine. The default is None.

setupui()#

Set up UI.

combo()#

Set up combo box to choose algorithm.

initchange()#

Set up radio button to choose initialisation type.

settings(nodialog=False)#

Entry point into item.

Parameters:

nodialog (bool) – Run settings without a dialog. The default is False.

Returns:

True if successful, False otherwise.

Return type:

bool

saveproj()#

Save project data from class.

update_vars()#

Update the variables.

pygmi.clust.fuzzy_clust.fuzzyclust(data, cltype='fuzzy c-means', min_cluster=5, max_cluster=5, cov_constr=0.0, no_runs=1, max_iter=100, expo=1.5, term_thresh=1e-05, init_type='random', showlog=print, piter=iter)#

Fuzzy Clustering.

Parameters:
  • data (list[pygmi.raster.datatypes.Data]) – List of PyGMI data.

  • cltype (str) – Clustering method, by default ‘k-means’

  • min_cluster (int) – Minimum number of clusters, by default 5

  • max_cluster (int) – Maximum number of clusters, by default 5

  • cov_constr (float) – Scalar between [0 1], by default 0.

  • no_runs (str) – Number of runs, by default 1

  • max_iter (str) – Maximum iterations, by default 100

  • expo (float) – Fuzzification exponent, by default 1.5

  • term_thresh (float) – Terminating threshold, by default 0.00001

  • init_type (str) – Initial guess, by default ‘random’

  • showlog (collections.abc.Callable[..., None]) – Show information using a function. The default is print.

  • piter (collections.abc.Iterable) – Progress bar iterator. The default is iter.

Returns:

List of raster datasets of classes.

Return type:

list of Data

pygmi.clust.fuzzy_clust.fuzzy_means(data, no_clust, init, centfix, maxit, term_thresh, expo, cltype, cov_constr, showlog=print, piter=iter)#

Fuzzy clustering.

Finds NO_CLUST clusters in the data set DATA.. Supported algorithms are fuzzy c-means, Gustafson-Kessel, advanced fuzzy c-means.

Parameters:
  • data (numpy.typing.NDArray) – DATA is size M-by-N, where M is the number of samples and N is the number of coordinates (attributes) for each sample.

  • no_clust (int) – Number of clusters.

  • init (numpy.typing.NDArray) – INIT may be set to [], in this case the FCM generates random initial center locations to start the algorithm. Alternatively, INIT can be of matrix type, either containing a user-given membership matrix [NO_CLUST M] or a cluster center matrix [NO_CLUST, N].

  • centfix (numpy.typing.NDArray) – Constrains the position of cluster centers.

  • maxit (int) – MAXIT give the maximum number of iterations.

  • term_thresh (float) – Gives the required minimum improvement in per cent per iteration. (termination threshold)

  • expo (float) – Fuzzification exponent.

  • cltype (str) – either ‘FCM’ for fuzzy c-means (spherically shaped clusters), ‘DET’ for advanced fuzzy c-means (ellipsoidal clusters, all clusters use the same ellipsoid), or ‘GK’ for Gustafson-Kessel clustering (ellipsoidal clusters, each cluster uses its own ellipsoid).

  • cov_constr (numpy.typing.NDArray) – COV_CONSTR applies only to the GK algorithm. constrains the cluster shape towards spherical clusters to avoid needle-like clusters. COV_CONSTR = 1 make the GK algorithm equal to the FCM algorithm, COV_CONSTR = 0 results in no constraining of the covariance matrices of the clusters.

  • showlog (collections.abc.Callable[..., None]) – Display information. The default is print.

  • piter (collections.abc.Iterable) – Progress bar iterator. The default is iter.

Returns:

  • uuu – This membership function matrix contains the grade of membership of each data sample to each cluster.

  • cent – The coordinates for each cluster center are returned in the rows of the matrix CENT.

  • obj_fcn – At each iteration, an objective function is minimized to find the best location for the clusters and its values are returned in OBJ_FCN.

  • xbi – Xie beni index.

Return type:

tuple[numpy.typing.NDArray | list, numpy.typing.NDArray | None, numpy.typing.NDArray, numpy.typing.NDArray]

pygmi.clust.fuzzy_clust.fuzzy_dist(cent, data, uuu, expo, cltype, cov_constr)#

Fuzzy distance calculation.

Parameters:
  • cent (numpy.typing.NDArray) – Class centers.

  • data (numpy.typing.NDArray) – Input data.

  • uuu (numpy.typing.NDArray) – Membership function matrix.

  • expo (float) – Fuzzification exponent.

  • cltype (str) – Clustering type.

  • cov_constr (float) – Applies only to the GK algorithm. constrains the cluster shape towards spherical clusters.

Returns:

Output data.

Return type:

ndarray

pygmi.clust.fuzzy_clust.xie_beni(data, expo, uuu, center, edist)#

Calculate the Xie-Beni index.

Accepts missing values when given as nan elements in the data base). A small Xie-Beni index is optimal.

Parameters:
  • data (numpy.typing.NDArray) – Input dataset

  • expo (float) – Fuzzification exponent.

  • uuu (numpy.typing.NDArray) – Membership matrix (FCM) or cluster index values (k-means)

  • center (numpy.typing.NDArray) – Cluster centers

  • edist (numpy.typing.NDArray) – Euclidean distances/

Returns:

Xie beni index

Return type:

ndarray