コード例 #1
0
ファイル: test_best.py プロジェクト: pythiac/BTB
    def test_select_less_scores_than_k_min(self, bandit_mock):
        """If min length is lt k_min, super().compute_rewards is used.

        In this case, we expect the socres to be returned as they are.
        """

        # Set-up
        selector = BestKReward(['RF', 'SVM'])

        bandit_mock.return_value = 'SVM'

        # Run
        choice_scores = {
            'DT': [0.7, 0.75, 0.73],
            'RF': [0.8],
            'SVM': [0.9, 0.95, 0.93],
        }
        best = selector.select(choice_scores)

        # Assert
        assert best == 'SVM'

        choice_rewards = {
            'RF': [0.8],
            'SVM': [0.9, 0.95, 0.93],
        }
        bandit_mock.assert_called_once_with(choice_rewards)
コード例 #2
0
ファイル: test_best.py プロジェクト: pythiac/BTB
    def test_select_more_scores_than_k_min(self, bandit_mock):
        """If min length is gt k_min, self.compute_rewards is used.

        In this case, we expect the lower scores to be nan.
        """

        # Set-up
        selector = BestKReward(['RF', 'SVM'])

        bandit_mock.return_value = 'SVM'

        # Run
        choice_scores = {
            'DT': [0.7, 0.75, 0.73],
            'RF': [0.8, 0.85, 0.83],
            'SVM': [0.9, 0.95, 0.93],
        }
        best = selector.select(choice_scores)

        # Assert
        assert best == 'SVM'

        choice_rewards_expected = {
            'RF': [np.nan, 0.85, 0.83],
            'SVM': [np.nan, 0.95, 0.93],
        }
        # TODO
        (choice_rewards, ), _ = bandit_mock.call_args
        assert choice_rewards.keys() == choice_rewards_expected.keys()
        for k in choice_rewards:
            assert k in choice_rewards_expected
            np.testing.assert_array_equal(choice_rewards[k],
                                          choice_rewards_expected[k])
コード例 #3
0
ファイル: test_best.py プロジェクト: wuqixiaobai/BTB
    def test_select_less_scores_than_k_min(self, bandit_mock):
        """If min length is lt k_min, super().compute_rewards is used.

        In this case, we expect the socres to be returned as they are.
        """

        # Set-up
        selector = BestKReward(['RF', 'SVM'])

        bandit_mock.return_value = 'SVM'

        # Run
        choice_scores = {
            'DT': [0.7, 0.75, 0.73],
            'RF': [0.8],
            'SVM': [0.9, 0.95, 0.93],
        }
        best = selector.select(choice_scores)

        # Assert
        assert best == 'SVM'

        choice_rewards = {
            'RF': [0.8],
            'SVM': [0.9, 0.95, 0.93],
        }
        bandit_mock.assert_called_once_with(choice_rewards)
コード例 #4
0
ファイル: test_best.py プロジェクト: csala/BTB_test
    def test_select_more_scores_than_k_min(self, bandit_mock):
        """If min length is gt k_min, self.compute_rewards is used.

        In this case, we expect the lower scores to be zeroed.
        """

        # Set-up
        selector = BestKReward(['RF', 'SVM'])

        bandit_mock.return_value = 'SVM'

        # Run
        choice_scores = {
            'DT': [0.7, 0.75, 0.73],
            'RF': [0.8, 0.85, 0.83],
            'SVM': [0.9, 0.95, 0.93],
        }
        best = selector.select(choice_scores)

        # Assert
        assert best == 'SVM'

        choice_rewards = {
            'RF': [0., 0.85, 0.83],
            'SVM': [0., 0.95, 0.93],
        }
        bandit_mock.assert_called_once_with(choice_rewards)
コード例 #5
0
ファイル: test_best.py プロジェクト: pythiac/BTB
 def test_compute_rewards_duplicates(self):
     k = 3
     choices = ['RF', 'SVM']
     scores = [0.7, 0.8, 0.7, 0.1, 0.8, 0.7]
     selector = BestKReward(choices, k=k)
     rewards = selector.compute_rewards(scores)
     np.testing.assert_array_equal(
         np.sort(rewards), np.sort([np.nan, np.nan, np.nan, 0.7, 0.8, 0.8]))
コード例 #6
0
ファイル: test_best.py プロジェクト: pythiac/BTB
    def test_compute_rewards_gt_k(self):

        # Set-up
        selector = BestKReward(['RF', 'SVM'], k=3)

        # Run
        scores = [0.83, 0.8, 0.86, 0.9]
        rewards = selector.compute_rewards(scores)

        # Assert
        np.testing.assert_array_equal(rewards, [0.83, np.nan, 0.86, 0.9])
コード例 #7
0
ファイル: test_best.py プロジェクト: pythiac/BTB
    def test_compute_rewards_lt_k(self):

        # Set-up
        selector = BestKReward(['RF', 'SVM'], k=3)

        # Run
        scores = [0.8, 0.9]
        rewards = selector.compute_rewards(scores)

        # Assert
        assert rewards == scores
コード例 #8
0
ファイル: test_best.py プロジェクト: wuqixiaobai/BTB
    def test_compute_rewards_gt_k(self):

        # Set-up
        selector = BestKReward(['RF', 'SVM'], k=3)

        # Run
        scores = [0.83, 0.8, 0.86, 0.9]
        rewards = selector.compute_rewards(scores)

        # Assert
        assert rewards == [0.83, 0.0, 0.86, 0.9]
コード例 #9
0
ファイル: test_best.py プロジェクト: pythiac/BTB
    def test___init__(self):

        # Run
        selector = BestKReward(['RF', 'SVM'], k=3)

        # Assert
        assert selector.choices == ['RF', 'SVM']
        assert selector.k == 3