@@ -39,47 +39,47 @@ type KF struct {
3939// - invalid state or output noise is given: noise covariance must either be nil or match the model dimensions
4040func New (m filter.DiscreteModel , init filter.InitCond , z , wn filter.Noise ) (* KF , error ) {
4141 // size of the input and output vectors
42- _nx , _ , _ny , _ := m .Dims ()
43- if _nx <= 0 || _ny <= 0 {
44- return nil , fmt .Errorf ("invalid model dimensions: [%d x %d]" , _nx , _ny )
42+ nx , _ , ny , _ := m .SystemDims ()
43+ if nx <= 0 || ny <= 0 {
44+ return nil , fmt .Errorf ("invalid model dimensions: [%d x %d]" , nx , ny )
4545 }
4646
4747 if z != nil {
48- if z .Cov ().Symmetric () != _nx {
49- return nil , fmt .Errorf ("invalid state noise dimension: %d != %d" , z .Cov ().Symmetric (), _ny )
48+ if z .Cov ().Symmetric () != nx {
49+ return nil , fmt .Errorf ("invalid state noise dimension: %d != %d" , z .Cov ().Symmetric (), ny )
5050 }
5151 } else {
5252 z , _ = noise .NewNone ()
5353 }
5454
5555 if wn != nil {
56- if wn .Cov ().Symmetric () != _ny {
56+ if wn .Cov ().Symmetric () != ny {
5757 return nil , fmt .Errorf ("invalid output noise dimension: %d" , wn .Cov ().Symmetric ())
5858 }
5959 } else {
6060 wn , _ = noise .NewNone ()
6161 }
6262
6363 rows , cols := m .SystemMatrix ().Dims ()
64- if rows != _nx || cols != _nx {
64+ if rows != nx || cols != nx {
6565 return nil , fmt .Errorf ("invalid propagation matrix dimensions: [%d x %d]" , rows , cols )
6666 }
6767
6868 if m .ControlMatrix () != nil && ! m .ControlMatrix ().(* mat.Dense ).IsEmpty () {
6969 rows , cols := m .ControlMatrix ().Dims ()
70- if rows != _nx {
70+ if rows != nx {
7171 return nil , fmt .Errorf ("invalid ctl propagation matrix dimensions: [%d x %d]" , rows , cols )
7272 }
7373 }
7474
7575 rows , cols = m .OutputMatrix ().Dims ()
76- if rows != _ny || cols != _nx {
76+ if rows != ny || cols != nx {
7777 return nil , fmt .Errorf ("invalid observation matrix dimensions: [%d x %d]" , rows , cols )
7878 }
7979
8080 if m .FeedForwardMatrix () != nil && ! m .FeedForwardMatrix ().(* mat.Dense ).IsEmpty () {
8181 rows , cols = m .FeedForwardMatrix ().Dims ()
82- if rows != _ny {
82+ if rows != ny {
8383 return nil , fmt .Errorf ("invalid ctl observation matrix dimensions: [%d x %d]" , rows , cols )
8484 }
8585 }
@@ -92,10 +92,10 @@ func New(m filter.DiscreteModel, init filter.InitCond, z, wn filter.Noise) (*KF,
9292 pNext := mat .NewSymDense (init .Cov ().Symmetric (), nil )
9393
9494 // innovation vector
95- inn := mat .NewVecDense (_ny , nil )
95+ inn := mat .NewVecDense (ny , nil )
9696
9797 // kalman gain
98- k := mat .NewDense (_nx , _ny , nil )
98+ k := mat .NewDense (nx , ny , nil )
9999
100100 return & KF {
101101 m : m ,
@@ -140,9 +140,9 @@ func (k *KF) Predict(x, u mat.Vector) (filter.Estimate, error) {
140140// Update corrects state x using the measurement z, given control intput u and returns corrected estimate.
141141// It returns error if either invalid state was supplied or if it fails to calculate system output estimate.
142142func (k * KF ) Update (x , u , ym mat.Vector ) (filter.Estimate , error ) {
143- _nx , _ , _ny , _ := k .m .Dims ()
143+ nx , _ , ny , _ := k .m .SystemDims ()
144144
145- if ym .Len () != _ny {
145+ if ym .Len () != ny {
146146 return nil , fmt .Errorf ("invalid measurement supplied: %v" , ym )
147147 }
148148
@@ -152,8 +152,8 @@ func (k *KF) Update(x, u, ym mat.Vector) (filter.Estimate, error) {
152152 return nil , fmt .Errorf ("failed to observe system output: %v" , err )
153153 }
154154
155- pxy := mat .NewDense (_nx , _ny , nil )
156- pyy := mat .NewDense (_ny , _ny , nil )
155+ pxy := mat .NewDense (nx , ny , nil )
156+ pyy := mat .NewDense (ny , ny , nil )
157157
158158 // P*H'
159159 pxy .Mul (k .pNext , k .m .OutputMatrix ().T ())
@@ -217,8 +217,8 @@ func (k *KF) Update(x, u, ym mat.Vector) (filter.Estimate, error) {
217217 k .inn .CopyVec (inn )
218218 k .k .Copy (gain )
219219 // update KF covariance matrix
220- for i := 0 ; i < _nx ; i ++ {
221- for j := i ; j < _nx ; j ++ {
220+ for i := 0 ; i < nx ; i ++ {
221+ for j := i ; j < nx ; j ++ {
222222 k .p .SetSym (i , j , pCorr .At (i , j ))
223223 }
224224 }
0 commit comments