3
$\begingroup$

I am doing nonlinear fits on multiple datasets with several fitting parameters. Each dataset is fit with the same equation and same fitting parameters. Specifically, I am using the curve fitting toolbox in MATLAB. One of the fitting parameters should be the same across all datasets (so that the data is physically meaningful), although when I actually fit the data, this parameter can shift between sets. Is there some way to fit my datasets while constraining this fitting parameter to take on a single value?

$\endgroup$
8
  • 2
    $\begingroup$ I think the idea would be to stack your datasets into a single one, and define the model/objective to simultaneously fit a common parameter plus the per-dataset parameters. So, for $N$ datasets where the form for dataset $i$ is $A_i e^{-x_i}+A_{common}$, the combined model would be $(A_1 e^{-x_1}+A_{common}) +...+(A_N e^{-x_N}+A_{common})$, with target $y=stack(y_1,...,y_N)$ and the loss calculated over $y$. I don't know how to do this in Matlab specifically, but I expect the idea would translate over. $\endgroup$ Commented Sep 19 at 17:38
  • 2
    $\begingroup$ @MuhammedYunusSaveGaza (+1) that sounds conceptually right to me, but are you sure about the algebra ? I would have thought that you don’t sum the models across datasets. Instead keep each dataset separate and stack the residuals into one big vector. I think this is the way they do it in physics and engineering anyway, so that the shared parameter appears only once, and then the solver obviously has to make it consistent across all datasets. So, [Continued....] $\endgroup$ Commented Sep 21 at 21:38
  • 3
    $\begingroup$ [....Continued] $$ {\bf r}(\phi,\theta_1,\ldots,\theta_N)= \begin{bmatrix} y_{1}-f(x_{1};\phi,\theta_{1})\\ \vdots\\ y_{N}-f(x_{N};\phi,\theta_{N}) \end{bmatrix}, \qquad \min_{\phi,\{\theta_i\}} \|{\bf r}\|_2^2. $$ Or, with weights: $$ \min_{\phi,\{\theta_i\}} \sum_{i=1}^N \|W_i^{1/2}(y_i-f(x_i;\phi,\theta_i))\|_2^2. $$ In MATLAB, if memory serves, this is done by writing a residual function that concatenates residuals from each dataset, then passes that to lsqnonlin (or maybe lsqcurvefit,I can't remember). Then $\phi$ appears only once in the parameter vector :) $\endgroup$ Commented Sep 21 at 21:39
  • 1
    $\begingroup$ Thanks for pointing that out @RobertLong (+2). You're right - rather than a summation of terms, it should be a vector of terms like $[A_1 e^{-x_1}+A_{common}, ..., A_N e^{-x_N}+A_{common}]$, corresponding to the targets $[y_1, ..., y_N]$. I think your two comments would make a nice answer👌 $\endgroup$ Commented Sep 21 at 21:58
  • 2
    $\begingroup$ @pyrochlor, I agree, both of those approaches are good (+1 btw)., and simpler than mine For the first, using constraints, lsqcurvefit supports this, as well as weights if needed. And if memory serves, that's one of its advantages over lsqnonlin, especially for this kind of curve-fitting/optimisation problem. The second - defining the function differently - is also a great solution, particularly in cases where the shared parameter is a known, fixed value. Occam's razor springs to mind ! $\endgroup$ Commented Sep 23 at 13:59

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.