From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

How to monitor the progress of Levenberg-Marquardt fit

Solved!
Go to solution

Dear all,

my Levenberg-Marquardt fit works perfectly, but one iteration takes quite long, ca. 5 seconds, as expected from my problem's complexity (~50 fit parameters).

Question: How can I display the current interation count in the main program, for the user to know that it is still going on?

(My workaround until now is to set a probe within the provided Levenberg-Marquardt subroutine on that "i" that is the current interation. But this is not user-friendly.)

Thanks & best regards!

Peter, LMU München, Germany

0 Kudos
Message 1 of 4
(2,668 Views)
Solution
Accepted by topic author peterbaum

You can use your model VI to increment a count that is displayed elsewhere. If your model function computes partial derivatives, then there will be one model VI call per LM iteration plus 1 for the initial guess.  If you are not computing the partial derivatives then LM uses the central difference method to compute them.  This means 3 function calls per LM iteration, plus 3 for the initial guess.

-Jim

Message 2 of 4
(2,657 Views)

great idea, thanks!

Peter

0 Kudos
Message 3 of 4
(2,647 Views)

Sometimes it is useful to see more than just the iteration count and there are plenty of methods to do that.

 

  • In one of my programs (MultiComponent), I write the current function and current parameters to an action engine that I read out at regular intervals to actually see the fit progress of the function. I even chart the chisq.
  • In a different program (LongDistances) I actually put a graph on the model VI. Then, right before fitting, I display the FP of the model and hide it again after the fitting completes.
  • In both cases I also use an action egine to stop fitting if it does not go right or of you think the fit is good enough. If I hit <escape> in the main VI, a boolean in the action engine is changed, generating an error inside the model ("interrupted by user"), and causing the fit to end with the best parameters found so far.  (Both programs mentioned contain simulated data so you can play with the fitting mechanisms right out of the box).
  • A third method is shown in the labview example "gaussian surface with offset fit" (open the example finder and search for it). Here a reference to the graph on the main VI is sent to the model via the data variant input. Inside the model, the graph on the main VI is updated via the reference.

I would recommend to do the partial derivatives inside the model to limit the number of display updates since there are fewer model calls. This makes the relative overhead of displaying the fit progress smaller. It also potentially allows you do parallelize the computation of the partial derivatives for a great speedup, typically on the order of the number of CPU cores. I have a 16 core dual xeon and it is 17x faster when the code is parallelized. (some details are described here).

 

Message 4 of 4
(2,639 Views)