mathematical optimization - R DEoptim() function: How to select parameters to be opimised? -
i wish estimate parameters following example:
but how can make deoptim optimise 2 of 3 parameters? - there direct method this?
rm(list=ls()) t <- seq(0.1,20,length=100) hobs <- 20 + 8*exp(-0.05*t) hsim <- function(p,t) {p[1] + p[2]*exp(-p[3]*t)} upper <- c(30,10,1) lower <- -upper resfun <- function(p, t, hobs) { r <- hobs - hsim(p,t) return(t(r)%*%r) } deoptim(resfun, lower, upper, hobs = hobs, t = t, deoptim.control(np = 80, itermax = 200, f = 1.2, cr = 0.7, trace =false))
i found workaround cf below. there more elegant way of doing this?
rm(list=ls()) t <- seq(0.1,20,length=100) hobs <- 20 + 8*exp(-0.05*t) #hkorr <- rnorm(100,0,0.2) hsim <- function(p,t) {p[1] + p[2]*exp(-p[3]*t)} upper <- c(20,10,1) lower <- c(1,1,0.001) sel = c(0,1,1) ini = c(20,na,na) # correct upper , lower selected parameters upper <- upper[which(sel==1)] lower <- lower[which(sel==1)] resfun <- function(par,t,hobs, sel, ini) { p <- rep(na,3) p[which(sel == 0)] <- ini[which(sel==0)] p[which(sel == 1)] <- par r <- hobs - hsim(p,t) return(t(r)%*%r) } deoptim(resfun, lower, upper, hobs = hobs, t = t, sel = sel, ini = ini, deoptim.control(np = 80, itermax = 200, f = 1.2, cr = 0.7, trace =false))
you can set upper
, lower
parameter value equal whichever parameter want hold constant.
# hold first parameter constant @ 20 opt <- deoptim(resfun, c(20, -10, -1), c(20, 10 ,1), hobs=hobs, t=t, deoptim.control(np=80, itermax=200, f=1.2, cr=0.7))
Comments
Post a Comment