forum.alglib.net

ALGLIB forum
 It is currently Wed Jun 29, 2022 12:47 pm

 All times are UTC

Forum rules

1. This forum can be used for discussion of both ALGLIB-related and general numerical analysis questions
2. This forum is English-only - postings in other languages will be removed.

 Page 1 of 1 [ 5 posts ]
 Print view Previous topic | Next topic
Author Message
 Post subject: optimisation in vba - Levenberg-Marquardt algorithmPosted: Wed Oct 13, 2010 3:59 pm

Joined: Wed Oct 13, 2010 3:52 pm
Posts: 2
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'.

Top

 Post subject: Re: optimisation in vba - Levenberg-Marquardt algorithmPosted: Wed Oct 13, 2010 4:53 pm

Joined: Fri May 07, 2010 7:06 am
Posts: 871
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
&  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.

Top

 Post subject: Re: optimisation in vba - Levenberg-Marquardt algorithmPosted: Thu Oct 14, 2010 1:32 pm

Joined: Wed Oct 13, 2010 3:52 pm
Posts: 2
It works well - thanks

Top

 Post subject: Re: optimisation in vba - Levenberg-Marquardt algorithmPosted: Sun Jan 11, 2015 6:27 pm

Joined: Sun Jan 11, 2015 6:23 pm
Posts: 1
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.

Top

 Post subject: Re: optimisation in vba - Levenberg-Marquardt algorithmPosted: Sat Jan 31, 2015 7:25 am

Joined: Sat Jan 31, 2015 7:22 am
Posts: 1
ALGLIB implementation (which was actually taken from LAPACK) won't overflow until final result is close to or beyond double capacity.

_________________
second last

Top

 Display posts from previous: All posts1 day7 days2 weeks1 month3 months6 months1 year Sort by AuthorPost timeSubject AscendingDescending
 Page 1 of 1 [ 5 posts ]

 All times are UTC

Who is online

Users browsing this forum: No registered users and 2 guests

 You cannot post new topics in this forumYou cannot reply to topics in this forumYou cannot edit your posts in this forumYou cannot delete your posts in this forumYou cannot post attachments in this forum

Search for: