Turn on suggestions

Auto-suggest helps you quickly narrow down your search results by suggesting possible matches as you type.

Showing results for

- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Mute
- Printer Friendly Page

photoon

Member

09-28-2011 10:21 AM

Options

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report to a Moderator

Hi,

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

Solved! Go to Solution.

- Tags:
- curve fit
- Regression

DSPGuy

Active Participant

09-28-2011 04:05 PM

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report to a Moderator

You could concatenate the Y1 and Y2 data (keep as 1-D) and then pass to the nonlinear curve fit.vi. 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 fit.vi 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 fit.vi. 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.

-Jim

09-28-2011 09:44 PM

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report to a Moderator

DSPGuy,

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

altenbach

Knight of NI

09-29-2011 01:10 AM - edited 09-29-2011 01:11 AM

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report to a Moderator

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?

DSPGuy

Active Participant

09-29-2011 09:59 AM

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report to a Moderator

Doogie,

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 fit.vi, 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.

-Jim

09-29-2011 10:25 AM

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report to a Moderator

Jim,

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

Virus scan in progress. Please wait to download attachments.

altenbach

Knight of NI

09-29-2011 10:31 AM - edited 09-29-2011 10:36 AM

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report to a Moderator

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.

09-29-2011 01:06 PM - edited 09-29-2011 01:06 PM

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report to a Moderator

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.

altenbach

Knight of NI

09-29-2011 01:09 PM - edited 09-29-2011 01:09 PM

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report to a Moderator

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.

altenbach

Knight of NI

09-29-2011 01:16 PM

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report to a Moderator

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.