![]() |
(18.4) |
This gives us
![]() |
![]() |
![]() |
(18.5) |
![]() |
![]() |
![]() |
(18.6) |
![]() |
![]() |
![]() |
(18.7) |
We note here that
As first example we have taken Petr Franek's data
kalman.dat
together with his specifications for the
system matrices and by manipulating observations ,
,
entered three artificial outliers; the result is saved in kalmanao.dat.
library("xplore") library("plot") library("kalman") serie = read("kalmanao.dat") y = serie[,2] mu = 10 Sig = 0 H = 1 F = 1 Q = 9 R = 9 T=dim(y) e=0.05 N=100 eps=0.01 itmax=15 aus=4The rLS filter is then calibrated to an efficiency loss of
ergLS=calibrLS(T,Sig,H,F,Q,R,e,N,eps,itmax,aus) b=ergLS.bNext we filter the data with the Kalman filter and the rLS filter.
res = kfilter2(y,mu,Sig, H,F,Q,R) fx = res.filtX res= rlsfil(y,mu,Sig, H,F,Q,R,b) frx = res.filtXThe results are then displayed, the classical Kalman filter in red, the rLS filter in green and the observations from kalmanao.dat in blue. Additionally we set flags on the time instances where the rLS filter clips
origy= serie[,1]~serie[,2] origy= setmask(origy, "line", "blue", "thin") fx = serie[,1]~fx fx = setmask(fx, "line", "red", "thin") frx = serie[,1]~frx frx = setmask(frx, "line", "green", "thin") clip=serie[,1]~(res.clipInd) clip=paf(clip,clip[,2]==1) clip[,2]=0 setmaskp(clip,4, 3, 4) disp = createdisplay(1,1) show(disp,1,1, origy,fx,frx,clip) setgopt(disp,1,1, "title", "KalmanData1 + AO's in t=50,60,90") setgopt(disp,1,1, "xlabel", "t") setgopt(disp,1,1, "ylabel", "y, rLS, Kalman")
![]() |
As a second example we took the state-space model underlying Petr Franek's Example 2.
library("xplore") library("plot") library("kalman") mu = #(20,0) Sig = #(0,0)~#(0,0) H = #(0.3,-0.3)~#(1,1) F = #(1,0)~#(1,0) R = #(0,0)~#(0,9) mid=#(0,0) Qid= #(9,0)~#(0,9)According to this model we simulated
T=50 e=0.1 mcont=#(25,30) Qcont=0.1.*Qid AOr=0.1 randomize(0) ErrX = epscontnorm(T,0,mid,R,mcont,Qcont,0) ErrY = epscontnorm(T,AOr,mid,Qid,mcont,Qcont,0) sim = kemitor2(T,mu,H,F,(ErrY.X),(ErrX.X)) y=sim.Y Xact=sim.XThe rLS filter is then calibrated to an efficiency loss of
N=10000 eps=0.01 itmax=15 aus=4 ergLS=calibrLS(T,Sig,H,F,Qid,R,e,N,eps,itmax,aus) b=ergLS.bThe simulated data are filtered by the classical Kalman filter and the rLS filter
res = kfilter2(y,mu,Sig, H,F,Qid,R) fx = res.filtX res= rlsfil(y,mu,Sig, H,F,Qid,R,b) frx = res.filtXNext, the filtered values are prepared for graphical output: the classical Kalman filter is to be displayed in red, the rLS filter in green and the actual simulated states in blue.
i=(1:T) Xact1 = i~(Xact[,1]) Xact1 = setmask(Xact1, "line", "blue", "thin") fx1 = i~(fx[,1]) fx1 = setmask(fx1, "line", "red", "thin") frx1= i~(frx[,1]) frx1 = setmask(frx1, "line", "green", "thin")Additionally we set green flags on the time instances where the rLS filter clips
ym1=max(vec((Xact[,1])~(fx[,1])~(frx[,1]))) ;top of graphics ym2=min(vec((Xact[,1])~(fx[,1])~(frx[,1]))) ;bottom of graphics flagInd=i~(ErrY.Ind) flagInd=paf(flagInd,flagInd[,2]==1) flagInd[,2]=ym1*((ym1>0)*1.1+(ym1<0)*0.9) flagclip=i~(res.clipInd) flagclip=paf(flagclip,flagclip[,2]==1) flagclip[,2]= ym2*((ym2<0)*1.1+(ym2>0)*0.9) setmaskp(flagInd,4, 3, 4) setmaskp(flagclip,2, 4, 4)Finally, all the results of the 1-st coordinate are displayed in the left half of a graphic window.
disp = createdisplay(1,2) show(disp,1,1,Xact1,fx1,frx1,flagInd,flagclip) setgopt(disp,1,1, "title", "simulated Model under AO -- 1st coord.") setgopt(disp,1,1, "xlabel", "t") setgopt(disp,1,1, "ylabel", "x, rLS, Kalman")
![]() |
To show that robustification does not go for free, we have taken Petr Franek's data set kalman2.dat as it was, together with his specification of the state space model. So the data stems from the ideal situation and the classical Kalman filter in this case should do better than the rLS.
library("xplore") library("plot") library("kalman") serie = read("kalman2.dat") y = serie[,2] mu = #(0,0) Sig = #(0,0)~#(0,0) H = #(1,0)' F = #(0.5,1)~#(-0.3,0) R = #(1,0)~#(0,0) Q = 4 e=0.05 N=10000 eps=0.01 itmax=15 aus=4Here the rLS filter is calibrated to an efficiency loss of
ergLS=calibrLS(T,Sig,H,F,Q,R,e,N,eps,itmax,aus) b=ergLS.b res= kfilter2(y,mu,Sig, H,F,Q,R) fx = res.filtX fy=(H*fx')' res= rlsfil(y,mu,Sig, H,F,Q,R,b) frx = res.filtX fry=(H*frx')'As we do not have any information about the actual states in this example, we examine the filtered observations
These filtered observations are then displayed, as usual.
origy = serie[,1]~serie[,2] origy = setmask(origy, "line", "blue", "thin") fy = serie[,1]~fy fy = setmask(fy, "line", "red", "thin") fry = serie[,1]~fry fry = setmask(fry, "line", "green", "thin") flags = serie[,1]~(res.clipInd) flags=paf(flags,flags[,2]==1) setmaskp(flags,4, 3, 4) disp = createdisplay(1,1) show(disp,1,1,origy,fy,fry,flags) setgopt(disp,1,1, "title", "KalmanData2 in Observation Space") setgopt(disp,1,1, "xlabel", "t") setgopt(disp,1,1, "ylabel", "y, y-rLS, y-Kalman")
![]() |