コード例 #1
0
 def test_forward_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()
     ss.compute(inputs=inputs, outputs=outputs, method='local', nboot=250)
     ss.partition(2)
     active = ss.forward(np.random.uniform(-1, 1, 8).reshape(2, 4))[0]
     true_active = np.array([[-0.004748, 0.331107], [-0.949099, 0.347534]])
     np.testing.assert_array_almost_equal(true_active, active)
コード例 #2
0
 def test_forward_05(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(2)
     inactive = ss.forward(np.random.uniform(-1, 1, 8).reshape(2, 4))[1]
     true_inactive = np.array([[-1.03574242, -0.04662904],
                               [-0.49850367, -0.37146678]])
     np.testing.assert_array_almost_equal(true_inactive, inactive)
コード例 #3
0
 def test_forward_04(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 = ActiveSubspaces()
     ss.compute(inputs=inputs, outputs=outputs, method='local', nboot=250)
     ss.partition(2)
     active = ss.forward(np.random.uniform(-1, 1, 8).reshape(2, 4))[0]
     true_active = np.array([[0.15284753, 0.67109407],
                             [0.69006622, -0.4165206]])
     np.testing.assert_array_almost_equal(true_active, active)
コード例 #4
0
 def test_backward_02(self):
     np.random.seed(42)
     inputs = np.random.uniform(-1, 1, 80).reshape(16, 5)
     outputs = np.random.uniform(-1, 3, 16)
     ss = ActiveSubspaces()
     ss.compute(inputs=inputs, outputs=outputs, method='local', nboot=250)
     ss.partition(2)
     new_inputs = np.random.uniform(-1, 1, 15).reshape(3, 5)
     active = ss.forward(new_inputs)[0]
     new_inputs = ss.backward(reduced_inputs=active, n_points=500)[0]
     np.testing.assert_array_almost_equal(
         np.kron(active, np.ones((500, 1))), new_inputs.dot(ss.W1))
コード例 #5
0
 def test_forward_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 = ActiveSubspaces()
     ss.compute(inputs=inputs,
                outputs=outputs,
                method='local',
                nboot=250,
                metric=np.diag(np.ones(3)))
     ss.partition(2)
     new_inputs = np.random.uniform(-1, 1, 8).reshape(2, 4)
     active, inactive = ss.forward(new_inputs)
     reconstructed_inputs = active.dot(ss.W1.T) + inactive.dot(ss.W2.T)
     np.testing.assert_array_almost_equal(new_inputs, reconstructed_inputs)
コード例 #6
0
 def test_hit_and_run_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()
     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._hit_and_run_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))