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])
| 15 | |
| 16 | |
| 17 | def 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 | |
| 51 | def select_instance( |
no outgoing calls
no test coverage detected
searching dependent graphs…