Hi everyone! I want to use cmipack to fit my data to different models (least squares nonlinear problem) but actually I see that routine returns 1 and initial guess vector is not changed, but the fitting problem is quite simple. I think that probably I'm doing something wrong.
My fitting problem is the following. Find parameters of gaussian function (amplitude, mu, and sigma) to fit the data:
It's obvious gaussian function as we can see. In cmipack we can use several functions to fit the data. I've tried lmdif1, when the derivatives are calculated automatically using forward finite difference approximation. In this case I need just define the function to minimize:
struct FData
{
std::vector<double> x;
std::vector<double> dataToModel;
};
int gaussian_cminpack(void* p, int m, int n, const double* x,
double* fvec, int flag)
{
auto myData = reinterpret_cast<FData*>(p);
for (int i = 0; i < m; ++i)
{
double y = x[2] * exp(-0.5 * sqr((myData->x[i] - x[0]) / x[1])) / (sqrt(2 * PI) * x[1]);
fvec[i] = abs(y - sqr(myData->dataToModel[i]));
}
return 0;
}
Then I just following the documentation and
double iGuess[]{ 0.01, 0.6, 3239 };
FData data{ x1, y1 };
double fvec[9];
int iwa[3];
double wa[51];
int lwa = 51;
auto r = lmdif1(gaussian_cminpack, &data, 9, 3, iGuess, fvec, 0.01, iwa, wa, lwa);
I get r = 1 and iGuess is not changed. Why?
Also, I've tried to use lmder1, when I should give the jacobian 9x3 matrix and also I don't get some adequate result. Can you help me please?
Hi everyone! I want to use cmipack to fit my data to different models (least squares nonlinear problem) but actually I see that routine returns 1 and initial guess vector is not changed, but the fitting problem is quite simple. I think that probably I'm doing something wrong.
My fitting problem is the following. Find parameters of gaussian function (amplitude, mu, and sigma) to fit the data:
It's obvious gaussian function as we can see. In cmipack we can use several functions to fit the data. I've tried lmdif1, when the derivatives are calculated automatically using forward finite difference approximation. In this case I need just define the function to minimize:
Then I just following the documentation and
I get r = 1 and iGuess is not changed. Why?
Also, I've tried to use lmder1, when I should give the jacobian 9x3 matrix and also I don't get some adequate result. Can you help me please?