diff options
author | Suraj Yerramilli | 2016-02-10 13:17:38 +0530 |
---|---|---|
committer | Suraj Yerramilli | 2016-02-10 13:17:38 +0530 |
commit | 483bd07eb2b1f83e1e1428007a8678793e4d7e4b (patch) | |
tree | 4839d1a91aacefad618669f500ba7e2e405d3b13 /R/estpoly.R | |
parent | bec44fa0276ab03eadc56d771352980052e36baf (diff) | |
download | SysID-R-code-483bd07eb2b1f83e1e1428007a8678793e4d7e4b.tar.gz SysID-R-code-483bd07eb2b1f83e1e1428007a8678793e4d7e4b.tar.bz2 SysID-R-code-483bd07eb2b1f83e1e1428007a8678793e4d7e4b.zip |
added the bj routine
Diffstat (limited to 'R/estpoly.R')
-rw-r--r-- | R/estpoly.R | 41 |
1 files changed, 35 insertions, 6 deletions
diff --git a/R/estpoly.R b/R/estpoly.R index 6d3a13f..a1faff9 100644 --- a/R/estpoly.R +++ b/R/estpoly.R @@ -332,7 +332,6 @@ armax <- function(x,order=c(0,1,1,0),options=optimOptions()){ #' #' @export oe <- function(x,order=c(1,1,0),options=optimOptions()){ - require(signal) y <- outputData(x); u <- inputData(x); N <- dim(y)[1] nb <- order[1];nf <- order[2]; nk <- order[3]; nb1 <- nb+nk-1 ; n <- max(nb1,nf); df <- N - nb - nf @@ -341,13 +340,9 @@ oe <- function(x,order=c(1,1,0),options=optimOptions()){ stop("Not an OE model") leftPadZeros <- function(x,n) c(rep(0,n),x) - - # Initial Guess - mod_arx <- arx(x,c(nf,nb,nk)) # fitting ARX model - iv <- matrix(predict(mod_arx)) - theta0 <- matrix(c(mod_arx$sys$B,mod_arx$sys$A[-1])) uout <- apply(u,2,leftPadZeros,n=n) + l <- levbmqdt(y,uout,order,iv,obj=oeGrad,theta0=theta0,N=N, opt=options) theta <- l$params @@ -359,4 +354,38 @@ oe <- function(x,order=c(1,1,0),options=optimOptions()){ estpoly(sys = model,stats=list(vcov = l$vcov, sigma = l$sigma), fitted.values=y-e,residuals=e,call=match.call(),input=u, options = options,termination = l$termination) +} + +#' @export +bj <- function(x,order=c(1,1,1,1,0),init_sys=NULL, + options=optimOptions()){ + y <- outputData(x); u <- inputData(x); N <- dim(y)[1] + nb <- order[1];nc <- order[2]; nd <- order[3]; + nf <- order[4]; nk <- order[5]; + nb1 <- nb+nk-1 ; n <- max(nb1,nc,nd,nf); df <- N-nb-nc-nd-nf + + # Initial Guess + mod_oe <- oe(x,c(nb,nf,nk)) + v <- resid(mod_oe); zeta <- predict(mod_oe) + mod_arma <- arima(v,order=c(nd,0,nc),include.mean = F) + theta0 <- matrix(c(mod_oe$sys$B,coef(mod_arma)[nd+1:nc], + coef(mod_arma)[1:nd],mod_oe$sys$F1[-1])) + eps <- resid(mod_arma) + + leftPadZeros <- function(x,n) c(rep(0,n),x) + uout <- apply(u,2,leftPadZeros,n=n) + + l <- levbmqdt(y,uout,order,zeta,eps,obj=bjGrad,theta0=theta0,N=N, + opt=options) + theta <- l$params + e <- ts(l$residuals,start = start(y),deltat = deltat(y)) + + model <- idpoly(B = theta[1:nb],C=c(1,theta[nb+1:nc]), + D=c(1,theta[nb+nc+1:nd]), + F1 = c(1,theta[nb+nc+nd+1:nf]), + ioDelay = nk,Ts=deltat(x)) + + estpoly(sys = model,stats=list(vcov = l$vcov, sigma = l$sigma), + fitted.values=y-e,residuals=e,call=match.call(),input=u, + options = options,termination = l$termination) }
\ No newline at end of file |