Skip to content

Commit 970fdd0

Browse files
committed
Added simpler (provisional) information imbalance implementation
1 parent f073bf4 commit 970fdd0

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed

dadapy/metric_comparisons.py

+29
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,35 @@ def __init__(
7373
n_jobs=n_jobs,
7474
)
7575

76+
def return_information_imbalace(self, coordinates, k=1):
77+
78+
distances = None
79+
dist_indices = None
80+
81+
assert any(
82+
var is not None for var in [self.X, self.distances, self.dist_indices]
83+
), "MetricComparisons should be initialized with a dataset."
84+
85+
assert any(
86+
var is not None for var in [coordinates, distances, dist_indices]
87+
), "The overlap with data requires a second dataset. \
88+
Provide at least one of coordinates, distances, dist_indices."
89+
90+
dist_indices_base, _ = self._get_nn_indices(
91+
self.X, self.distances, self.dist_indices, self.maxk
92+
)
93+
94+
dist_indices_other, _ = self._get_nn_indices(
95+
coordinates, distances, dist_indices, self.maxk
96+
)
97+
98+
assert dist_indices_base.shape[0] == dist_indices_other.shape[0]
99+
100+
imb_ij = _return_imbalance(dist_indices_base, dist_indices_other, self.rng, k=k)
101+
imb_ji = _return_imbalance(dist_indices_other, dist_indices_base, self.rng, k=k)
102+
103+
return imb_ij, imb_ji
104+
76105
def return_inf_imb_two_selected_coords(self, coords1, coords2, k=1):
77106
"""Return the imbalances between distances taken as the i and the j component of the coordinate matrix X.
78107

0 commit comments

Comments
 (0)