Calculates the information density metric of the given data using the given metric. Args: X: The data for which the information density is to be calculated. metric: The metric to be used. Should take two 1d numpy.ndarrays for argument. Todo: Should work with al
(X: modALinput, metric: Union[str, Callable] = 'euclidean')
| 31 | |
| 32 | |
| 33 | def information_density(X: modALinput, metric: Union[str, Callable] = 'euclidean') -> np.ndarray: |
| 34 | """ |
| 35 | Calculates the information density metric of the given data using the given metric. |
| 36 | |
| 37 | Args: |
| 38 | X: The data for which the information density is to be calculated. |
| 39 | metric: The metric to be used. Should take two 1d numpy.ndarrays for argument. |
| 40 | |
| 41 | Todo: |
| 42 | Should work with all possible modALinput. |
| 43 | Perhaps refactor the module to use some stuff from sklearn.metrics.pairwise |
| 44 | |
| 45 | Returns: |
| 46 | The information density for each sample. |
| 47 | """ |
| 48 | # inf_density = np.zeros(shape=(X.shape[0],)) |
| 49 | # for X_idx, X_inst in enumerate(X): |
| 50 | # inf_density[X_idx] = sum(similarity_measure(X_inst, X_j) for X_j in X) |
| 51 | # |
| 52 | # return inf_density/X.shape[0] |
| 53 | |
| 54 | similarity_mtx = 1/(1+pairwise_distances(X, X, metric=metric)) |
| 55 | |
| 56 | return similarity_mtx.mean(axis=1) |
no outgoing calls
no test coverage detected
searching dependent graphs…