constrOptim总是返回起始值为optima,counts = 0,iterations = 1

时间:2017-02-20 20:25:49

标签: r math optimization mathematical-optimization

我的约束优化正在发生一些有趣的事情,但我不确定问题是什么。 "优化"值始终与我的起始值相同。它表示已收敛,但计数= 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

0 个答案:

没有答案