Multi-dimensional Fitting

83 visualizaciones (últimos 30 días)
Muhammet Dabak
Muhammet Dabak el 25 de Dic. de 2019
Comentada: Muhammet Dabak el 27 de Dic. de 2019
I have 3 parameters for my function. Let's say f(x,y,z)=(a*x+b)*exp(-y/c)*(z^2+d) (Or i have n parameters).
I constructed the custom function because I know the behavior of the function (that I desire).
I have many samples(around 5000). For example f(1000,10,2)= 35;
Is there a method to fit these samples into a shape,solid (for 3 parameters case) ?
Or is there a method that to find the coefficients (a,b,c,d in this case) for my custom function using all my samples?
The answer doesnt have to be a specific for 3 parameter case, i need actually a solution for n parameters case.
(I know Matlab has curve fitting and surface fitting tools but no more dimensions.)
Any support will help me, thanks.

Respuesta aceptada

Walter Roberson
Walter Roberson el 25 de Dic. de 2019
You cannot use cftool it supports at most two independent variables and on dependent variable. You can, however, use your custom equation with fit() from the Curve Fitting Toolbox, or you could use nonlinear least squares https://www.mathworks.com/help/optim/nonlinear-least-squares-curve-fitting.html
fit() is often surprisingly efficient at what it does, and often generates coefficients that are close enough to optimal to be "good enough" for practical purposes.
However, in equations that have two or more major basins of attraction, fit() will typically go with the larger basin even when the smaller basin has a significantly better fit. Adding upper and lower bounds on the "reasonable" values of parameters can help a lot.
I would predict that the in your sample equation, the c value would tend to vary a lot. You do not have have an additive constant so the fitter would tend try to raise or lower the overall height by driving c large, but large values of c lead to small -y/c leading to near 1 value of exp() and relatively large changes in c have small effects, making it difficult to locate the best c value. This is a common problem for equations with exp() and a multiplicative coefficient inside.
  5 comentarios
Walter Roberson
Walter Roberson el 27 de Dic. de 2019
If the first term cannot be have a negative coefficient then put in bounds on the values.
Muhammet Dabak
Muhammet Dabak el 27 de Dic. de 2019
With the way that you show in lsqcurvefit for each variable i created a vector than I gather them and it worked.
xyz = [x.', y.', z.'];
my final equation like this:
(c1*x+c2).*exp(-y/500).*(1-c3./(c4+exp(-15*(z-0.5))))
lsqcurvefit gave me
c1=13.5195
c2=162.8643
c3=7.8244e-09
c4=1.0062e-08
These values solve my problem perfectly.
Additionally, I set lower band [0;0;0;0] to avoid possible errors.
Now, I have a function that includes linearity, exponentiality and sigmoid property.
Thank you for everything.
See you later.

Iniciar sesión para comentar.

Más respuestas (2)

Muhammet Dabak
Muhammet Dabak el 25 de Dic. de 2019
Editada: Walter Roberson el 26 de Dic. de 2019
You said I cannot use cftool because it allows 2 variables most, that is ok. But, 'use your custom equation with fit() from the Curve Fitting Toolbox' , here is the fit definition in Matlab: Fit a curve or surface to data. Means no variables more than 2.
lsqcurvefit and lsqnonlin can be used if I have just x as a variable(1 parameter).
I couldn't get what you mean by these.
And my exact function is
f(x,y,z)=(a*x+b)*exp(-y/500)*(1-c/(d+exp(-z/e))); %[ 3 unknowns,5 coefficients]
I can set some coefficients by trying , that is not the deal actually(thanks for consideration in the sample equation).
I need a way to find coefficients for at least 3 unknowns.
If you see a way to do it just give me a very simple example so I could understand you.(3unknowns,3 coefficients
for ex. f(x,y,z)=(x+a)(y+b)(z+c);
Thanks anyway.
//Edit//
Note: I tried 'polyfitn' and 'regress' functions but they supply just polynomial and linear expressions ,however, i have exponential terms. One can use these functions if your function does not contain exponential expressions. 'polyfitn' produces n variables-m degree expression for you. But you have to download it.
// This note is written for people who has similar issues about this topic.//
  1 comentario
Walter Roberson
Walter Roberson el 26 de Dic. de 2019
You are right, fit() cannot be used for 3 or more independent variables. You will need to use a nonlinear least squares such as https://www.mathworks.com/help/optim/ug/lsqcurvefit.html .
Unfortunately with the random data I generated, lsqcurvefit did not do a good job. I am experimenting further.

Iniciar sesión para comentar.


Muhammet Dabak
Muhammet Dabak el 26 de Dic. de 2019
With 'polyfitn' function describing a function as a summation of all variables in the degree that you choose.
For example:
p=polyfitn([x,y,z],t,'constant x^2 y^3 z z.*x')
formula=polyn2sym(p);
Which gives
formula= c1*x^2 + c2*y^3 + c3*z + c4*z*x + c5
Which is very useful if you can describe your function as a summation and if it just includes polynomial and linear components. If I cannot find a way to build a custom equation for my case, I will try to convert my function to eliminate exponential terms and try again.
Thank you.

Categorías

Más información sobre Get Started with Curve Fitting Toolbox en Help Center y File Exchange.

Productos


Versión

R2018b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by