kaushikrch / rucm

Implementation of Unobserved Components Models (UCM) in R
3 stars 3 forks source link

Customizing fitSSM function to incorporate Trust Region Optimization using package trustOptim #5

Open RajarshiBhadra opened 8 years ago

RajarshiBhadra commented 8 years ago

Currently the fitSSM module uses optim package for minimizing the likelihood function. For expanding the capability of rucm to incorporate Trust Region Optimization while minimizing the likelihood function in the fitSSM , the code can be modified using packages trustOptim (For trust Region Optimization) and numDeriv (For gradient calculations) in the following way:

Current

fitSSM <- 
function (model, inits, updatefn, checkfn, update_args = NULL, 
    ...)
{ .............
out$optim.out <- optim(par = inits, fn = likfn, model = model, 
        ...)
out$model <- do.call(updatefn, args = c(list(out$optim.out$par, 
        model), update_args))
...............
}

Proposed Customization

fitSSM_cus <- 
function (model, inits, updatefn, checkfn, update_args = NULL, 
    ...)
{ .............
gradient <- function(x,model,...){
    return(numDeriv::grad(likfn,x,model=model,...))
  }
out <- NULL
out$optim.out <- trustOptim::trust.optim(x = inits, fn = likfn, gr= gradient,method = "SR1", model= model, control = list(report.level = 0,start.trust.radius = 5, maxit = 1000), ...)
out$model <- do.call(updatefn, args = c(list(out$optim.out$solution, 
        model), update_args))
.................
}