Skip to content

Commit 40eb306

Browse files
committed
add option to save mus in compute_id_2nn
fixed linting remove flag form mus; save them as default attribute fix
1 parent a1f83b7 commit 40eb306

File tree

1 file changed

+12
-4
lines changed

1 file changed

+12
-4
lines changed

dadapy/id_estimation.py

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ def __init__(
7272
self.intrinsic_dim = None
7373
self.intrinsic_dim_err = None
7474
self.intrinsic_dim_scale = None
75+
self.intrinsic_dim_mus = None
7576

7677
# ----------------------------------------------------------------------------------------------
7778

@@ -110,7 +111,11 @@ def func(x, m):
110111

111112
# ----------------------------------------------------------------------------------------------
112113
def compute_id_2NN(
113-
self, algorithm="base", fraction=0.9, decimation=1, set_attr=True
114+
self,
115+
algorithm="base",
116+
fraction=0.9,
117+
decimation=1,
118+
set_attr=True,
114119
):
115120
"""Compute intrinsic dimension using the 2NN algorithm.
116121
@@ -133,6 +138,9 @@ def compute_id_2NN(
133138
ids = np.zeros(nrep)
134139
rs = np.zeros(nrep)
135140

141+
N_subset = int(np.rint(self.N * decimation))
142+
mus = np.zeros((nrep, N_subset))
143+
136144
for j in range(nrep):
137145

138146
if decimation == 1 and self.distances is not None:
@@ -146,7 +154,6 @@ def compute_id_2NN(
146154

147155
else:
148156
# if set_attr==False or for decimation < 1 random sample points don't save distances
149-
N_subset = int(np.rint(self.N * decimation))
150157
idx = np.random.choice(self.N, size=N_subset, replace=False)
151158
X_decimated = self.X[idx]
152159

@@ -157,8 +164,8 @@ def compute_id_2NN(
157164
period=self.period,
158165
)
159166

160-
mus = np.log(distances[:, 2] / distances[:, 1])
161-
ids[j] = self._compute_id_2NN(mus, fraction, algorithm)
167+
mus[j] = np.log(distances[:, 2] / distances[:, 1])
168+
ids[j] = self._compute_id_2NN(mus[j], fraction, algorithm)
162169
rs[j] = np.mean(distances[:, np.array([1, 2])])
163170

164171
intrinsic_dim = np.mean(ids)
@@ -172,6 +179,7 @@ def compute_id_2NN(
172179
self.intrinsic_dim = intrinsic_dim
173180
self.intrinsic_dim_err = intrinsic_dim_err
174181
self.intrinsic_dim_scale = intrinsic_dim_scale
182+
self.intrinsic_dim_mus = mus
175183

176184
return intrinsic_dim, intrinsic_dim_err, intrinsic_dim_scale
177185

0 commit comments

Comments
 (0)