def plt_anyfeature_mean(ftr_name): import matplotlib.colors as mcolors color = np.zeros((m, n)) size = np.ones_like(hits) for x in range(m): for y in range(n): color[x, y] = data[ftr_name].iloc[wmix[x, y]].mean() vmax = data[ftr_name].max() vmin = data[ftr_name].min() color = np.nan_to_num(color) cbmin = color.min() cbmax = color.max() color = (color - color.min()) / (color.max() - color.min()) fig, ax = plt.subplots(1, 1, figsize=(m / 2, n / 2)) cmap = 'inferno_r' map_plot(ax, dist, color, m, n, size=size, scale=4, title=ftr_name + ' mean', cmap=cmap) norm = mcolors.Normalize(vmin=vmax, vmax=vmin) sm = plt.cm.ScalarMappable(cmap=cmap, norm=norm) sm.set_array([]) fig.subplots_adjust(right=0.75, left=0.1) cbar1 = fig.add_axes([0.8, 0.25, 0.05, 0.45]) cb = plt.colorbar(sm, cax=cbar1) cb.ax.tick_params(labelsize='x-small')
def plt_features(ftr_name): ftr = feat[case].index(ftr_name) size = np.ones_like(hits) WW = W.reshape(m * n, bneck) if pca and not acode: WW = pcomp.inverse_transform(WW) if acode: WW = ae.decode(torch.Tensor(WW)).detach().numpy() WW = scaler.inverse_transform(WW) WW = WW.reshape(m, n, nfeat) color = WW[:, :, ftr] cmin = color.min() cmax = color.max() color = (color - cmin) / (cmax - cmin) fig, ax = plt.subplots(1, 1) map_plot(ax, dist, color, m, n, size=size, scale=8, cmap='inferno_r') plt.title(ftr_name)
def plt_mapdatamean(K): color = np.zeros((m, n)) size = hits for x in range(m): for y in range(n): color[x, y] = data[K].iloc[wmix[x, y]].mean() color = np.nan_to_num(color) cbmin = color.min() cbmax = color.max() color = (color - cbmin) / (cbmax - cbmin) fig, ax = plt.subplots(1, 1) cmap = plt.cm.get_cmap('jet_r', 5) map_plot(ax, dist, color, m, n, size=size, scale=6, cmap=cmap, lcolor='black')
data_added = [] for i in range(len(data)): x, y = som.winner(data[i]) data_added.append(mapdata[x, y]) data_added = np.array(data_added) return data_added def som_addinfo(som, df, data, mapdata, mapname): assert (som.get_weights().shape[0] == mapdata.shape[0]) assert (som.get_weights().shape[1] == mapdata.shape[1]) data_added = som_adddata(som, data, mapdata) df[mapname] = data_added return df if __name__ == "__main__": from matplotlib_hex_map import matplotlib_hex_map as map_plot m = 7 n = 9 model, data = som_colortest(m, n) d = som_distances(model) hits = som_hits(model, data, m, n, log=False) wmi = model.win_map_index(data) color = model.get_weights()[:, :, :3] color = (color - color.min()) / (color.max() - color.min()) map_plot(d, color, m, n, size=hits, scale=3)
# plt.close('all') color = W.sum(axis=2) cmin = color.min() #np.min(x, axis=0) cmax = color.max() #np.max(x, axis=0) color = (color - cmin) / (cmax - cmin) if plot_hitmap: size = hits # np.ones_like(hits) fig, ax = plt.subplots(1, 1) map_plot(ax, dist, color, m, n, size=size, scale=3, cmap='inferno_r', lcolor='black') plt.title('Hit map') if plot_neighbors: f = lambda p, q: p - 0.5 if (q % 2 == 0) else p i = f(px, py) j = py plt.plot([i, i + 0.5], [j * 0.75, j * 0.75 + 0.75], 'k-') plt.plot([i, i + 1], [j * 0.75, j * 0.75], 'k-') plt.plot([i, i + 0.5], [j * 0.75, j * 0.75 - 0.75], 'k-') plt.plot([i, i - 0.5], [j * 0.75, j * 0.75 - 0.75], 'k-')