cov = [[0.02, 0], [0, 0.02]] K = 50 x, y = np.random.multivariate_normal(mean, cov, K).T x = np.stack((x, y), axis=1).clip(-0.99, 0.99) use_gpu = False if use_gpu and torch.cuda.is_available(): device = 'cuda:0' else: device = 'cpu' x1 = torch.from_numpy(x1) x2 = torch.from_numpy(x2) x = torch.from_numpy(x) vwb = VWB(x, [x1, x2], device=device, verbose=False) output = vwb.cluster(max_iter_h=5000, max_iter_p=1) idx = output['idx'] xmin, xmax, ymin, ymax = -1.0, 1.0, -0.5, 0.5 for k in [33]: plt.figure(figsize=(8, 4)) for i in range(2): ce = np.array(plt.get_cmap('viridis')(idx[i].cpu().numpy() / (K - 1))) utils.scatter_otsamples(vwb.data_p, vwb.data_e[i], size_p=30, marker_p='o', color_x=ce, xmin=xmin,
fig6.savefig("x3_histogram_kmeans1.png", dpi=300, bbox_inches='tight') # -------------- VWB ------------------ # use_gpu = False if use_gpu and torch.cuda.is_available(): device = 'cuda:0' else: device = 'cpu' x1 = torch.from_numpy(x1.clip(-0.99, 0.99)) x2 = torch.from_numpy(x2.clip(-0.99, 0.99)) x3 = torch.from_numpy(x3.clip(-0.99, 0.99)) x = torch.from_numpy(C1_16.clip(-0.99, 0.99)) vwb = VWB(x, [x1], device=device, verbose=False) output = vwb.cluster(lr=1, max_iter_h=5000, max_iter_p=1) e_idx = output['idx'] x1_vwb_16 = vwb.data_p[e_idx[0], :].cpu().numpy() x1_vwb_16 = np.transpose(np.reshape(x1_vwb_16 * 255, (128, 128, 3)), (1, 0, 2)) imageio.imwrite("x1_vwb_16.png", x1_vwb_16) fig1 = plt.figure(figsize=(8, 8)) ax1 = fig1.add_subplot(111, projection='3d') ce2 = vwb.data_p[e_idx].numpy() p11 = vwb.data_p.numpy() ax1.scatter(x1[:, 0], x1[:, 1], x1[:, 2], s=dot_size, color=ce2, alpha=alpha) ax1.xaxis.pane.fill = False ax1.yaxis.pane.fill = False ax1.zaxis.pane.fill = False ax1.scatter(p11[:, 0], p11[:, 1],
x1 = torch.from_numpy(x1).double().to(device) x2 = torch.from_numpy(x2).double().to(device) wd = np.zeros((50, 50)) k = 0 for K in [50, 125, 250, 500, 750, 1000, 1500, 2500]: for i in range(10): mean = [0.0, -0.5] cov = [[0.02, 0], [0, 0.02]] x, y = np.random.multivariate_normal(mean, cov, K).T x = np.stack((x, y), axis=1).clip(-0.99, 0.99) x = torch.from_numpy(x).double().to(device) vwb = VWB(x, [x1, x2], device=device, verbose=False) output = vwb.cluster(lr=1, max_iter_h=10000, max_iter_p=1, beta=0.9, lr_decay=500) wd[k, i] = output['wd'] print(output['wd']) # np.savetxt(f, output['wd'], delimiter=',') del x del vwb k += 1 # np.savetxt('ship_error/K_total.csv', wd, delimiter=',') import ot
use_gpu = False if use_gpu and torch.cuda.is_available(): device = 'cuda:0' else: device = 'cpu' # ---------------VWB--------------- x = newx for reg in [0.5, 2, 1e9]: x_copy = torch.from_numpy(x) x0_copy = torch.from_numpy(x0) vwb = VWB(x_copy, [x0_copy], device=device, verbose=False) output = vwb.cluster(lr=0.5, max_iter_h=1000, max_iter_p=1, beta=0.5, reg=reg) e_idx = output['idx'] fig = plt.figure(figsize=(4, 4)) ce = color_map[e_idx[0]] utils.scatter_otsamples(vwb.data_p, vwb.data_e[0], size_p=30, marker_p='o', color_e=ce,
cur_axes = plt.gca() cur_axes.axes.get_xaxis().set_ticks([]) cur_axes.axes.get_yaxis().set_ticks([]) # plt.savefig("euclidean_center.svg", bbox_inches='tight') plt.savefig("euclidean_center.png", dpi=300, bbox_inches='tight') # VWB use_gpu = False if use_gpu and torch.cuda.is_available(): device = 'cuda:0' else: device = 'cpu' ell_all = [torch.from_numpy(ell).t() for ell in ell_all] vwb = VWB(ell_all[0][0:-1:5, :], ell_all, device=device, verbose=False) output = vwb.cluster(lr=0.5, max_iter_h=3000, max_iter_p=1) e_idx = output['idx'] fig = plt.figure(4, figsize=(2, 2)) ax = fig.add_subplot(111) plt.grid(True) for i in range(N): plt.plot(vwb.data_e[i][:, 0], vwb.data_e[i][:, 1], linewidth=5, c='lightgray') size = vwb.data_p.shape[0] // 2 ax.set_prop_cycle(