# Path: attitude/geom/util.py
# def dot(*matrices):
#     return reduce(N.dot, matrices)


import numpy as N
import pytest
from .test_pca import random_pca
from ..geom.util import dot
"""
Functions to test implementations of the statistical distance between two
orientation measurements. This will lead us to a quantification of the distance
between two uncertain orientation measurements.
"""
from __future__ import division


def bhattacharyya_distance(pca1,pca2):
    """
    A measure of the distance between two probability distributions
    """
    u1 = pca1.coefficients
    s1 = pca1.covariance_matrix
    u2 = pca2.coefficients
    s2 = pca2.covariance_matrix

    sigma = (s1+s2)/2

    assert all(u1 > 0)
    assert all(u2 > 0)
    assert all(s1.sum(axis=1) > 0)
    assert all(s2.sum(axis=1) > 0)


# Path: attitude/geom/util.py
# def dot(*matrices):
#     return reduce(N.dot, matrices)


# Path: attitude/__dustbin/statistical_distances.py
import numpy as N
import pytest
from .test_pca import random_pca
from ..geom.util import dot

"""
Functions to test implementations of the statistical distance between two
orientation measurements. This will lead us to a quantification of the distance
between two uncertain orientation measurements.
"""
from __future__ import division


def bhattacharyya_distance(pca1,pca2):
    """
    A measure of the distance between two probability distributions
    """
    u1 = pca1.coefficients
    s1 = pca1.covariance_matrix
    u2 = pca2.coefficients
    s2 = pca2.covariance_matrix

    sigma = (s1+s2)/2

    assert all(u1 > 0)
    assert all(u2 > 0)
    assert all(s1.sum(axis=1) > 0)
    assert all(s2.sum(axis=1) > 0)


    _ = 1/8*dot((u1-u2).T, N.linalg.inv(sigma),u1-u2)