diff options
author | Suraj Yerramilli | 2016-02-12 14:29:24 +0530 |
---|---|---|
committer | Suraj Yerramilli | 2016-02-12 14:29:24 +0530 |
commit | 7d0876037a42fdd11c52e08eae76870752213fcb (patch) | |
tree | 539fb7ce5492b2c197f1463531cc0480db4e5c3f | |
parent | 4ea181410b17ac2cd2d99fa686651f19d747a192 (diff) | |
download | SysID-R-code-7d0876037a42fdd11c52e08eae76870752213fcb.tar.gz SysID-R-code-7d0876037a42fdd11c52e08eae76870752213fcb.tar.bz2 SysID-R-code-7d0876037a42fdd11c52e08eae76870752213fcb.zip |
minor changes
-rw-r--r-- | R/estUtil.R | 16 |
1 files changed, 7 insertions, 9 deletions
diff --git a/R/estUtil.R b/R/estUtil.R index a526d4d..26c0fa6 100644 --- a/R/estUtil.R +++ b/R/estUtil.R @@ -13,8 +13,6 @@ levbmqdt <- function(...,obj,theta0,N,opt){ l <- obj(theta=theta0,e=NULL,dots) e <- l$Y-l$X%*%theta0 sumsq0 <- sum(e^2) - # parameter indicating whether to update gradient in the iteration - update <- 1 # variable to count the number of times objective function is called countObj <- 0 @@ -23,22 +21,22 @@ levbmqdt <- function(...,obj,theta0,N,opt){ # Update gradient l <- obj(theta0,e,dots) + g <- t(l$grad)%*%e + termPar <- norm(g,"2")/sumsq0/100 + if(termPar < tol) break + repeat{ # Update Parameters H <- t(l$grad)%*%l$grad + d*diag(dim(theta0)[1]) - Hinv <- solve(H); g <- t(l$grad)%*%e + Hinv <- solve(H); theta <- theta0 + Hinv%*%g - termPar <- norm(g,"2")/sumsq0/100 - if(termPar < tol) break - # Evaulate sum square error fn <- l$Y-l$X%*%theta sumsq <- sum(fn^2) sumSqDiff <- sumsq0-sumsq countObj <- countObj + 1 - # If sum square error with the updated parameters is less than the # previous one, the updated parameters become the current parameters # and the damping coefficient is reduced by a factor of mu @@ -53,7 +51,7 @@ levbmqdt <- function(...,obj,theta0,N,opt){ } } - if((termPar < tol)||(i == maxIter)) break + if(i == maxIter) break } if(termPar < tol){ @@ -84,7 +82,7 @@ levbmqdt <- function(...,obj,theta0,N,opt){ #' @param LMstep Size of the Levenberg-Marquardt step #' #' @export -optimOptions <- function(tol=1e-4,maxIter=20,LMinit=0.1,LMstep=2){ +optimOptions <- function(tol=1e-2,maxIter=20,LMinit=0.1,LMstep=2){ return(list(tol=tol,maxIter= maxIter, adv= list(LMinit=LMinit, LMstep=LMstep))) } |