提问人:Hack-R 提问时间:2/21/2017 最后编辑:Erwin KalvelagenHack-R 更新时间:2/23/2017 访问量:382
constrOptim 始终以 optima 的形式返回起始值,计数 = 0,迭代次数 = 1
constrOptim always returns starting values as optima, counts = 0, iterations = 1
问:
我的约束优化发生了一些有趣的事情,但我不确定问题出在哪里。“优化”值始终与我的起始值完全相同。它说它是收敛的,但计数 = 0,迭代次数 = 1。我不知道为什么。
options(scipens=15)
# Argument Vector ---------------------------------------------------------
# Starting values
args <- c(3553.13, 727.48)
# Revenue Formula ---------------------------------------------------------
intercept <- -4.5315
p_elast <- -.065
o_elast <- .066
leads <- 20000
rev_fn <- function(args){
CR <- exp(intercept + (p_elast*log(args[1])) + (o_elast*log(args[2])))
price <- args[1]-args[2] # charges - offer amount
quantity <- leads*CR # leads * CR
revenue <- price*quantity
return(revenue)
}
rev_fn(args)
# Gradient Function -------------------------------------------------------
gr <- function(args){
c(leads * (exp(intercept + (p_elast * log(args[1])) + (o_elast *
log(args[2]))) * (p_elast * (1/args[1]))),
leads * (exp(intercept + (p_elast * log(args[1])) + (o_elast *
log(args[2]))) * (o_elast * (1/args[2])))
)
}
# Constrained Optimization ------------------------------------------------
# Constraints
# 1. Gross price > 0
# 2. Offer > 0
# 3. Gross price > offer
constraint_matrix <- matrix(c(1,0,1,0,1,-1),ncol=2)
constraint_vector <- c(0,0,0)
# Note: feasible region = ui %*% theta - ci >= 0
constrOptim(theta = c(args[1], # gross price
args[2] # offer amount
),
f = rev_fn,
grad = gr,
ui = constraint_matrix, # constraint matrix (k x p)
ci = constraint_vector, # constraint vector of length k
control = list(fnscale = -1) # maximization
)
$par [1] 3553.13 727.48 $value [1] 552374.2 $counts [1] 0 $convergence [1] 0 $message NULL $outer.iterations [1] 1 $barrier.value [1] 4.919046
答: 暂无答案
评论