forum.alglib.net http://forum.alglib.net/ |
|
optimisation in vba - Levenberg-Marquardt algorithm http://forum.alglib.net/viewtopic.php?f=2&t=76 |
Page 1 of 1 |
Author: | levi [ Wed Oct 13, 2010 3:59 pm ] |
Post subject: | optimisation in vba - Levenberg-Marquardt algorithm |
Hi, I am trying to use the VBA code of Algib, for optimisation, more particularly the MinLM functionnality (Levenberg-Marquardt algorithm). Can someone explain me briefly where I am supposed to write the expression of my function / its gradient (or other) ? And a brief example how to call practically the optimisation algorithm on this function ? In the manual it is said that 'reverse communication' is used instead of function pointers. I could not figure out what is 'reverse communication'. Thanks for your help ! |
Author: | Sergey.Bochkanov [ Wed Oct 13, 2010 4:53 pm ] |
Post subject: | Re: optimisation in vba - Levenberg-Marquardt algorithm |
Here is example for VBA: Code: 'Routines Public Sub DemoRoutine() Dim State As MinLMState Dim Rep As MinLMReport Dim S() As Double Dim X As Double Dim Y As Double ' ' Example of solving simple task using FJ scheme. ' ' Function minimized: ' F = (x-2*y)^2 + (x-2)^2 + (y-1)^2 ' exact solution is (2,1). ' ReDim S(0 To 2#-1) S(0#) = Rnd()-0.5 S(1#) = Rnd()-0.5 Call MinLMCreateFJ(2#, 3#, S, State) Call MinLMSetCond(State, 0.0, 0.0, 0.001, 0#) Do While MinLMIteration(State) X = State.X(0#) Y = State.X(1#) If State.NeedF then State.F = Square(X-2#*Y)+Square(X-2#)+Square(Y-1#) End If If State.NeedFiJ then State.Fi(0#) = X-2#*Y State.Fi(1#) = X-2# State.Fi(2#) = Y-1# State.J(0#,0#) = 1# State.J(0#,1#) = -2# State.J(1#,0#) = 1# State.J(1#,1#) = 0# State.J(2#,0#) = 0# State.J(2#,1#) = 1# End If Loop Call MinLMResults(State, S, Rep) ' ' output results ' ConsoleOutputString "X = " & FormatFReal(S(0#), 4, 2) _ & " (correct value - 2.00)" & vbNewLine ConsoleOutputString "Y = " & FormatFReal(S(1#), 4, 2) _ & " (correct value - 1.00)" & vbNewLine ConsoleOutputString "TerminationType = " & FormatInteger(Rep.TerminationType, 0) _ & " (should be 2 - stopping when step is small enough)" _ & vbNewLine ConsoleOutputString "NFunc = " & FormatInteger(Rep.NFunc, 0) _ & vbNewLine ConsoleOutputString "NJac = " & FormatInteger(Rep.NJac, 0) _ & vbNewLine ConsoleOutputString "NGrad = " & FormatInteger(Rep.NGrad, 0) _ & vbNewLine ConsoleOutputString "NHess = " & FormatInteger(Rep.NHess, 0) _ & vbNewLine End Sub I also recommend to read viewtopic.php?f=2&t=61&start=0 It discusses slightly different optimizer, but with similar interface. |
Author: | levi [ Thu Oct 14, 2010 1:32 pm ] |
Post subject: | Re: optimisation in vba - Levenberg-Marquardt algorithm |
It works well - thanks |
Author: | muhsanar [ Sun Jan 11, 2015 6:27 pm ] |
Post subject: | Re: optimisation in vba - Levenberg-Marquardt algorithm |
You can try to guess them from problem properties - this is the best advice known to whole numerical community so far :) Really, answer is problem-specific and there are no general recommendations which will work in any case. If you don't know what to choose, you may try several runs from random points and choose best solution. |
Author: | Chancedo1 [ Sat Jan 31, 2015 7:25 am ] |
Post subject: | Re: optimisation in vba - Levenberg-Marquardt algorithm |
ALGLIB implementation (which was actually taken from LAPACK) won't overflow until final result is close to or beyond double capacity. |
Page 1 of 1 | All times are UTC |
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group http://www.phpbb.com/ |