T O P I C R E V I E W |
mileso |
Posted - 01/03/2011 : 02:23:12 AM Origin 8.5.0 SR1 Windows 7
Hello, I am currently working with an evaluation copy of Origin 8.5 to see about porting over an OriginC curve fitting procedure that we are using with OriginPro 7.5 SR5 in the lab at my university. Because v8.5 has the old NLSF fitter for backwards compatibility, the existing code works much as it did on our other copy of Origin. We want to take advantage, however, of all the bugfixes since v7.5 and the speed improvements that the new fitter offers. This is why we are evaluating 8.5 at the moment.
We are doing a simultaneous nonlinear fit of two functions with many shared parameters to two datasets which represent the real and imaginary parts of our data. Here is an excerpt from the FDF file to give you an idea:
[GENERAL INFORMATION]
Function Name=PerpVNA
Brief Description=
Function Source=N/A
Function Type=User-Defined
Function Form=Equations
Number Of Parameters=9
Number Of Independent Variables=1
Number Of Dependent Variables=2
Analytical Derivatives for User-Defined=Off
[FITTING PARAMETERS]
Naming Method=User-Defined
Names=Ms,alpha,Heff,phi,Xm,X1m,Ym,Y1m,Zm
Meanings=?
Initial Values=--(V)
Lower Bounds=--(X,OFF)
Upper Bounds=--(X,OFF)
Number Of Significant Digits=
[FORMULA]
Re_S21=Xm+X1m*H+Zm*(Ms*(H-Ms))*( ( ((H-Ms)^2 - Heff^2)*cos(phi) - 2*alpha*Heff*(H-Ms)*sin(phi) )/( ((H-Ms)^2 - Heff^2)^2 + (2*alpha*Heff*(H-Ms))^2 ) );
Im_S21=Ym+Y1m*H-Zm*(Ms*(H-Ms))*( ( ((H-Ms)^2 - Heff^2)*sin(phi) + 2*alpha*Heff*(H-Ms)*cos(phi) )/( ((H-Ms)^2 - Heff^2)^2 + (2*alpha*Heff*(H-Ms))^2 ) );
(...)
[INDEPENDENT VARIABLES]
H=
[DEPENDENT VARIABLES]
Re_S21=
Im_S21=
The only parameters that are not shared by both parts of the formula are the linear background lines (the first two terms in each formula). Note that, though they are similar, the functions are not identical. I have been following an example from the Origin C Programming Guide PDF, section 11.3.1 "Nonlinear Fitting" (p. 132-134). It details fitting two datasets with a shared parameter (in the example, a couple of Gaussians with shared peak center location). Unfortunately, this technique of simultaneously fitting two datasets with shared parameters seems to rely on using the same function for both datasets.
Before we go too much further with Origin 8.5, I'd like to know if there is a way to fit two different functions with shared parameters to a pair of datasets using the new fitter. I have looked into the included documentation CHM files and have not yet found any information about this. The topic "Fit on multiple datasets with one function, parameters shared" in the OriginC CHM file appears to be almost identical to section 11.3.1 in the PDF, for anyone who doesn't have that PDF but wants to see the information I'm referring to. An alternative approach to this problem might be to fit the complex data instead of breaking it up into real and imaginary parts and fitting those both simultaneously, if complex fitting is possible in Origin.
Thanks, Miles. |
5 L A T E S T R E P L I E S (Newest First) |
mileso |
Posted - 01/19/2011 : 04:14:58 AM Hi Larry,
Sorry, I forget to check that email address frequently. I see your message now, thanks. We do indeed lack completely orthogonal parameters in our model here. The way we've handled this so far is to keep Heff fixed throughout the entire fitting procedure. It is, physically, a constant in our experiment. The only reason it remains in our function is because that happens to be the way these ferromagnetic resonance equations were formulated.
In your email you describe a procedure for fitting with the NLFit dialog. I have successfully fit our data using this dialog, even without employing the careful technique of keeping Ms fixed initially, as you wrote. Unfortunately we need to fit programmatically because each time we do a new run of the experiment, we generate datasets of about 250 (or a multiple thereof) more such files to analyze. Fitting by hand in the NLFit dialog is going to be slower than just using our slow old v7.5 code. More importantly, the old code can do that task without one of us having to sit at the computer for the entire analysis procedure.
Since the fit goes well in the dialog, I assume it can be done programmatically. However, because of how slow it sometimes executes when I click the "1 iteration" button, I was curious if the dialog falls back to using the slower, old fitter if it receives input that the new fitter can't handle. If that's the case, I need to stop spending time trying to get the new fitter working and we'll just tough it out with Origin 7.5 until a newer version of Origin is able to offer what we want. (I do like what I see in the documentation about eventually moving fitting into its own separate process. We would love to make use of a multi-core processor for going even faster with multiple parallel fits.)
If there is no answer here, and looking through the included system sources still doesn't reveal how the dialog gets a proper fit, while my seemingly documentation-compliant code fails, then I guess that will be the end of my effort to solve this problem. I appreciate your help so far, Larry, and I hope that this post and my previous one will have clarified the problem I'm having. If you have some insights as to why the posted code does not work, I would be eager to hear them.
The fitting stuff all happens between the comments
//fit the data on line 344 and // Copy fit parameters and associated errors into worksheet on line 552
Thanks, Miles. |
larry_lan |
Posted - 01/19/2011 : 03:03:32 AM Hi Miles:
I sent email to you yesterday, did you get that?
Thanks Larry |
mileso |
Posted - 01/18/2011 : 7:05:53 PM I assume that this can be done programmatically because I had some success fitting one of our data files using the NLfit dialog box and the docs say that NLFitSession is the kernel of the new NLFit dialog. For all I know, though, the interface between that dialog and the fitter makes use of undocumented functionality. For instance, functions to tell the fitter important things like "which dataset corresponds to which equation in the multi-equation .FDF file". My assumption is that the lowest dataset index, 0, gets associated with the first equation and the second dataset index, 1, gets associated with the second equation, but I sure don't see that written anywhere.
This dialog allows users to specify bounds on the parameters, but I see no mention in the NLFitSession documentation for setting bounds on parameters. Does the dialog fall back to using an old fitter with more features if the user selects options that are not yet available with the new fitter?
Since the documentation doesn't tell me how to do what I need, I have taken to looking through the included source files. The following undated comment from NLFitSession.h is not very reassuring.
/**#
Hong, to do
This class seem will be hard to handle multiple function case, as multiple
function depend on Peaks Tree which is totally different, we need to think out a
solution for it, otherwise it may event fail to work with Parameter Manager as
duplicate knowledge and will be hard to maintain
*/
class NLFitSession
{
... I eventually identified \OriginC\OriginLab\NLFitting.h and NLFitting.c as the relevant files for the NLFit dialog, but it looks like instead of using the NLFitSession class directly, the dialog makes use of an NLFitSplitter object and I'm finding it pretty difficult to navigate this tangled web of oddly named, clutter-filled source files. I imagine that with enough time, I will eventually be able to answer my question of "what is the NLFit dialog doing to fit our two-function FDF file to two datasets", but if someone here can tell me the tricks that the documentation doesn't reveal, I would be most grateful.
http://www.mediafire.com/?b8vgkd7ptp3h6n4 There is a link to a .zip file with our current program source and a few representative data files, for anyone interested in having a look. Sorry the program is a single long function. I have not yet invested a lot of effort in cleaning up the file I received as a starting point - just trying to implement the new fitter at this point. If you do want to play around with it, use the default options on the dialog box that it brings up after file selection. It's an old file that has undergone many revisions and anything other than the default options may not function properly until I do some further work on things like windowing the fit, or keeping certain values fixed.
I'm pretty sure that the fit parameter values it is arriving at are bad, but because the NLFitSesssion::GetYFromX() function doesn't return Y values like it should, this has been difficult to visualize (it doesn't seem to be returning the "failure" code when it fails, either). The error values are definitely bad, they should not be on the order of 10^-300.
You'll need to manually add OriginC\OriginLab\graph_utils.c and nlsf_utils.c to the workspace or run the labtalk commands to load them into the workspace: run.LoadOC(Originlab\graph_utils.c, 16) run.LoadOC(Originlab\nlsf_utils.c, 16)
Thanks, Miles.
EDIT: I initially forgot to include the FDF file in the .zip archive. It's there now though, so the code section in my first post is unnecessary. I'm going to alter the long lines in my posts so this thread isn't so irritatingly wide.
FURTHER EDIT: Due to an apparent bug in the forum software,
Microsoft VBScript runtime error '800a000d' Type mismatch: 'rs' /forum/post.asp, line 663
I cannot edit my first post. Perhaps a moderator can trim those two long lines under the [FORMULA] heading. If so, thank you.
|
mileso |
Posted - 01/13/2011 : 7:57:16 PM Hi Larry,
I realized that I forgot to send some initial guess values for the data file I uploaded. These should lead the fitter to converge.
Guess Values: Ms = -3608.201384 alpha = 0.002539 Heff = 5358.581384 phi = -0.021591 Xm = -1.517182 X1m = 0.000000 Ym = 0.032763 Y1m = 0.000000 Zm = -0.000087
Miles. |
larry_lan |
Posted - 01/03/2011 : 9:41:04 PM Hi Miles:
To share parameters within two different functions, you can define a multiple dependent variables fitting function, and use the same paremeters in these functions. From the FDF you posted, looks like you already did that. So, I not sure why you failed. If you don't mind, could you please send the FDF and some sample data to us through this page. Then I can have a try.
Thanks Larry OriginLab Technical Services |
|
|