Skip to content

Commit

Permalink
Failing test for #7
Browse files Browse the repository at this point in the history
  • Loading branch information
oseiskar committed Sep 17, 2019
1 parent 139183f commit 7e9e589
Showing 1 changed file with 45 additions and 0 deletions.
45 changes: 45 additions & 0 deletions tests/testsuite.py
Original file line number Diff line number Diff line change
Expand Up @@ -357,6 +357,30 @@ def test_multi_dimensional_observations(self):
self.assertSequenceEqual(r.predicted.observations.mean.shape, (5,15,2))
self.assertSequenceEqual(r.predicted.observations.cov.shape, (5,15,2,2))

def test_4_dimensional_observations(self):
training_matrix = np.ones((5,10,4))
training_matrix[1,1,1] = np.nan

kf = simdkalman.KalmanFilter(
state_transition = np.eye(3),
process_noise = 0.1,
observation_model = np.array([[1,1,0],[0,0,1],[0,1,1],[1,1,0]]),
observation_noise = np.eye(4))

r = kf.compute(training_matrix, 15,
gains=True, filtered=True, smoothed=True, log_likelihood=True)

self.assertSequenceEqual(
r.smoothed.observations.mean.shape,
training_matrix.shape)

self.assertSequenceEqual(r.smoothed.states.mean.shape, (5,10,3))
self.assertSequenceEqual(r.smoothed.states.cov.shape, (5,10,3,3))
self.assertSequenceEqual(r.smoothed.gains.shape, (5,10,3,3))
self.assertSequenceEqual(r.filtered.gains.shape, (5,10,3,4))
self.assertSequenceEqual(r.predicted.observations.mean.shape, (5,15,4))
self.assertSequenceEqual(r.predicted.observations.cov.shape, (5,15,4,4))

def test_em_algorithm(self):
training_matrix = np.ones((5,10))

Expand Down Expand Up @@ -398,6 +422,27 @@ def test_em_algorithm_multi_dimensional_observations(self):
self.assertSequenceEqual(B.shape, (5,2,2))
self.assertTrue(min(np.linalg.eig(B[0,...])[0]) > 0)

def test_em_algorithm_3_dimensional_observations(self):
training_matrix = np.ones((5,10,3))
training_matrix[1,1,1] = np.nan

kf = simdkalman.KalmanFilter(
state_transition = np.eye(2),
process_noise = 0.1,
observation_model = np.array([[1,1], [0,1], [1,0]]),
observation_noise = 0.1)

r = kf.em(training_matrix, n_iter=5, verbose=False)

self.assertSequenceEqual(r.process_noise.shape, (5,2,2))
A0 = r.process_noise[0,...]
self.assertMatrixEqual(A0, A0.T, epsilon=1e-8)
self.assertTrue(min(np.linalg.eig(A0)[0]) > 0)

B = r.observation_noise
self.assertSequenceEqual(B.shape, (5,3,3))
self.assertTrue(min(np.linalg.eig(B[0,...])[0]) > 0)

def test_one_dimensional(self):

training_matrix = range(10)
Expand Down

0 comments on commit 7e9e589

Please sign in to comment.