Skip to content

Commit

Permalink
refactor covariance_matrix usage to make code more compact and clear
Browse files Browse the repository at this point in the history
  • Loading branch information
enriquecarlostoomey committed Nov 29, 2017
1 parent f765db2 commit df4485f
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 5 deletions.
2 changes: 1 addition & 1 deletion quaternions/quaternion.py
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,7 @@ def average_and_std_lerner(*quaternions, weights=None):
"""
q_average = Quaternion.average(*quaternions, weights=weights)
diffs = [quat / q_average for quat in quaternions]
angles_list = np.array([[2 * diff.coordinates[i] for i in [1, 2, 3]] for diff in diffs])
angles_list = [2 * diff.coordinates[1:] for diff in diffs]
covariance_matrix = covariance_matrix_from_angles(angles_list)
return q_average, np.degrees(sigma_lerner(covariance_matrix))

Expand Down
6 changes: 2 additions & 4 deletions quaternions/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,8 @@ def covariance_matrix_from_angles(angles_list):
Computes covariance matrix from 3d vectors list
:param angles_list: list of NumPy arrays
"""
covariance_matrix = np.zeros((3, 3))
for angles in angles_list:
covariance_matrix += np.outer(angles.T, angles)
covariance_matrix /= (angles_list.shape[0] + 1)
covariance_matrix = sum(np.outer(angles, angles) for angles in angles_list)
covariance_matrix /= (len(angles_list) + 1)
return covariance_matrix


Expand Down

0 comments on commit df4485f

Please sign in to comment.