Skip to content

Commit

Permalink
if you pass a list of list as the covariance into
Browse files Browse the repository at this point in the history
multivariate_gaussian you get an erroneous answer because
it does not correctly convert the list into an np.array.rlabbe#40
multivariate_gaussian doesn't handle lists

if you pass a list of list as the covariance into
multivariate_gaussian you get an erroneous answer because
it does not correctly convert the list into an np.array.rlabbe#40
multivariate_gaussian doesn't handle lists

if you pass a list of list as the covariance into
multivariate_gaussian you get an erroneous answer because
it does not correctly convert the list into an np.array.rlabbe#40
multivariate_gaussian doesn't handle lists

if you pass a list of list as the covariance into
multivariate_gaussian you get an erroneous answer because
it does not correctly convert the list into an np.array.rlabbe#40
multivariate_gaussian doesn't handle lists

if you pass a list of list as the covariance into
multivariate_gaussian you get an erroneous answer because
it does not correctly convert the list into an np.array.rlabbe#40
multivariate_gaussian doesn't handle lists

if you pass a list of list as the covariance into
multivariate_gaussian you get an erroneous answer because
it does not correctly convert the list into an np.array.rlabbe#40
multivariate_gaussian doesn't handle lists

if you pass a list of list as the covariance into
multivariate_gaussian you get an erroneous answer because
it does not correctly convert the list into an np.array.rlabbe#40
multivariate_gaussian doesn't handle lists

if you pass a list of list as the covariance into
multivariate_gaussian you get an erroneous answer because
it does not correctly convert the list into an np.array.rlabbe#40
multivariate_gaussian doesn't handle lists

if you pass a list of list as the covariance into
multivariate_gaussian you get an erroneous answer because
it does not correctly convert the list into an np.array.rlabbe#40
multivariate_gaussian doesn't handle lists

if you pass a list of list as the covariance into
multivariate_gaussian you get an erroneous answer because
it does not correctly convert the list into an np.array.rlabbe#40
multivariate_gaussian doesn't handle lists

if you pass a list of list as the covariance into
multivariate_gaussian you get an erroneous answer because
it does not correctly convert the list into an np.array.rlabbe#40
multivariate_gaussian doesn't handle lists

if you pass a list of list as the covariance into
multivariate_gaussian you get an erroneous answer because
it does not correctly convert the list into an np.array.rlabbe#40
multivariate_gaussian doesn't handle lists

if you pass a list of list as the covariance into
multivariate_gaussian you get an erroneous answer because
it does not correctly convert the list into an np.array.rlabbe#40
multivariate_gaussian doesn't handle lists

if you pass a list of list as the covariance into
multivariate_gaussian you get an erroneous answer because
it does not correctly convert the list into an np.array.rlabbe#40
multivariate_gaussian doesn't handle lists

if you pass a list of list as the covariance into
multivariate_gaussian you get an erroneous answer because
it does not correctly convert the list into an np.array.rlabbe#40
multivariate_gaussian doesn't handle lists

if you pass a list of list as the covariance into
multivariate_gaussian you get an erroneous answer because
it does not correctly convert the list into an np.array.rlabbe#40
multivariate_gaussian doesn't handle lists

if you pass a list of list as the covariance into
multivariate_gaussian you get an erroneous answer because
it does not correctly convert the list into an np.array.rlabbe#40
multivariate_gaussian doesn't handle lists

if you pass a list of list as the covariance into
multivariate_gaussian you get an erroneous answer because
it does not correctly convert the list into an np.array.rlabbe#40
multivariate_gaussian doesn't handle lists

if you pass a list of list as the covariance into
multivariate_gaussian you get an erroneous answer because
it does not correctly convert the list into an np.array.rlabbe#40
multivariate_gaussian doesn't handle lists

if you pass a list of list as the covariance into
multivariate_gaussian you get an erroneous answer because
it does not correctly convert the list into an np.array.rlabbe#40
multivariate_gaussian doesn't handle lists

if you pass a list of list as the covariance into
multivariate_gaussian you get an erroneous answer because
it does not correctly convert the list into an np.array.rlabbe#40
multivariate_gaussian doesn't handle lists

if you pass a list of list as the covariance into
multivariate_gaussian you get an erroneous answer because
it does not correctly convert the list into an np.array.rlabbe#40
multivariate_gaussian doesn't handle lists

if you pass a list of list as the covariance into
multivariate_gaussian you get an erroneous answer because
it does not correctly convert the list into an np.array.rlabbe#40
multivariate_gaussian doesn't handle lists

if you pass a list of list as the covariance into
multivariate_gaussian you get an erroneous answer because
it does not correctly convert the list into an np.array.rlabbe#40
multivariate_gaussian doesn't handle lists

if you pass a list of list as the covariance into
multivariate_gaussian you get an erroneous answer because
it does not correctly convert the list into an np.array.rlabbe#40
multivariate_gaussian doesn't handle lists

if you pass a list of list as the covariance into
multivariate_gaussian you get an erroneous answer because
it does not correctly convert the list into an np.array.rlabbe#40
multivariate_gaussian doesn't handle lists

if you pass a list of list as the covariance into
multivariate_gaussian you get an erroneous answer because
it does not correctly convert the list into an np.array.rlabbe#40
multivariate_gaussian doesn't handle lists

if you pass a list of list as the covariance into
multivariate_gaussian you get an erroneous answer because
it does not correctly convert the list into an np.array.rlabbe#40
multivariate_gaussian doesn't handle lists

if you pass a list of list as the covariance into
multivariate_gaussian you get an erroneous answer because
it does not correctly convert the list into an np.array.rlabbe#40
multivariate_gaussian doesn't handle lists

if you pass a list of list as the covariance into
multivariate_gaussian you get an erroneous answer because
it does not correctly convert the list into an np.array.rlabbe#40
multivariate_gaussian doesn't handle lists

if you pass a list of list as the covariance into
multivariate_gaussian you get an erroneous answer because
it does not correctly convert the list into an np.array.rlabbe#40
multivariate_gaussian doesn't handle lists

if you pass a list of list as the covariance into
multivariate_gaussian you get an erroneous answer because
it does not correctly convert the list into an np.array.rlabbe#40
multivariate_gaussian doesn't handle lists

if you pass a list of list as the covariance into
multivariate_gaussian you get an erroneous answer because
it does not correctly convert the list into an np.array.rlabbe#40
multivariate_gaussian doesn't handle lists

if you pass a list of list as the covariance into
multivariate_gaussian you get an erroneous answer because
it does not correctly convert the list into an np.array.rlabbe#40
multivariate_gaussian doesn't handle lists

if you pass a list of list as the covariance into
multivariate_gaussian you get an erroneous answer because
it does not correctly convert the list into an np.array.rlabbe#40
multivariate_gaussian doesn't handle lists

if you pass a list of list as the covariance into
multivariate_gaussian you get an erroneous answer because
it does not correctly convert the list into an np.array.rlabbe#40
multivariate_gaussian doesn't handle lists

if you pass a list of list as the covariance into
multivariate_gaussian you get an erroneous answer because
it does not correctly convert the list into an np.array.rlabbe#40
multivariate_gaussian doesn't handle lists

if you pass a list of list as the covariance into
multivariate_gaussian you get an erroneous answer because
it does not correctly convert the list into an np.array.rlabbe#40
multivariate_gaussian doesn't handle lists

if you pass a list of list as the covariance into
multivariate_gaussian you get an erroneous answer because
it does not correctly convert the list into an np.array.rlabbe#40
multivariate_gaussian doesn't handle lists

if you pass a list of list as the covariance into
multivariate_gaussian you get an erroneous answer because
it does not correctly convert the list into an np.array.
  • Loading branch information
rlabbe committed Jun 19, 2016
1 parent 22ba601 commit abb540c
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 6 deletions.
27 changes: 22 additions & 5 deletions filterpy/stats/stats.py
Original file line number Diff line number Diff line change
Expand Up @@ -597,7 +597,7 @@ def _is_inside_ellipse(x, y, ex, ey, orientation, width, height):
return ((x-ex)*co - (y-ey)*so)**2/width**2 + \
((x-ex)*so + (y-ey)*co)**2/height**2 <= 1

def _to_cov(x,n):
def _to_cov(x, n):
""" If x is a scalar, returns a covariance matrix generated from it
as the identity matrix multiplied by x. The dimension will be nxn.
If x is already a numpy array then it is returned unchanged.
Expand All @@ -608,7 +608,14 @@ def _to_cov(x,n):
x = np.asarray(x)[0]
return x
except:
return np.eye(n) * x
cov = np.asarray(x)
try:
# asarray of a scalar returns an unsized object, so len will raise
# an exception
len(cov)
return cov
except:
return np.eye(n) * x


def _do_plot_test():
Expand Down Expand Up @@ -704,14 +711,24 @@ def NESS(xs, est_xs, ps):

if __name__ == '__main__':

ax = plot_gaussian_pdf(2, 3)
"""ax = plot_gaussian_pdf(2, 3)
plot_gaussian_cdf(2, 3, ax=ax)
plt.show()
ys =np.abs(np.random.randn(100))
ys /= np.sum(ys)
plot_discrete_cdf(xs=None, ys=ys)

plot_discrete_cdf(xs=None, ys=ys)"""

mean=(0,0)

cov=[[1,.5],[.5,1]]
print("For list and np.array covariances:")
for covariance in (cov,np.asarray(cov)):
a = [[multivariate_gaussian((i,j),mean,covariance)
for i in (-1,0,1)]
for j in (-1,0,1)]
print(np.asarray(a))
print()

#P1 = [[2, 1.9], [1.9, 2]]
#plot_covariance_ellipse((10, 10), P1, facecolor='y', alpha=0.6)
Expand Down
25 changes: 24 additions & 1 deletion filterpy/stats/tests/test_stats.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,30 @@
for more information.
"""

from filterpy.stats import norm_cdf
from filterpy.stats import norm_cdf, multivariate_gaussian
import numpy as np


def test_multivariate_gaussian():

# test that we treat lists and arrays the same
mean= (0, 0)
cov=[[1, .5], [.5, 1]]
a = [[multivariate_gaussian((i, j), mean, cov)
for i in (-1, 0, 1)]
for j in (-1, 0, 1)]

b = [[multivariate_gaussian((i, j), mean, np.asarray(cov))
for i in (-1, 0, 1)]
for j in (-1, 0, 1)]

assert np.allclose(a, b)

a = [[multivariate_gaussian((i, j), np.asarray(mean), cov)
for i in (-1, 0, 1)]
for j in (-1, 0, 1)]
assert np.allclose(a, b)



def test_norm_cdf():
Expand Down

0 comments on commit abb540c

Please sign in to comment.