我是朱莉娅的新手并且正在尝试使用JuMP来解决NLP,下面是代码
Sub test22()
Dim num_of_row As Long
Dim num_of_column As Long
Dim i As Long, j As Long
Dim template As Object
Dim t As Object
Dim name As String
num_of_column = 20
num_of_row = ActiveSheet.Cells(Rows.Count, "A").End(xlUp).Row - 1
With CreateObject("word.application") ' late binding
.Visible = False
For i = 1 To num_of_row
Set template = .documents.Open("D:\zzz LINH TINH\02. Test VBA\01. LRAMP\Template_KHQLMT.docx")
Set t = template.Content
For j = 1 To num_of_column
t.Find.Execute _
FindText:=ActiveSheet.Cells(1, j).Value, _
ReplaceWith:=ActiveSheet.Cells(i + 1, j).Value, _
Replace:=wdReplaceAll
Next
template.SaveAs Filename:=ThisWorkbook.Path & Application.PathSeparator & i & "-KHQLMT " & ".docx"
Next
.Quit
End With
Set t = Nothing
Set template = Nothing
End Sub
从代码中可以看出,每当求解器调用我的目标函数时,我会尝试计时并注意一些事情,下面是输出的一部分:
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))
我不太明白为什么调用相同的目标函数导致gc时间明显不同。
请您就如何加快我的代码提供一些建议?