File Exchange

image thumbnail

Multiple curve fitting with common parameters using NLINFIT

version 1.1 (5.21 KB) by

Wrapper for NLINFIT which allows simultaneous fitting for multiple data sets with shared parameters.

45 Downloads

Updated

View License

This function allows you to simultaneously fit multiple data sets (for example noisy measurements) with multiple models, which share some (or all) of the fitting parameters.
Unlike difference approaches using fminsearch (or similar functions), this submission wraps around NLINFIT and thus allows immediate estimation of confidence intervals on data predictions and fitted parameters.

Comments and Ratings (17)

Ana Ferreira

Very lovely code. Thanks so much. I'm wondering if it's possible to apply to only one model which changes from each data set in one scalar variable... I've been fiddling with it but with no success. Do you have any idea? Thanks

It works great for me. However I wonder whether it's possible to fix some of the parameters, so that they are not changed during fitting procedure (as in this example: http://learn-one-thing-a-day.blogspot.com/2012/11/how-to-hold-parameters-in-nlinfit-matlab.html ).
I fit complicated models with NLINMULTIFIT and now when I want to keep one of the parameters constant, I have to rearrange the whole model and vector of initial parameters.

It worked for me. It was some problem with copying and pasting the example. The code is great and can fit my equations. Thanks Chen

Chen

Chen (view profile)

Jochen Friedemann: it seems that you uncommented the example within the function file itself. You need to copy it to an outside script and run it from there.

Arman Rashidi: A bit hard to tell without more information. Which version of Matlab are you running? What is the full error message that yo receive? Feel free to contact me via email for help.

Thank you Chen for sharing this. This is the exact function that I want. First I want to run your example and let if it works on my computer and then I can use it for my data. When I try run your example it gives me this error:
Error in nlinmultifit (line 97)
for ii = 1:length(varargin)
Do you know how to fix this? Thanks in advance.

This function looks exactly like what I am looking for. If I uncomment the example it says:

Out of memory. The likely cause is an infinite recursion within the program.

Error in nlinmultifit (line 53)
nlinmultifit(x_cell, y_cell, mdl_cell, beta0);

Any ideas?
Thanks & regards,
Jochen

adi

adi (view profile)

great job! easy to use and well documented.

Chen

Chen (view profile)

Trine, thanks for your comment. I have updated the function to allow a weights function/vector to be specified, and also the default functionality is now to give equal weights to all data sets.

Dear Chen. Thank you for this file. It works fine for me. Although I have a problem since I want to weight the fitting to errors on the datasets. And I got the error 'Too many input argument using nlinmultifit' when I try to make a w_cell. Do you have a solution for this?

Luis Cerdan

Dear Chen: To make it work, even with the example your provided, I had to remove the output arguments "errorparam" and "robustw", as otherwise nlinfit gave an error (Too many output arguments). Once remove the program worked fine for my needs.

Luis Cerdan

Kevin

Kevin (view profile)

Chen

Chen (view profile)

You are always free to do the wrapping manually, yourself. I found that I routinely need to perform this task of multiple fitting, and was tired of writing code every time for different models, and came up with this solution. I hope it will help and save time to others as it did for me.

Matt J

Matt J (view profile)

OK, sorry, I didn't see that the parameters were shared.

I wonder, though, why it wouldn't be better to just manually write an mfile for the combined modelfun, instead of auto-wrapping several separate anonymous model functions into one big anonymous function?

You obviously don't intend this for wrapping a large number of model functions and data sets. The nesting of many anonymous functions would make it very slow. Conversely, for a small number of data sets, manually wrapping the problems together should be pretty easy.

Chen

Chen (view profile)

Matt: I don't understand how a for-loop would enable you to fit multiple data sets with COMMON estimation parameters.

Matt J

Matt J (view profile)

I would be surprised if this were faster than a for-loop. If I'm wrong, it might be worthwhile to add some demo files showing the advantage of the wrapping.

Updates

1.1

Updated: 1) Allow use to specify a cell array of weights vectors/functions, similarly to NLINFIT itself. 2) When a weights cell array is not provided by the user, the NLINMULTIFIT will create one by itself to give equal weight to all data sets.

1.1

Updated: 1) Allow use to specify a cell array of weights vectors/functions, similarly to NLINFIT itself. 2) When a weights cell array is not provided by the user, the NLINMULTIFIT will create one by itself to give equal weight to all data sets.

MATLAB Release
MATLAB 7.14 (R2012a)

Download apps, toolboxes, and other File Exchange content using Add-On Explorer in MATLAB.

» Watch video