def test_partition_05(self): np.random.seed(42) matrix = np.random.uniform(-1, 1, 9).reshape(3, 3) ss = KernelActiveSubspaces() ss.evects = matrix with self.assertRaises(ValueError): ss.partition(dim=4)
def test_partition_02(self): np.random.seed(42) matrix = np.random.uniform(-1, 1, 9).reshape(3, 3) ss = KernelActiveSubspaces() ss.evects = matrix ss.partition(dim=2) np.testing.assert_array_almost_equal(matrix[:, 2:], ss.W2)
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_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_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)