def test_margin(distributions, reduction): np.random.seed(1337) margin = Margin(reduction=reduction) marg = margin(distributions) assert np.all(marg == [1, 2, 0]), "Margin is not right {}".format(marg) margin = Margin(shuffle_prop=0.9, reduction=reduction) marg = margin(distributions) assert np.any(marg != [1, 2, 0])
def test_heuristics_reorder_list(): # we are just testing if given calculated uncertainty measures for chunks of data # the `reorder_indices` would make correct decision. Here index 0 has the # highest uncertainty chosen but both methods (uncertainties1 and uncertainties2) streaming_prediction = [np.array([0.98]), np.array([0.87, 0.68]), np.array([0.96, 0.54])] heuristic = BALD() ranks = heuristic.reorder_indices(streaming_prediction) assert np.all(ranks == [0, 3, 1, 2, 4]), "reorder list for BALD is not right {}".format(ranks) heuristic = Variance() ranks = heuristic.reorder_indices(streaming_prediction) assert np.all(ranks == [0, 3, 1, 2, 4]), "reorder list for Variance is not right {}".format( ranks) heuristic = Entropy() ranks = heuristic.reorder_indices(streaming_prediction) assert np.all(ranks == [0, 3, 1, 2, 4]), "reorder list for Entropy is not right {}".format( ranks) heuristic = Margin() ranks = heuristic.reorder_indices(streaming_prediction) assert np.all(ranks == [4, 2, 1, 3, 0]), "reorder list for Margin is not right {}".format(ranks) heuristic = Certainty() ranks = heuristic.reorder_indices(streaming_prediction) assert np.all(ranks == [4, 2, 1, 3, 0]), "reorder list for Certainty is not right {}".format( ranks) heuristic = Random() ranks = heuristic.reorder_indices(streaming_prediction) assert ranks.size == 5, "reorder list for Random is not right {}".format( ranks)