MCPcopy Create free account
hub / github.com/modAL-python/modAL / shuffled_argmax

Function shuffled_argmax

modAL/utils/selection.py:8–34  ·  view source on GitHub ↗

Shuffles the values and sorts them afterwards. This can be used to break the tie when the highest utility score is not unique. The shuffle randomizes order, which is preserved by the mergesort algorithm. Args: values: Contains the values to be selected from. n_insta

(values: np.ndarray, n_instances: int = 1)

Source from the content-addressed store, hash-verified

6
7
8def shuffled_argmax(values: np.ndarray, n_instances: int = 1) -> np.ndarray:
9 """
10 Shuffles the values and sorts them afterwards. This can be used to break
11 the tie when the highest utility score is not unique. The shuffle randomizes
12 order, which is preserved by the mergesort algorithm.
13
14 Args:
15 values: Contains the values to be selected from.
16 n_instances: Specifies how many indices and values to return.
17 Returns:
18 The indices and values of the n_instances largest values.
19 """
20 assert n_instances <= values.shape[0], 'n_instances must be less or equal than the size of utility'
21
22 # shuffling indices and corresponding values
23 shuffled_idx = np.random.permutation(len(values))
24 shuffled_values = values[shuffled_idx]
25
26 # getting the n_instances best instance
27 # since mergesort is used, the shuffled order is preserved
28 sorted_query_idx = np.argsort(shuffled_values, kind='mergesort')[
29 len(shuffled_values)-n_instances:]
30
31 # inverting the shuffle
32 query_idx = shuffled_idx[sorted_query_idx]
33
34 return query_idx, values[query_idx]
35
36
37def shuffled_argmin(values: np.ndarray, n_instances: int = 1) -> np.ndarray:

Callers 15

SVM_binary_minimumFunction · 0.90
max_lossFunction · 0.90
mean_max_lossFunction · 0.90
avg_confidenceFunction · 0.90
max_scoreFunction · 0.90
avg_scoreFunction · 0.90
vote_entropy_samplingFunction · 0.90
max_std_samplingFunction · 0.90
mc_dropout_baldFunction · 0.90
mc_dropout_mean_stFunction · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…