def test_transform_04(self): np.random.seed(42) inputs = np.random.uniform(-1, 1, 60).reshape(15, 4) outputs = np.random.uniform(0, 5, 15) ss = KernelActiveSubspaces(dim=2, method='local', n_boot=49) ss.fit(inputs=inputs, outputs=outputs) inactive = ss.transform(np.random.uniform(-1, 1, 8).reshape(2, 4))[1] true_inactive = np.array([[0.27110018, -0.29359021], [0.76399199, -0.02233936]]) np.testing.assert_array_almost_equal(true_inactive, inactive)
def test_transform_03(self): np.random.seed(42) inputs = np.random.uniform(-1, 1, 60).reshape(15, 4) outputs = np.random.uniform(0, 5, 45).reshape(15, 3) ss = KernelActiveSubspaces(dim=2, method='local', n_boot=50) ss.fit(inputs=inputs, outputs=outputs, metric=np.diag(np.ones(3))) active = ss.transform(np.random.uniform(-1, 1, 8).reshape(2, 4))[0] true_active = np.array([[-0.18946138, 0.31916713], [-0.25310859, -0.30280365]]) np.testing.assert_array_almost_equal(true_active, active)
def test_transform_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(dim=2, n_features=4, n_boot=49) ss.fit(inputs=inputs, gradients=gradients, weights=weights) active = ss.transform(np.random.uniform(-1, 1, 4).reshape(2, 2))[0] true_active = np.array([[0.94893046, 0.01774345], [1.09617095, -0.20832091]]) np.testing.assert_array_almost_equal(true_active, active)
def test_transform_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(dim=2, n_features=4, method='exact', n_boot=49) ss.fit(inputs=inputs, gradients=gradients, weights=weights) inactive = ss.transform(np.random.uniform(-1, 1, 4).reshape(2, 2))[1] true_inactive = np.array([[-0.33551797, 0.36254188], [-0.19427817, 0.2576207]]) np.testing.assert_array_almost_equal(true_inactive, inactive)