예제 #1
0
 def test_rejection_sampling_inactive_01(self):
     np.random.seed(42)
     inputs = np.random.uniform(-1, 1, 60).reshape(15, 4)
     outputs = np.random.uniform(0, 5, 15)
     ss = ActiveSubspaces(dim=1, method='local', n_boot=250)
     ss.fit(inputs=inputs, outputs=outputs)
     new_inputs = np.random.uniform(-1, 1, 8).reshape(2, 4)
     active = ss.transform(new_inputs)[0]
     inactive_swap = np.array([
         ss._rejection_sampling_inactive(reduced_input=red_inp, n_points=1)
         for red_inp in active
     ])
     inactive_inputs = np.swapaxes(inactive_swap, 1, 2)
     new_inputs = ss._rotate_x(reduced_inputs=active,
                               inactive_inputs=inactive_inputs)[0]
     np.testing.assert_array_almost_equal(active, new_inputs.dot(ss.W1))
예제 #2
0
 def test_rejection_sampling_inactive_02(self):
     np.random.seed(42)
     inputs = np.random.uniform(-1, 1, 60).reshape(15, 4)
     outputs = np.random.uniform(0, 5, 15)
     ss = ActiveSubspaces()
     ss.compute(inputs=inputs, outputs=outputs, method='local', nboot=250)
     ss.partition(1)
     new_inputs = np.random.uniform(-1, 1, 8).reshape(2, 4)
     active = ss.forward(new_inputs)[0]
     inactive_swap = np.array([
         ss._rejection_sampling_inactive(reduced_input=red_inp, n_points=10)
         for red_inp in active
     ])
     inactive_inputs = np.swapaxes(inactive_swap, 1, 2)
     new_inputs = ss._rotate_x(reduced_inputs=active,
                               inactive_inputs=inactive_inputs)[0]
     np.testing.assert_array_almost_equal(np.kron(active, np.ones((10, 1))),
                                          new_inputs.dot(ss.W1))