@@ -207,9 +207,12 @@ def __init__(self, dim_x, dim_z, dim_u=0, compute_log_likelihood=True):
207
207
off.
208
208
"""
209
209
210
- assert dim_x > 0
211
- assert dim_z > 0
212
- assert dim_u >= 0
210
+ if dim_z < 1 :
211
+ raise ValueError ('dim_x must be 1 or greater' )
212
+ if dim_z < 1 :
213
+ raise ValueError ('dim_x must be 1 or greater' )
214
+ if dim_u < 0 :
215
+ raise ValueError ('dim_x must be 0 or greater' )
213
216
214
217
self .dim_x = dim_x
215
218
self .dim_z = dim_z
@@ -297,9 +300,6 @@ def update(self, z, R=None, H=None):
297
300
# predict new x with residual scaled by the kalman gain
298
301
self .x = self .x + dot (self .K , self .y )
299
302
300
- if self .x .ndim == 2 :
301
- assert self .x .shape [0 ] == self .dim_x and self .x .shape [1 ] == 1
302
-
303
303
# P = (I-KH)P(I-KH)' + KRK'
304
304
I_KH = self ._I - dot (self .K , H )
305
305
self .P = dot (dot (I_KH , self .P ), I_KH .T ) + dot (dot (self .K , R ), self .K .T )
@@ -490,7 +490,6 @@ def test_matrix_dimensions(self, z=None, H=None, R=None, F=None, Q=None):
490
490
"Shape of F must be ({},{}), but is {}" .format (
491
491
self .dim_x , self .dim_x , F .shape )
492
492
493
-
494
493
assert np .ndim (H ) == 2 , \
495
494
"Shape of H must be (dim_z, {}), but is {}" .format (
496
495
P .shape [0 ], shape (H ))
@@ -816,7 +815,9 @@ def rts_smoother(self, Xs, Ps, Fs=None, Qs=None):
816
815
817
816
"""
818
817
819
- assert len (Xs ) == len (Ps )
818
+ if len (Xs ) != len (Ps ):
819
+ raise ValueError ('length of Xs and Ps must be the same' )
820
+
820
821
n = Xs .shape [0 ]
821
822
dim_x = Xs .shape [1 ]
822
823
@@ -992,8 +993,9 @@ def log_likelihood_of(self, z):
992
993
993
994
@alpha .setter
994
995
def alpha (self , value ):
995
- assert np .isscalar (value )
996
- assert value > 0.
996
+
997
+ if not np .isscalar (value ) or value <= 0 :
998
+ raise ValueError ('alpha must be a float greater than 0' )
997
999
998
1000
self ._alpha_sq = value ** 2
999
1001
@@ -1457,7 +1459,9 @@ def rts_smoother(Xs, Ps, Fs, Qs):
1457
1459
(x, P, K, pP) = rts_smoother(mu, cov, kf.F, kf.Q)
1458
1460
"""
1459
1461
1460
- assert len (Xs ) == len (Ps )
1462
+ if len (Xs ) != len (Ps ):
1463
+ raise ValueError ('length of Xs and Ps must be the same' )
1464
+
1461
1465
n = Xs .shape [0 ]
1462
1466
dim_x = Xs .shape [1 ]
1463
1467
0 commit comments