def create_dataset(self, opt, means_x, std_x, name): means_x = list(means_x) variances_x = [np.eye(2) * std_x for _ in means_x] priors_x = [1.0 / len(means_x) for _ in means_x] dataset_x = sample_GMM(opt.dataset_size_x, means_x, variances_x, priors_x, sources=('features', )) save_path_x = opt.result_dir + name # plot_GMM(dataset, save_path) ## reconstruced x X_dataset = dataset_x.data['samples'] X_targets = dataset_x.data['label'] self.set_means(means_x) self.set_priors(priors_x) self.set_variances(variances_x) self.set_dataset(X_dataset) fig_mx, ax = plt.subplots(nrows=1, ncols=1, figsize=(4.5, 4.5)) ax.scatter(X_dataset[:, 0], X_dataset[:, 1], c=cm.Set1(X_targets.astype(float) / opt.input_dim / 2.0), edgecolor='none', alpha=0.5) ax.set_xlim(-3, 3) ax.set_ylim(-3.5, 3.5) ax.set_xlabel('$x_1$') ax.set_ylabel('$x_2$') ax.axis('on') plt.savefig(save_path_x, transparent=True, bbox_inches='tight')
def create_dataset_test(self, opt, std_x, name): variances_x = self.get_variances() priors_x = self.get_priors() means_x = self.get_means() # create X dataset datasetX_test = sample_GMM(opt.dataset_size_x_test, means_x, variances_x, priors_x, sources=('features', )) save_path = opt.result_dir + name # plot_GMM(dataset, save_path) ## reconstruced x X_np_data_test = datasetX_test.data['samples'] X_targets_test = datasetX_test.data['label'] self.set_dataset_test(X_np_data_test) self.set_label_test(X_targets_test) fig_mx, ax = plt.subplots(nrows=1, ncols=1, figsize=(4.5, 4.5)) ax.scatter(X_np_data_test[:, 0], X_np_data_test[:, 1], c=cm.Set1( X_targets_test.astype(float) / opt.input_dim / 2.0), edgecolor='none', alpha=0.5) ax.set_xlim(-3, 3) ax.set_ylim(-3.5, 3.5) ax.set_xlabel('$x_1$') ax.set_ylabel('$x_2$') ax.axis('on') plt.savefig(save_path, transparent=True, bbox_inches='tight')
# means = map(lambda x: np.array(x), [[0, 0]]) means_x = map(lambda x: np.array(x), [[0, 0], [2, 2], [-2, -2], [2, -2], [-2, 2]]) means_x = list(means_x) std_x = 0.04 variances_x = [np.eye(2) * std_x for _ in means_x] priors_x = [1.0/len(means_x) for _ in means_x] gaussian_mixture = GMM_distribution(means=means_x, variances=variances_x, priors=priors_x) dataset_x = sample_GMM(dataset_size_x, means_x, variances_x, priors_x, sources=('features', )) save_path_x = result_dir + 'X_gmm_data_train.pdf' # plot_GMM(dataset, save_path) ## reconstruced x X_dataset = dataset_x.data['samples'] X_targets = dataset_x.data['label'] fig_mx, ax = plt.subplots(nrows=1, ncols=1, figsize=(4.5, 4.5)) ax.scatter(X_dataset[:, 0], X_dataset[:, 1], c=cm.Set1(X_targets.astype(float)/input_dim/2.0), edgecolor='none', alpha=0.5) ax.set_xlim(-3, 3); ax.set_ylim(-3.5, 3.5) ax.set_xlabel('$x_1$'); ax.set_ylabel('$x_2$') ax.axis('on') plt.savefig(save_path_x, transparent=True, bbox_inches='tight')
""" Create dataset """ # create X dataset means_x = map(lambda x: np.array(x), [[0, 0], [2, 2], [-2, -2], [2, -2], [-2, 2]]) means_x = list(means_x) std_x = 0.04 variances_x = [np.eye(2) * std_x for _ in means_x] priors_x = [1.0/len(means_x) for _ in means_x] dataset_x = sample_GMM(dataset_size_x, means_x, variances_x, priors_x, sources=('features', )) save_path_x = result_dir + 'X_train.png' # plot x X_dataset = dataset_x.data['samples'] X_targets = dataset_x.data['label'] fig_mx, ax = plt.subplots(nrows=1, ncols=1, figsize=(4.5, 4.5)) ax.scatter(X_dataset[:, 0], X_dataset[:, 1], c=cm.Set1(X_targets.astype(float)/x_dim/2.0), edgecolor='none', alpha=0.5) ax.set_xlim(-3, 3); ax.set_ylim(-3.5, 3.5) ax.set_xlabel('$x$ train') ax.axis('on') plt.savefig(save_path_x, transparent=True, bbox_inches='tight') # create Y dataset