View source: R/util.ts.R View source: R/lin_rls.R
| rls | R Documentation | 
Recursive least-squares step
rls(x, y, t, P, mu = 1)
| x: | new input | 
| y: | new output | 
| t: | current parameter vector | 
| P: | current covariance matrix | 
a list with fields:
t.new: updated parameter vector,
P.new: updated covariance matrix,
mu: forgetting factor, the lower the highr the forgetting (1: no forget)
Gianluca Bontempi Gianluca.Bontempi@ulb.be
Handbook Statistical foundations of machine learning available in https://tinyurl.com/sfmlh
par(ask=TRUE)
n<-1;
X<-seq(-pi,pi,by=.02)
N<-length(X)
y<-sin(X)+0.1*rnorm(N)
t<-numeric(2)
P<-500*diag(n+1)
mu<-0.9 ## forgetting factor
for (i in 1:N){
 rls.step<-rls(c(1, X[i]),y[i],t,P,mu)
 t<-rls.step[[1]]
 P<-rls.step[[2]]
 plot(X[1:i],y[1:i],xlim=c(-4,4),ylim=c(-2,2),main=paste("Forgetting factor mu=",mu))
 lines(X[1:i],cbind(array(1,c(i,1)), X[1:i])%*%t,col="red",)
 ## rls fitting
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.