[R] Problem to optimize a truncated function with auglag (alabama)

Siebert jan.siebert at ibes.uni-due.de
Tue Jul 28 15:05:28 CEST 2015


Hello,
I use the auglag-command of the alabama package to optimize a function under
constraints. The function is truncated at -400. I am afraid, that the
auglag-command has problems to maximize this function.  The solution found
by the auglag-command is not even close to the optimum. It is easy to show
that other values than the solution found by auglag are producing higher
output values and still fulfill the constraints. Does anybody know how I can
optimize that function with auglag or with another R-command?
Thank you very much for any commands and suggestions.

The following explanation is just to understand the background of the
optimization problem. It has nothing to do with the code problem. The
function goes back to an economic intertemporal consumption model. I am
looking for an optimal solution for the consumption-saving-lifetime-plan. 
The utility is the sum of the utilities of 30 periods. The utility in each
period depends on the current consumption and on a habit stock it is never
below -400. The habit stock is a function of the consumption in the last
periods.

# Here is the data I am using:
expectations<-c(124.671, 49.238595, 15.2649945, 85.8809574, 130.43232916875, 
                45.1340382917813, 14.8597845206344, 121.3933676634,
75.1980497225319, 
                76.9945912185161, 184.798095407901, 139.642709300636,
182.57573338504, 
                322.923072570281, 275.238211364469, 155.536259099569,
54.7838218320803, 
                285.968249457082, 644.995614202314, 385.243665085798,
60.2035902594974, 
                218.295491752216, 168.796319321643, 387.193213147244,
110.975689063189, 
                333.047669801961, 81.5607312506053, 253.458002848022,
28.3825973908511, 
                458.282304918595)

habit_ex<-10

# Here is the function I like to optimize:

utility<-function(consum){
  period<<-0
  consum<<-consum
  sum(
    sapply(consum, utility_t)
  )
}

utility_t<-function(consum_t){
  period<<-period+1
  max(c(-400, (40+750*(((consum_t+2.7)/habit(consum, period
  )^0.6)^-2/-2))*5.5))
}

habit<-function(consum, period){if (period==1){habit_ex} else
{0.7*habit(consum, period-1)+consum[(period-1)]}}

# Here are the constraints:

hin<-function(consum){
  h<-rep(NA, 60)
    for (j in 1:30){
      h[j]<-  sum(expectations[1:j]) - sum(consum[1:j])
      h[(j+30)]<-consum[j]
    }
  h
}

# Here is the code to optimize:

install.packages("alabama")
library(alabama)

start<-c(1:30)

ans <- auglag(start, fn=utility, hin=hin, control.optim = list(fnscale =
-1), control.outer = list(sig0 = 100, trace=TRUE))



# Here is an example for input values that have a higher output than the
solution of auglag:  
opt1<-c(15.057, 27.135, 41.067, 55.62, 70.047, 83.79, 96.516, 108.558, 
119.637, 120, 139.707, 148.77, 157.185, 165.339, 174.249, 182.295, 
190.314, 199.359, 208.485, 219.168, 228.816, 240.12, 253.782, 
267.39, 237.705, 254.475, 280.41, 312.8925, 372.9975, 484.432)
utility(opt1)




--
View this message in context: http://r.789695.n4.nabble.com/Problem-to-optimize-a-truncated-function-with-auglag-alabama-tp4710478.html
Sent from the R help mailing list archive at Nabble.com.



More information about the R-help mailing list