积分和数值优化(nlminb)R
Integral and numeric optimization (nlminb) R
我遇到的优化问题涉及包含未知变量的积分的数值估计。
数值估计积分非常简单,只需使用 R 中的积分函数即可。我正在尝试估计一个相当不愉快的积分,需要优化,因为它包含未知变量和约束。我正在使用 nlminb 函数,但结果非常不正确。这个想法是评估小于或等于 1-l 的约束的积分,其中 l 在 0 和 1 之间。
代码如下:
integrand <- function(x, p) {dnorm(x,0,1)*(1-dnorm((qnorm(p)
-sqrt(0.12)*x)/(sqrt(1-0.12)), 0, 1))^800}
未知的变量p
要最小化的objective函数如下:
objective <- function(p){
PoD <- integrate(integrand, lower = -Inf, upper = Inf, p = p)$value
PoD - 0.5
}
test <- nlminb(0.015, objective = objective, lower = 0, upper = 1)$par*100
编辑以反映 objective 函数和积分中的错误。
同样的问题仍然存在。
我认为我的错误是没有指定要最小化的变量。优化只是将 nlminb 中的起始值乘以 100。
该论文的作者使用了虚拟变量并表明 l = 0,5 应该给出 p=0,15%。
感谢您的宝贵时间。
当然,因为您的 objective 函数不依赖于 p
。做:
integrand <- function(x, p) {dnorm(x,0,1)*(1-dnorm((qnorm(p)
-sqrt(0.12)*x)/(sqrt(1-0.12)), 0, 1))^800}
objective <- function(p){
PoD <- integrate(integrand, lower = -Inf, upper = Inf, p = p)$value
PoD - 0.5
}
我遇到的优化问题涉及包含未知变量的积分的数值估计。
数值估计积分非常简单,只需使用 R 中的积分函数即可。我正在尝试估计一个相当不愉快的积分,需要优化,因为它包含未知变量和约束。我正在使用 nlminb 函数,但结果非常不正确。这个想法是评估小于或等于 1-l 的约束的积分,其中 l 在 0 和 1 之间。
代码如下:
integrand <- function(x, p) {dnorm(x,0,1)*(1-dnorm((qnorm(p)
-sqrt(0.12)*x)/(sqrt(1-0.12)), 0, 1))^800}
未知的变量p
要最小化的objective函数如下:
objective <- function(p){
PoD <- integrate(integrand, lower = -Inf, upper = Inf, p = p)$value
PoD - 0.5
}
test <- nlminb(0.015, objective = objective, lower = 0, upper = 1)$par*100
编辑以反映 objective 函数和积分中的错误。 同样的问题仍然存在。
我认为我的错误是没有指定要最小化的变量。优化只是将 nlminb 中的起始值乘以 100。
该论文的作者使用了虚拟变量并表明 l = 0,5 应该给出 p=0,15%。
感谢您的宝贵时间。
当然,因为您的 objective 函数不依赖于 p
。做:
integrand <- function(x, p) {dnorm(x,0,1)*(1-dnorm((qnorm(p)
-sqrt(0.12)*x)/(sqrt(1-0.12)), 0, 1))^800}
objective <- function(p){
PoD <- integrate(integrand, lower = -Inf, upper = Inf, p = p)$value
PoD - 0.5
}