Skip to content

Commit

Permalink
Remove duplicate points in principal_direction_extents (#999)
Browse files Browse the repository at this point in the history
  • Loading branch information
eleftherioszisis authored Mar 10, 2022
1 parent cfc7012 commit 127d6fd
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 7 deletions.
10 changes: 6 additions & 4 deletions neurom/morphmath.py
Original file line number Diff line number Diff line change
Expand Up @@ -441,10 +441,10 @@ def segment_taper_rate(seg):
def pca(points):
"""Estimate the principal components of the covariance on the given point cloud.
Input
A numpy array of points of the form ((x1,y1,z1), (x2, y2, z2)...)
Args:
points: A numpy array of points of the form ((x1,y1,z1), (x2, y2, z2)...)
Ouptut
Returns:
Eigenvalues and respective eigenvectors
"""
return np.linalg.eig(np.cov(points.transpose()))
Expand Down Expand Up @@ -474,8 +474,10 @@ def principal_direction_extent(points):
eigs : eigenvalues of the covariance matrix
eigv : respective eigenvectors of the covariance matrix
"""
# pca can be biased by duplicate points
points = np.unique(points, axis=0)

# center the points around 0.0
points = np.copy(points)
points -= np.mean(points, axis=0)

# principal components
Expand Down
12 changes: 9 additions & 3 deletions tests/features/test_get_features.py
Original file line number Diff line number Diff line change
Expand Up @@ -797,9 +797,15 @@ def test_principal_direction_extents():

# test with a realistic morphology
m = nm.load_morphology(DATA_PATH / 'h5/v1' / 'bio_neuron-000.h5')
p_ref = [1672.9694359427331, 142.43704397865031, 226.45895382204986,
415.50612748523838, 429.83008974193206, 165.95410536922873,
346.83281498399697]
p_ref = [
1672.969491,
142.437047,
224.607978,
415.50613,
429.830081,
165.954097,
346.832825,
]
p = features.get('principal_direction_extents', m)
assert_allclose(p, p_ref, rtol=1e-6)

Expand Down

0 comments on commit 127d6fd

Please sign in to comment.