def test_compute_02(self): np.random.seed(42) gradients = np.random.uniform(-1, 1, 30).reshape(15, 2) inputs = np.random.uniform(-1, 1, 30).reshape(15, 2) weights = np.ones((15, 1)) / 15 ss = KernelActiveSubspaces() ss.compute(inputs=inputs, gradients=gradients, weights=weights, method='exact', nboot=49, n_features=4, feature_map=None) true_evals = np.array([0.42588097, 0.19198234, 0.08228976, 0.0068496]) np.testing.assert_array_almost_equal(true_evals, ss.evals)
def test_plot_eigenvalues_03(self): np.random.seed(42) gradients = np.random.uniform(-1, 1, 200).reshape(50, 1, 4) inputs = np.random.uniform(-1, 1, 200).reshape(50, 4) weights = np.ones((50, 1)) / 50 ss = KernelActiveSubspaces() ss.compute(inputs=inputs, gradients=gradients, weights=weights, method='exact', nboot=49, n_features=8, feature_map=None) with assert_plot_figures_added(): ss.plot_eigenvalues(n_evals=3, figsize=(7, 7), title='Eigenvalues')
def test_plot_sufficient_summary_02(self): np.random.seed(42) gradients = np.random.uniform(-1, 1, 200).reshape(50, 1, 4) inputs = np.random.uniform(-1, 1, 200).reshape(50, 4) weights = np.ones((50, 1)) / 50 ss = KernelActiveSubspaces() ss.compute(inputs=inputs, gradients=gradients, weights=weights, method='exact', nboot=49, n_features=8, feature_map=None) ss.partition(3) with self.assertRaises(ValueError): ss.plot_sufficient_summary(10, 10)
def test_plot_eigenvectors_03(self): np.random.seed(42) gradients = np.random.uniform(-1, 1, 200).reshape(50, 1, 4) inputs = np.random.uniform(-1, 1, 200).reshape(50, 4) weights = np.ones((50, 1)) / 50 ss = KernelActiveSubspaces() ss.compute(inputs=inputs, gradients=gradients, weights=weights, method='exact', nboot=49, n_features=5, feature_map=None) with assert_plot_figures_added(): ss.plot_eigenvectors(n_evects=2, figsize=(5, 8), labels=[r'$x$', r'$y$', 'q', r'$r$', r'$z$'])
def test_compute_bootstrap_ranges_02(self): np.random.seed(42) gradients = np.random.uniform(-1, 1, 60).reshape(30, 1, 2) inputs = np.random.uniform(-1, 1, 60).reshape(30, 2) weights = np.ones((30, 1)) / 30 ss = KernelActiveSubspaces() ss.compute(inputs=inputs, gradients=gradients, weights=weights, method='exact', nboot=49, n_features=4, feature_map=None) true_bounds_subspace = np.array([[0.01734317, 0.09791063, 0.19840464], [0.05112582, 0.43105485, 0.92323839], [0.05890817, 0.27517302, 0.89262039]]) np.testing.assert_array_almost_equal(true_bounds_subspace, ss.subs_br)
def test_plot_sufficient_summary_03(self): np.random.seed(42) gradients = np.random.uniform(-1, 1, 200).reshape(50, 1, 4) inputs = np.random.uniform(-1, 1, 200).reshape(50, 4) weights = np.ones((50, 1)) / 50 ss = KernelActiveSubspaces() ss.compute(inputs=inputs, gradients=gradients, weights=weights, method='exact', nboot=49, n_features=8, feature_map=None) ss.partition(2) with assert_plot_figures_added(): ss.plot_sufficient_summary( np.random.uniform(-1, 1, 100).reshape(25, 4), np.random.uniform(-1, 1, 25).reshape(-1, 1))
def test_forward_01(self): np.random.seed(42) gradients = np.random.uniform(-1, 1, 30).reshape(15, 1, 2) inputs = np.random.uniform(-1, 1, 30).reshape(15, 2) weights = np.ones((15, 1)) / 15 ss = KernelActiveSubspaces() ss.compute(inputs=inputs, gradients=gradients, weights=weights, method='exact', nboot=49, n_features=4, feature_map=None) ss.partition(2) active = ss.forward(np.random.uniform(-1, 1, 4).reshape(2, 2))[0] true_active = np.array([[1.34199032, 0.02509303], [1.55021982, -0.29461026]]) np.testing.assert_array_almost_equal(true_active, active)
def test_compute_03(self): np.random.seed(42) gradients = np.random.uniform(-1, 1, 30).reshape(15, 2) inputs = np.random.uniform(-1, 1, 30).reshape(15, 2) weights = np.ones((15, 1)) / 15 ss = KernelActiveSubspaces() ss.compute(inputs=inputs, gradients=gradients, weights=weights, method='exact', nboot=49, n_features=4, feature_map=None) true_evects = np.array( [[0.74714817, 0.6155644, 0.23414206, 0.08959675], [0.35380297, -0.10917583, -0.91115623, 0.18082704], [-0.50287165, 0.76801638, -0.33072226, -0.21884635], [-0.25241469, 0.1389674, 0.07479708, 0.95466239]]) np.testing.assert_array_almost_equal(true_evects, ss.evects)
def test_compute_bootstrap_ranges_01(self): np.random.seed(42) gradients = np.random.uniform(-1, 1, 60).reshape(30, 2) inputs = np.random.uniform(-1, 1, 60).reshape(30, 2) weights = np.ones((30, 1)) / 30 ss = KernelActiveSubspaces() ss.compute(inputs=inputs, gradients=gradients, weights=weights, method='exact', nboot=49, n_features=4, feature_map=None) true_bounds_evals = np.array([[2.59177494, 7.11443789], [0.5456548, 1.94294036], [0.05855044, 0.84178668], [0.01530059, 0.187785]]) np.testing.assert_array_almost_equal(true_bounds_evals, ss.evals_br)
def test_forward_02(self): np.random.seed(42) gradients = np.random.uniform(-1, 1, 30).reshape(15, 1, 2) inputs = np.random.uniform(-1, 1, 30).reshape(15, 2) weights = np.ones((15, 1)) / 15 ss = KernelActiveSubspaces() ss.compute(inputs=inputs, gradients=gradients, weights=weights, method='exact', nboot=49, n_features=4, feature_map=None) ss.partition(2) inactive = ss.forward(np.random.uniform(-1, 1, 4).reshape(2, 2))[1] print(inactive) true_inactive = np.array([[-0.47449407, 0.51271165], [-0.27475082, 0.36433068]]) np.testing.assert_array_almost_equal(true_inactive, inactive)
def test_compute_01(self): ss = KernelActiveSubspaces() with self.assertRaises(ValueError): ss.compute()