Skip to content

Commit

Permalink
add option to save mus in compute_id_2nn
Browse files Browse the repository at this point in the history
fixed linting


remove flag form mus; save them as default attribute


fix
  • Loading branch information
AldoGl committed Jun 29, 2022
1 parent a1f83b7 commit 88bb048
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions dadapy/id_estimation.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ def __init__(
self.intrinsic_dim = None
self.intrinsic_dim_err = None
self.intrinsic_dim_scale = None
self.intrinsic_dim_mus = None

# ----------------------------------------------------------------------------------------------

Expand Down Expand Up @@ -110,7 +111,11 @@ def func(x, m):

# ----------------------------------------------------------------------------------------------
def compute_id_2NN(
self, algorithm="base", fraction=0.9, decimation=1, set_attr=True
self,
algorithm="base",
fraction=0.9,
decimation=1,
set_attr=True,
):
"""Compute intrinsic dimension using the 2NN algorithm.
Expand All @@ -133,6 +138,9 @@ def compute_id_2NN(
ids = np.zeros(nrep)
rs = np.zeros(nrep)

N_subset = int(np.rint(self.N * decimation))
mus = np.zeros((nrep, N_subset))

for j in range(nrep):

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

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

Expand All @@ -157,8 +164,8 @@ def compute_id_2NN(
period=self.period,
)

mus = np.log(distances[:, 2] / distances[:, 1])
ids[j] = self._compute_id_2NN(mus, fraction, algorithm)
mus[j] = np.log(distances[:, 2] / distances[:, 1])
ids[j] = self._compute_id_2NN(mus[j], fraction, algorithm)
rs[j] = np.mean(distances[:, np.array([1, 2])])

intrinsic_dim = np.mean(ids)
Expand All @@ -172,6 +179,7 @@ def compute_id_2NN(
self.intrinsic_dim = intrinsic_dim
self.intrinsic_dim_err = intrinsic_dim_err
self.intrinsic_dim_scale = intrinsic_dim_scale
self.intrinsic_dim_mus = mus

return intrinsic_dim, intrinsic_dim_err, intrinsic_dim_scale

Expand Down

0 comments on commit 88bb048

Please sign in to comment.