Genfit and Foster Thermal Model
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Notify Moderator
Genfit and Foster Thermal Model
Following up on thr thread https://community.ptc.com/t5/Mathcad/LeastSquaresFit-usage-for-Foster-Model-parameters/td-p/100070
Why does genfit blow up when provided with the actual Foster Model thermal fitting function and guess values used within that model when fitting to VD_12953418's digitized plot data?
I would have guessed that the genfit result would have been close to the plot of the model or to the example of digitized data.
Solved! Go to Solution.
- Labels:
-
Mathcad Usage
-
Statistics_Analysis
Accepted Solutions
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Notify Moderator
You are absolutely right that Mathcad and Prime do not help in finding a suitable function type nor in providing suitable guesses. Thats what specialized programs like CurveExpert Pro are good in.
Your example is very sensible with respect to the guesses and so a guess vector with all 1's leads to an undesired result in Prime.
I tried using vector a as a guess (the values you wrote you want to improve), but this threw an error ("found a a number greater than 10^307"). So while jiggling the parameters around to find abetter overall fit, Prime ran into this numerical IEEE limit. This also shows that the function you try to fit is quite a the edge.
I wrapped the function Z in a try and catch and used this in genfit (omitting the partial derivatives which IMHO have no effect unless you evaluate it symbolically first).
Now a decent fit could be found:
I also defined a sum of squared errors function and used "minimize" to find a good fit.
The result was even better!
Using your guess vector of all 1's still gives a decent result, but does not fit well for lower values of t.
"minimize" can be used stand alone but if you want to add additional constraints like a>0 you may also use it in a solve block.
You may also use a solve block with "minerr".
Best result in this example was achieved by minimizing the user defined sum of squared errors function with good guesses (vector a).
Curve fitting in Prime is not automatic and needs trying different attempts and a good feeling (or knowledge) for the function type and guesses.
It looks like "genfit" is a quite good allrounder but its results could sometimes be improved by using minimize and/or minerr.
EDIT: Just closed the worksheet without saving it 😞
Luckily I took the screenshots beforehand 😉
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Notify Moderator
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Notify Moderator
Thanks Terry. I always enjoy reading your responses to Mathcad questions.
But I'm afraid that I did a poor job of phrasing my real question. I'm looking for a "black box" solution, and the data in the original post is just used for convenience. I'm fairly sure that VD_12953418 drove the device with some input and then collected and plotted the response thereby generating one of many possible curves.
I want to generate a function that would generate a similar response for that same input (whatever it happened to be). This function of time should be independent of the original plot data used for its creation.
Looking at a plot of the data and selecting Mathcad prime genfit() as my tool, I guessed a collection of N exponentials for my fitting function (3 or 4 seem to work pretty well). But with no other constraints, the parameters that work as a group are "all over the place" positive, negative, large, small.
Genfit() help does not provide any hints for selecting fit functions or "guess" values.
So I asked myself the question "what would genfit() give me if I used the actual Foster Model and the actual device parameters"? R and C values are small positive numbers.
Alas, genfit(0 blows up...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Notify Moderator
You are absolutely right that Mathcad and Prime do not help in finding a suitable function type nor in providing suitable guesses. Thats what specialized programs like CurveExpert Pro are good in.
Your example is very sensible with respect to the guesses and so a guess vector with all 1's leads to an undesired result in Prime.
I tried using vector a as a guess (the values you wrote you want to improve), but this threw an error ("found a a number greater than 10^307"). So while jiggling the parameters around to find abetter overall fit, Prime ran into this numerical IEEE limit. This also shows that the function you try to fit is quite a the edge.
I wrapped the function Z in a try and catch and used this in genfit (omitting the partial derivatives which IMHO have no effect unless you evaluate it symbolically first).
Now a decent fit could be found:
I also defined a sum of squared errors function and used "minimize" to find a good fit.
The result was even better!
Using your guess vector of all 1's still gives a decent result, but does not fit well for lower values of t.
"minimize" can be used stand alone but if you want to add additional constraints like a>0 you may also use it in a solve block.
You may also use a solve block with "minerr".
Best result in this example was achieved by minimizing the user defined sum of squared errors function with good guesses (vector a).
Curve fitting in Prime is not automatic and needs trying different attempts and a good feeling (or knowledge) for the function type and guesses.
It looks like "genfit" is a quite good allrounder but its results could sometimes be improved by using minimize and/or minerr.
EDIT: Just closed the worksheet without saving it 😞
Luckily I took the screenshots beforehand 😉
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Notify Moderator
One additional remark:
In Prime 10 we can again change the algorithm used by right clicking the keyword.
Usually the default algorithm is the best choice anyway, but sometimes its worth to play around with the others as well.
In case of "genfit" we have the choice between "Optimized LM" and LM".
If we change the algorithm in your first try with "genfit" to Levenberg-Marquardt we get a much better result compared to the one using the "Optimized" variant.
BTW, we get pretty much the same optical result when we try vector a as a guess. But even though we don't run into the "number greater than 10^307" error, two of the parameters are way off.
But most of the times the default algorithm is the best choice. You may give it a try in your last fit with the four exponentials.
