def _cmeans0(data, u_old, c, m, metric): """ Single step in generic fuzzy c-means clustering algorithm. Modified from Ross, Fuzzy Logic w/Engineering Applications (2010), pages 352-353, equations 10.28 - 10.35. Parameters inherited from cmeans() """ # Normalizing, then eliminating any potential zero values. u_old = normalize_columns(u_old) u_old = np.fmax(u_old, np.finfo(np.float64).eps) um = u_old**m # Calculate cluster centers data = data.T cntr = um.dot(data) / np.atleast_2d(um.sum(axis=1)).T d = _distance(data, cntr, metric) d = np.fmax(d, np.finfo(np.float64).eps) jm = (um * d**2).sum() u = normalize_power_columns(d, -2. / (m - 1)) return cntr, u, jm, d
def _cmeans_predict0(test_data, cntr, u_old, c, m, metric): """ Single step in fuzzy c-means prediction algorithm. Clustering algorithm modified from Ross, Fuzzy Logic w/Engineering Applications (2010) p.352-353, equations 10.28 - 10.35, but this method to generate fuzzy predictions was independently derived by Josh Warner. Parameters inherited from cmeans() Very similar to initial clustering, except `cntr` is not updated, thus the new test data are forced into known (trained) clusters. """ # Normalizing, then eliminating any potential zero values. u_old = normalize_columns(u_old) u_old = np.fmax(u_old, np.finfo(np.float64).eps) um = u_old**m test_data = test_data.T # For prediction, we do not recalculate cluster centers. The test_data is # forced to conform to the prior clustering. d = _distance(test_data, cntr, metric) d = np.fmax(d, np.finfo(np.float64).eps) jm = (um * d**2).sum() u = normalize_power_columns(d, -2. / (m - 1)) return u, jm, d
def _pfcm0(data, centers_old, gamma, c, m, eta, a, b): """ Single step of pfcm""" dist = _distance(data, centers_old) dist = np.fmax(dist, np.finfo(np.float64).eps ) #Nullen vorsichtshalber durch minimum Wert ersetzen" #Zugehörigkeitsgrade berechnen (u_i_k) u = normalize_power_columns(dist, -2. / (m - 1)) #Berechnung der Typischkeitswerte #Wichtige Funktionen: #np.reciprocal: reciprocal(x) entspricht 1/x, nur Elementweise #np.ones: Matrix mit Dimension (x,y) mit Einsen gefüllt, x Anzahl der Zeilen, y Spalten # Compute typicality values d2 = dist**2 d2 = np.fmax(d2, np.finfo(np.float64).eps) t = np.reciprocal( np.add(np.ones((c, data.shape[0])), (np.divide(np.multiply(d2, b).T, gamma).T**(1. / (eta - 1))))) #Clusterzentroiden berechnen (v_i) #ut entspricht der Summe (a*u_i_k**m + b*t_i_k**eta) ut = np.add(np.multiply((u**m), a), np.multiply((t**eta), b)) centers = np.divide((ut.dot(data)).T, (ut.sum(axis=1)).T).T #Berechnung der Zielfunktion J_m_eta d_new = _distance(data, centers) d_new = np.fmax(d_new, np.finfo(np.float64).eps) d_new = d_new**2 d_new = np.fmax(d_new, np.finfo(np.float64).eps) jm = np.multiply(ut, d_new).sum() + np.multiply(gamma, (np.subtract( np.ones((c, data.shape[0])), t)**eta).sum(axis=1).T).sum() return centers, u, t, jm