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)