forum.alglib.net

ALGLIB forum
It is currently Sun Dec 22, 2024 6:34 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.



Post new topic Reply to topic  [ 5 posts ] 
Author Message
 Post subject: optimisation in vba - Levenberg-Marquardt algorithm
PostPosted: Wed Oct 13, 2010 3:59 pm 
Offline

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'.

Thanks for your help !


Top
 Profile  
 
 Post subject: Re: optimisation in vba - Levenberg-Marquardt algorithm
PostPosted: Wed Oct 13, 2010 4:53 pm 
Offline
Site Admin

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


Top
 Profile  
 
 Post subject: Re: optimisation in vba - Levenberg-Marquardt algorithm
PostPosted: Thu Oct 14, 2010 1:32 pm 
Offline

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


Top
 Profile  
 
 Post subject: Re: optimisation in vba - Levenberg-Marquardt algorithm
PostPosted: Sun Jan 11, 2015 6:27 pm 
Offline

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
 Profile  
 
 Post subject: Re: optimisation in vba - Levenberg-Marquardt algorithm
PostPosted: Sat Jan 31, 2015 7:25 am 
Offline

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
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 5 posts ] 

All times are UTC


Who is online

Users browsing this forum: No registered users and 37 guests


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

Search for:
Jump to:  
cron
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group