11"""
22Measures for estimating the information density of a given sample.
33"""
4+ from typing import Callable
45
56import numpy as np
67from scipy .spatial .distance import cosine , euclidean
78
9+ from modAL .utils .data import modALinput
810
9- def similarize_distance (distance_measure ):
11+
12+ def similarize_distance (distance_measure : Callable ) -> Callable :
1013 """
1114 Takes a distance measure and converts it into a information_density measure.
1215
13- :param distance_measure:
14- The distance measure to be converted into information_density measure.
15- :type distance_measure:
16- function
16+ Args:
17+ distance_measure: The distance measure to be converted into information_density measure.
1718
18- :returns:
19- - **sim** *(function)* --
20- The information_density measure obtained from the given disance measure.
19+ Returns:
20+ The information_density measure obtained from the given distance measure.
2121 """
2222 def sim (* args , ** kwargs ):
2323 return 1 / (1 + distance_measure (* args , ** kwargs ))
@@ -29,25 +29,20 @@ def sim(*args, **kwargs):
2929euclidean_similarity = similarize_distance (euclidean )
3030
3131
32- def information_density (X , similarity_measure = cosine_similarity ):
32+ def information_density (X : modALinput , similarity_measure : Callable = cosine_similarity ) -> np . ndarray :
3333 """
34- Calculates the information density metric of the given data using the similarity
35- measure given.
34+ Calculates the information density metric of the given data using the similarity measure given.
3635
37- :param X:
38- The data for which the information density is to be calculated.
39- :type X:
40- numpy.ndarray of shape (n_samples, n_features)
36+ Args:
37+ X: The data for which the information density is to be calculated.
38+ similarity_measure: The similarity measure to be used. Should take two 1d numpy.ndarrays for argument.
4139
42- :param similarity_measure:
43- The similarity measure to be used. Should take two 1d numpy.ndarrays for argument.
44- :type similarity_measure:
45- function
40+ Todo:
41+ Should work with all possible modALinput.
42+ Perhaps refactor the module to use some stuff from sklearn.metrics.pairwise
4643
47- :returns:
48- - **inf_density** *(numpy.ndarray of shape (n_samples, ))* --
44+ Returns:
4945 The information density for each sample.
50-
5146 """
5247 inf_density = np .zeros (shape = (X .shape [0 ],))
5348 for X_idx , X_inst in enumerate (X ):
0 commit comments