def test_plot_points_h2_poincare_disk(self): points = self.H2.random_uniform(self.n_samples) visualization.plot(points, space='H2_poincare_disk')
def test_plot_points_s2(self): points = self.S2.random_uniform(self.n_samples) visualization.plot(points, space='S2')
x = torch.from_numpy(x).reshape((1, 3, 32, 32)).float() with torch.no_grad(): x = net(x) return entropy_loss(x, torch.zeros(1, dtype=torch.long)) fig = plt.figure(figsize=(10, 10)) ax = fig.add_subplot(111, projection='3d') sphere = Sphere() # f_points = sphere.fibonnaci_points(10000).swapaxes(0, 1) # tf_points = transformer.transform(f_points, base_point) # # print(tf_points[:, 0].min(), tf_points[:, 0].max()) # print(tf_points[:, 1].min(), tf_points[:, 1].max()) # print(tf_points[:, 2].min(), tf_points[:, 2].max()) sphere.plot_heatmap(ax=ax, n_points=10000, scalar_function=loss_f) correct_points = points[labels == 0] correct_labels = labels[labels == 0] wrong_points = points[labels != 0] wrong_labels = labels[labels != 0] plot_points = np.concatenate((correct_points[:100], wrong_points[:100])) plot_labels = np.concatenate((correct_labels[:100], wrong_labels[:100])) visualization.plot(plot_points, ax=ax, space='S2', c=plot_labels == 0, s=80, alpha=0.5) plt.show()
def test_plot_points_se3(self): points = self.SE3_GROUP.random_uniform(self.n_samples) visualization.plot(points, space='SE3_GROUP')
def main(): """Perform tangent PCA at the mean.""" fig = plt.figure(figsize=(15, 5)) hyperbolic_plane = Hyperbolic(dimension=2) data = hyperbolic_plane.random_uniform(n_samples=140) mean = FrechetMean(metric=hyperbolic_plane.metric) mean.fit(data) mean_estimate = mean.estimate_ tpca = TangentPCA(metric=hyperbolic_plane.metric, n_components=2) tpca = tpca.fit(data, base_point=mean_estimate) tangent_projected_data = tpca.transform(data) geodesic_0 = hyperbolic_plane.metric.geodesic( initial_point=mean_estimate, initial_tangent_vec=tpca.components_[0]) geodesic_1 = hyperbolic_plane.metric.geodesic( initial_point=mean_estimate, initial_tangent_vec=tpca.components_[1]) n_steps = 100 t = np.linspace(-1, 1, n_steps) geodesic_points_0 = geodesic_0(t) geodesic_points_1 = geodesic_1(t) print('Coordinates of the Log of the first 5 data points at the mean, ' 'projected on the principal components:') print(tangent_projected_data[:5]) ax_var = fig.add_subplot(121) xticks = np.arange(1, 2 + 1, 1) ax_var.xaxis.set_ticks(xticks) ax_var.set_title('Explained variance') ax_var.set_xlabel('Number of Principal Components') ax_var.set_ylim((0, 1)) ax_var.plot(xticks, tpca.explained_variance_ratio_) ax = fig.add_subplot(122) visualization.plot(mean_estimate, ax, space='H2_poincare_disk', color='darkgreen', s=10) visualization.plot(geodesic_points_0, ax, space='H2_poincare_disk', linewidth=2) visualization.plot(geodesic_points_1, ax, space='H2_poincare_disk', linewidth=2) visualization.plot(data, ax, space='H2_poincare_disk', color='black', alpha=0.7) plt.show()