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

Function select_cold_start_instance

modAL/batch.py:17–48  ·  view source on GitHub ↗

Define what to do if our batch-mode sampling doesn't have any labeled data -- a cold start. If our ranked batch sampling algorithm doesn't have any labeled data to determine similarity among the uncertainty set, this function finds the element with highest average similarity to cold-st

(X: modALinput,
                               metric: Union[str, Callable],
                               n_jobs: Union[int, None])

Source from the content-addressed store, hash-verified

15
16
17def select_cold_start_instance(X: modALinput,
18 metric: Union[str, Callable],
19 n_jobs: Union[int, None]) -> Tuple[int, modALinput]:
20 """
21 Define what to do if our batch-mode sampling doesn't have any labeled data -- a cold start.
22
23 If our ranked batch sampling algorithm doesn't have any labeled data to determine similarity among the uncertainty
24 set, this function finds the element with highest average similarity to cold-start the batch selection.
25
26 TODO:
27 - Figure out how to test this! E.g. how to create modAL model without training data.
28 - Think of optimizing pairwise_distance call for large matrix.
29
30 Refer to Cardoso et al.'s "Ranked batch-mode active learning":
31 https://www.sciencedirect.com/science/article/pii/S0020025516313949
32
33 Args:
34 X: The set of unlabeled records.
35 metric: This parameter is passed to :func:`~sklearn.metrics.pairwise.pairwise_distances`.
36 n_jobs: This parameter is passed to :func:`~sklearn.metrics.pairwise.pairwise_distances`.
37
38 Returns:
39 Index of the best cold-start instance from `X` chosen to be labelled; record of the best cold-start instance
40 from `X` chosen to be labelled.
41 """
42 # Compute all pairwise distances in our unlabeled data and obtain the row-wise average for each of our records in X.
43 n_jobs = n_jobs if n_jobs else 1
44 average_distances = np.mean(pairwise_distances(X, metric=metric, n_jobs=n_jobs), axis=0)
45
46 # Isolate and return our best instance for labeling as the record with the least average distance.
47 best_coldstart_instance_index = np.argmin(average_distances)
48 return best_coldstart_instance_index, X[best_coldstart_instance_index].reshape(1, -1)
49
50
51def select_instance(

Callers 1

ranked_batchFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…