Example #1
0
 def test_catch_combos_too_large(self):
     N = int(1e6)
     k_choices = 4
     num_params = 2
     input_sample = np.random.random_sample((N, num_params))
     strategy = BruteForce()
     with raises(ValueError):
         strategy.find_most_distant(input_sample, N, num_params, k_choices)
Example #2
0
 def test_combo_from_find_most_distant(self, setup_input):
     '''
     Tests whether the correct combination is picked from the fixture drawn
     from Saltelli et al. 2008, in the solution to exercise 3a,
     Chapter 3, page 134.
     '''
     sample_inputs = setup_input
     N = 6
     num_params = 2
     k_choices = 4
     strategy = BruteForce()
     scores = strategy.find_most_distant(sample_inputs, N, num_params,
                                         k_choices)
     output = strategy.find_maximum(scores, N, k_choices)
     expected = [0, 2, 3, 5]  # trajectories 1, 3, 4, 6
     assert_equal(output, expected)
Example #3
0
    def test_scores_from_find_most_distant(self, setup_input):
        '''
        Checks whether array of scores from (6 4) is correct.

        Data is derived from Saltelli et al. 2008,
        in the solution to exercise 3a, Chapter 3, page 134.

        '''
        sample_inputs = setup_input
        N = 6
        num_params = 2
        k_choices = 4
        strategy = BruteForce()
        output = strategy.find_most_distant(sample_inputs, N, num_params,
                                            k_choices)
        expected = np.array([15.022, 13.871, 14.815, 14.582, 16.178, 14.912,
                             15.055, 16.410, 15.685, 16.098, 14.049, 15.146,
                             14.333, 14.807, 14.825],
                            dtype=np.float32)

        assert_allclose(output, expected, rtol=1e-1, atol=1e-2)