cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
Showing results for 
Search instead for 
Did you mean: 

Community Tip - Learn all about PTC Community Badges. Engage with PTC and see how many you can earn! X

Levenburg Marquardt divergence

DanJoffe
1-Newbie

Levenburg Marquardt divergence

19 REPLIES 19

See

http://collab.mathsoft.com/~Mathcad2000/read?129868,15

It's long, but there you have two or more methods methods to solve a similar problem. Some ws only works into mcad 11, need few works arounds to works in mcad 14, and others are only "develp stages": good lucky.

Regards. Alvaro.

What function are you using? Levenberg-Marquardt is used by both find and minerr.

If the initial guess values actually satisfy all the constraints (something I'd need to see the worksheet to verify) I would expect find to simply return those values. How well do the modified calculated values fit the constraints?

What is actually the form of the constraints? A valid constraint must have a comparison operator at the top level. What you posted in your message does not.

I would be extremely cautious about the use of the absolute value operator. It is not differentiable, and can cause all kinds of trouble with algorithms based on the assumption of differentiability.

For find, degrees of freedom must match. If everthing is real scalars, that becomes the simple number of variables equals number of equations. But that gets modified if you work with complex numbers (two degrees of freedom) or arrays (one or two degrees per element, depending on whether the elements are real or complex). You say 36 constraints. That's quite a lot. Do you have enough variable (for which you are solving) to accomodate that?
__________________
� � � � Tom Gutman
RichardJ
19-Tanzanite
(To:DanJoffe)

On 11/18/2009 9:05:03 PM, djoffe wrote:
>Mathcad 11...Levenburg
>Marquardt solver...I can start
>it with an initial guess that
>satisfies all my
>constraints...it will grind
>and grind, eventually coming
>up with a way in left field
>answer that doesn't meet any
>of the constraints.

It sounds like you are using minerr. Something sounds very wrong though, because it should not do that.

>there are 36 constraint
>equations...of the form
>|f(x,y,z,w)-a0| LT bound. bound
>is a small constant

Avoid less than an greater than symbols on this forum. They get interpreted as HTML.

Do you have anything other than the constraints?

>f makes complex result, and
>the a's are complex also.
>
>Some cases converge
>beautifully, a few run into
>the weeds even though I
>started them in a place that
>already met all the
>constraints.
>
>Does anyone have any ideas? I
>would include the file, but
>it's big with a lot of details
>that may cloud the issue.

Actually, It's much more likely to clarify it. If it's big save it in either .mcd or .xmcdz format before posting it though (version 11 .mcd will get the widest audience), and highlight the relevant region so we can find it easily.

Richard

Thanks for all the comments. I will try some of the suggestions, and see if I can post a sufficiently clean version to allow you to see what's going on. It may take a day or so...

On 11/19/2009 10:06:02 AM, djoffe wrote:
>Thanks for all the comments. I
>will try some of the
>suggestions, and see if I can
>post a sufficiently clean
>version to allow you to see
>what's going on. It may take a
>day or so...
_______________________________

That's not an answer. You have 36 variables to solve for, i.e: you must construct "a" solver around the system. Up until now, it seems the problem is about the construct of the solver. Surely not more than one page to "prepare the solver" and one line to solve. What you might be doing or attempting to do is no guaranty your approach is correct. How do you know in advance the system has single/infinite/NO solution ?

If you post something, don't be short of explanation/source, any kind of information that will plug the reader.

jmG

A few hopefully helpful clarifications. I am using Mathcad 11.2a. The system has 36 points where we desire to minimize the error. The vector of parameters we adjust, e.g. the Minerr statement is of the form
Minerr(Td,Adc,R0,Rw1,Le,Lm,Rw2,Cc,Cp,m,v),
e.g. 11 knobs to tweak to try and get a good fit at the 36 points.

In the case at hand, even with an initial guess good enough to meet all the stated criteria, the solver grinds its way into the weeds.

I'll try to post something simpler that still exhibits the problem.

On 11/19/2009 12:11:03 PM, djoffe wrote:
...
>Minerr(Td,Adc,R0,Rw1,Le,Lm,Rw2
>,Cc,Cp,m,v),
>e.g. 11 knobs to tweak to try
>and get a good fit at the 36
>points.
>
>In the case at hand, even with
>an initial guess good enough
>to meet all the stated
>criteria, the solver grinds
>its way into the weeds.

==> What is an initial good guess ?
==> The solver decides what's good/NO good

>I'll try to post something
>simpler that still exhibits
>the problem.

==> NO, nothing simpler, because you will still do wrong !

Resume:

1. Attach just the data set as an input table ... just the data set.
2. If you have a proven model for the project, i.e: one not to be re-invented and valid, add the model below the data set.
3. As it looks secret/private/proprietary/not to be seen, then no word no nothing.

jmG





Using minerr as you state the constraints should not be inequalities, nor should they be using the absolute value function. They should be simple equalities, of the form calculated=desired. The definition of minerr is to minimize the differences between the two values.
__________________
� � � � Tom Gutman

Tom,

I have re-cast the problem in the left_side=right_side form. I have also
removed the magnitude signs. It hasn't
changed the result.

I have a streamlined version, but due to the proprietary nature, can't post it to a public forum like this...

any thoughts of other ways to try and handle this would be appreciated...

Thanks...

Dan

Just pass the data set w/o model, you will surely get something back rapidly or as annotated.



jmG

I have files ready to upload. They are cleaned up to show the problem without a lot of extra junk. Search for "good" and "bad" in the file.


As uploaded, with UTAPS:=bad/unorm, the initial pre-optimization result is great, but it goes into the weeds after optimization. If you change it to make UTAPS:=good/unorm, the initial guess is so, so, but it converges to a pretty good answer.







Load all five files into the same directory, and then make the mathcad sheet execute
(Note: this post was split into 3. With a hint from Tom, I have cleaned it up into this one post)

You can edit your own posts. Included in editing is adding/deleting attachments.
__________________
� � � � Tom Gutman

You have a number of issues, noted in the attached file. I think the biggest one is that the actual guess values used by minerr are not what you think they are. While minerr, with the original guess values, does not produce as good an answer as what you propose, it does significantly improve on the values.

Note that minerr only promises a local minimum, not a global minimum. Good guess values are important to getting the best answers. Also note that your measure of goodness is incomplete, it does not cover the additional inequality contraints you have included in the solve block. Minerr considers these constraints along with your main constraints. Errors in these constraints contribute to the overall error that minerr is minimizing.
__________________
� � � � Tom Gutman

Tom,

Thanks for looking this over. I think my single biggest mistake was not understanding, quoting from your email:

"The guess values used in the solve block are those in effect at the time the solve block is defined, not when it is invoked. This is a general rule when defining functions (whether or not solve blocks are involved) -- any variables appearing in the function definition that are not parameters of the function take on the values current at the point of the function definition."

When I actually changed the starting point, rather than just believing I had changed it, things converged just fine.

Thanks also for your comments on some of the functions, and showing me ways to write cleaner code.

Lastly...is there a book, or are there places on the site you might direct me with examples of elegant mathcad code?

Thanks and Best Regards,

Dan Joffe

If you build a data table and want to fit, put more points so that there is nothing to fit. If you have a data set from foreign source, then just the table in Mathcad input form.

What's that stuff ?



jmG

In combining the posts with the files the file names were changed (adding a serial number). Just change the names in the sheet to match the names on the server.
__________________
� � � � Tom Gutman

On 11/20/2009 3:49:48 AM, Tom_Gutman wrote:
>In combining the posts with
>the files the file names were
>changed (adding a serial
>number). Just change the
>names in the sheet to match
>the names on the server.
>__________________
>� � � � Tom Gutman
___________________________

OK, but the collab must first learn how to put data in an input table. There is more than enough in circulation to read and catch. It looks another case of of the "Mathcad User Manual" never read and no sheet read from this forum.
If you have the data set, jut put it as usual. Many collabs will open and try doing something.

Thanks for your attention, always appreciated.

jmG



Why should the collab learn to put his data in data tables? To satisfy your whims? He has the data in the form of data files, presumably with some means of generating those. Mathcad is quite capable of reading such data files, and there is no reason he should not avail himself of that facility.
__________________
� � � � Tom Gutman
Top Tags