问题描述
我有一个目标函数,看起来像
function myfun(θ,x)
logτ = θ
s(ϵ) = 1.0/sqrt(exp(logτ)) * ϵ
p(ϵ) = 1/(1 + 0.5 * exp((0.5 - s(ϵ))*exp(logτ)))
integrand(ϵ) = normcdf(0.0,1.0,x + p(ϵ))*(1/sqrt(2.0*π)*exp(-(ϵ^2.0)/2.0))
(expectation,err) = quadgk(ϵ -> integrand(ϵ),-4.0,4.0,rtol = 0.0001)
return expectation
end
我使用logτ
作为参数,以确保优化为τ
提供正值。当我运行优化时,经过几次迭代我通常会得到
ERROR: DomainError with 0.0:
integrand produced NaN in the interval (-4.0,4.0)
这是因为在搜索过程中τ
接近零时,例如logτ= -1000时,exp(logτ)
恰好返回零,而不是很小的正值。在这种情况下,s(ϵ)
变成Inf
,而p(ϵ)
变成NaN。
我试图添加
if logτ < -100
logτ = -100
end
这是不希望的,因为它会大大降低优化速度。有没有更好的解决方案来解决这个问题?
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)