def test_partition_05(self): np.random.seed(42) matrix = np.random.uniform(-1, 1, 9).reshape(3, 3) ss = ActiveSubspaces(dim=4) ss.evects = matrix with self.assertRaises(ValueError): ss._partition()
def test_partition_02(self): np.random.seed(42) matrix = np.random.uniform(-1, 1, 9).reshape(3, 3) ss = ActiveSubspaces(dim=2) ss.evects = matrix ss._partition() np.testing.assert_array_almost_equal(matrix[:, 2:], ss.W2)
#AS ss = ActiveSubspaces(dim=1) ss.fit(inputs=x, outputs=f, gradients=df) ss.plot_eigenvalues() ss.plot_eigenvectors() ss.plot_sufficient_summary(inputs=x, outputs=f) ## Active Subspaces with vectorial outputs #process data x, f, df = x_, fa_, dfa_.reshape(n_samples, d, input_dim) print("data", x.shape, f.shape, df.shape) #vectorial AS vss = ActiveSubspaces(dim=5, n_boot=10) vss.fit(inputs=x, outputs=f, gradients=df, metric=metric) np.save("data/modes_AS", vss.W1) vss.dim = 1 vss._partition() vss.plot_eigenvalues() vss.plot_eigenvectors() components = [100 + j * 100 for j in range(16)] for i in components: img = mpimg.imread("data/component_{}.png".format(i)) plt.imshow(img) plt.axis('off') vss.plot_sufficient_summary(inputs=x, outputs=f[:, i], title="dof {}".format(i), figsize=(4, 4))