1

我是 Julia 的新手,正在尝试使用 JuMP 来解决 NLP,下面是代码

m = JuMP.Model(solver=Ipopt.IpoptSolver(max_iter=50,tol=1e-6))

function lkhf(x1,x2,x3,x4,x5,x6,x7,x8)
x = [x1,x2,x3,x4,x5,x6,x7,x8]
@time ll = loglikelihood(x,pdpoeFacSim,intercept, pdpoeFacMean, pdpoeFacInitial, pdpoeTarget, pdVar, poeVar,corPDPOE,resRnd)
return ll
end

JuMP.register(m, :lkhf, 8, lkhf, autodiff=true)

@nlobjective(m, Min, lkhf(x1,x2,x3,x4,x5,x6,x7,x8))

正如您从代码中看到的那样,每次求解器调用我的目标函数并注意到一些东西时,我都会尝试计时,下面是输出的一部分:

0.224411 seconds (47.41 k allocations: 198.016 MiB, 54.80% gc time)
0.027915 seconds (30.61 k allocations: 22.983 MiB, 21.84% gc time) 
0.213348 seconds (47.41 k allocations: 198.016 MiB, 56.25% gc time)    
0.026281 seconds (30.61 k allocations: 22.983 MiB, 22.52% gc time)    
0.214388 seconds (47.41 k allocations: 198.016 MiB, 55.36% gc time)    
0.028030 seconds (30.61 k allocations: 22.983 MiB, 22.65% gc time)

我不太明白为什么调用相同的目标函数会导致 gc 时间显着不同。

您能否就如何加快代码速度给我一些建议?

4

0 回答 0