Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion gmr/mvn.py
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ def to_norm_factor_and_exponents(self, X):
if self.norm is None:
# Suppress a determinant of 0 to avoid numerical problems
L_det = max(sp.linalg.det(L), np.finfo(L.dtype).eps)
self.norm = 0.5 / np.pi ** (0.5 * n_features) / L_det
self.norm = (2 * np.pi) ** (-n_features/2) / L_det

# Solve L x = (X - mean)^T for x with triangular L
# (LL^T = Sigma), that is, x = L^T^-1 (X - mean)^T.
Expand Down
10 changes: 7 additions & 3 deletions gmr/tests/test_mvn.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
mean = np.array([0.0, 1.0])
covariance = np.array([[0.5, -1.0], [-1.0, 5.0]])


class AxisStub:
def __init__(self):
self.count = 0
Expand Down Expand Up @@ -75,13 +74,18 @@ def test_sample_confidence_region():

def test_probability_density():
"""Test PDF of MVN."""
mean = np.array([0.0, 1.0, 2.0])
covariance = np.array([[ 0.5, -1.0, 0.0],
[-1.0, 5.0, -0.5],
[ 0.0, -0.5, 1.0]])

random_state = check_random_state(0)
mvn = MVN(mean, covariance, random_state=random_state)

x = np.linspace(-100, 100, 201)
X = np.vstack(list(map(np.ravel, np.meshgrid(x, x)))).T
X = np.vstack(list(map(np.ravel, np.meshgrid(x, x, x)))).T
p = mvn.to_probability_density(X)
approx_int = np.sum(p) * ((x[-1] - x[0]) / 201) ** 2
approx_int = np.sum(p)
assert np.abs(1.0 - approx_int) < 0.01


Expand Down
Loading