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, ...])

Run.

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 (parent, optional) – Reference to the parent routine. The default is None.

setupui()#

Set up UI.

Return type:

None.

combo()#

Set up combo box to choose algorithm.

Return type:

None.

settings(nodialog=False)#

Entry point into item.

Parameters:

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

Returns:

True if successful, False otherwise.

Return type:

bool

saveproj()#

Save project data from class.

Return type:

None.

update_vars()#

Update the variables.

Return type:

None.

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', ifiles=None, showlog=print, piter=iter)#

Run.

Return type:

None.

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 array) – 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 array) – 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 array) – 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 (float) – 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.

Returns:

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

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

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

  • vrc (numpy array) – Variance ration criterion.

  • nce – Normalised class entropy.

  • xbi (numpy array) – Xie beni index.

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

Fuzzy distance calculation.

Parameters:
  • cent (numpy array) – Class centers.

  • data (numpy array) – Input data.

  • uuu (numpy array) – 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:

ddd – Output data.

Return type:

numpy array

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 array) – input dataset

  • expo (float)

  • uuu (numpy array) – membership matrix (FCM) or cluster index values (k-means)

  • center (numpy array) – cluster centers

  • edist (numpy array)

Returns:

xbi – xie beni index

Return type:

numpy array