Showing results for 
Search instead for 
Did you mean: 

simultaneous fitting with one shared parameter

Go to solution



I have two data sets with the same X series such as (X,Y1) and (X, Y2). I have a model function y=f(x,a) with four parameters. What I try to do is to fit those two data sets for the model function simultaneously for a specific parameter. But, other three parameters are not supposed to be matched. I will use nonlinear curve fit function. If you have any ideas how to do this, please let me know


0 Kudos
Message 1 of 16

You could concatenate the Y1 and Y2 data (keep as 1-D) and then pass to the nonlinear curve  Pass the X data as is.  Inside your model function evaluate the two different models on the X data, concatenate the results, and pass out of the model function using the 'f(X,a)' indicator. 


The initial guess for the nonlinear curve should be an array with a single parameter (the shared variable for both models).  The other 3 parameters for each model could be hard coded with constants in your model function, or could be passed using the variant input to the nonlinear curve  Then inside your model function simple cast the variant back to the type you used to aggregate the parameters, probably an array or cluster, and index/unbundle to use in your model.



Message 2 of 16



I think your explanation is out of my understanding. I may need to check whether I described my question correctly. Basically, I want to fit the two data sets for one model function with 4 fit parameters. For those two fits, one specific parameter values should be matched. I called this the simultaneous fit. 


So your explanation is to generate 1D data by concatenating Y1 and Y2. Also, this should be paired with the concatenation of X and X? Why do you say two different models on the X data?


The following steps are completely new to me. Would you mind giving me more detailed explanation?


- Doogie


0 Kudos
Message 3 of 16

Since both data sets have the same x, you don't need to concatenate them. One set is enough. X is only used in the model subVI, so it is up to you to know what it means.


Your model will take the x values and calculate the function for both data sets based on the four parameters, then concatenate the two sets. The fitting algorithm will compare the concatenated sets to the original data and adjust the parameters until the best possible fit to both sets is obtained.


@photoon wrote:

Why do you say two different models on the X data?

The model for set 1 and the model for set 2, to be concatenated.



What are the two actual models? Do you have some typical data to try?

LabVIEW Champion. It all comes together in GCentral GCentral
What does "Engineering Redefined" mean??
0 Kudos
Message 4 of 16


I misunderstood your problem.  As I understand you now, you have a single model function with four parameters.  One parameter is free to be optimized, the other 3 parameters are fixed.  You have two datasets, each of which is represented by the same model. 


As Christian stated in his post, you still need to concatenate the Y datasets that are input to the nonlinear curve, so the Y input is [Y1,Y2].  There is no need to concatenate the X values from your data because they are the same.  The curve fitting algorithm only passes the X array to the model function for evaluation and does not require that it be the same size as the Y input.  In your model function just evaluate for the single X data that is passed in.  Then concatenate ('build array' primitive configured to concatenate) the model evaluation once, so your f(x,a) output is [Ymodel,Ymodel].  The fitting algorithm will then compute the error as [(Y1-Ymodel),(Y2-Ymodel)], and will minimize the squared sum of the error terms. 



0 Kudos
Message 5 of 16



I think your first understanding of my questions is correct. Among 4 parameters, one parameter is free to be optimized to be the same for both models. Three other parameters should be free to be optimized for each model. Let me attach the model function and data. Data is composed of three colums which are X, Y1, and Y2.


Then, how can I practically provide 3 other parameters for each model separately? If they are hard coded, are they still parameters?


Feel free to give any more comments and questions.


- Doogie 

Download All
0 Kudos
Message 6 of 16

What is r and why is it an integer? If r is a constant, send it via the "data" variant and convert it back to the number inside the model. If it should be a fitting parameter, you need to add it to the array of paramters.


Which one is the parameter that should be shared?


Your diagram comment in the modes says "3D gaussian". Have a look at my 2D gaussian fit here, maybe it is an extension of what you are looking for.




LabVIEW Champion. It all comes together in GCentral GCentral
What does "Engineering Redefined" mean??
0 Kudos
Message 7 of 16

r is constant. I tried to adjust it whenever I need. I am not familiar with the "data" variant. 


The shared fitting parameter is the second parameter. 


Please ignore 3D gaussian.

0 Kudos
Message 8 of 16

You need a model with 7 parameters to fit the concatenated datasets. 1 shared parameter and six remaining parameters. Three for the first set and three for the last set.

LabVIEW Champion. It all comes together in GCentral GCentral
What does "Engineering Redefined" mean??
0 Kudos
Message 9 of 16

As an example, have a look at my multicomponent EPR fitting program. We can have up to four components, each with dozens of parameters and any combination of parameter can be shared by any combination of components. Any parameter (shared or not) can be held fixed or used for fitting. All UI and fitting code is pure LabVIEW.


I guess you are trying to do something similar.

LabVIEW Champion. It all comes together in GCentral GCentral
What does "Engineering Redefined" mean??
0 Kudos
Message 10 of 16