I'm doing a non-linear fit on some data. The calculation residual is low, but I prefer to minimize another objective function such as:
Mean((|exp - calc)/exp|)*100
When I try to to minimize with that objective function, the results are not encouraging.
I'll try to explain better: if I calculate the fit and then the objective function, I get 0.957233; if I minimize the objective function directly, I get 0.991929. I expected it to go vice-versa.
In my real problem, I've got 4000 data points and the difference is not acceptable.
Clear["Global`*"]
data = {
{0.1067`, 0.535903658`, 0.272`, 39.90165169`},
{0.1059`, 0.526916509`, 0.272`, 39.90165169`},
{0.1017`, 0.544890806`, 0.272`, 39.90165169`},
{0.1055`, 0.512537072`, 0.272`, 39.90165169`},
{0.1035`, 0.526916509`, 0.272`, 39.90165169`},
{0.1132`, 0.455019322`, 0.272`, 39.90165169`},
{0.1108`, 0.472993619`, 0.272`, 39.90165169`},
{0.1084`, 0.490967916`, 0.272`, 39.90165169`},
{0.1059`, 0.508942213`, 0.272`, 39.90165169`}
};
exp = data[[All, 1]];
trexp = data[[All, 2]];
ccfexp = data[[All, 3]];
radiusexp = data[[All, 4]];
fit = NonlinearModelFit[data[[All, {2, 3, 4, 1}]],
a*(1 + ccf)^b + (100 + grr)^c/(1 + tr)^d,
{{a, 0.1}, {b, 0.1}, {c, 0.1}, {d, 0.1}},
{ccf, tr, grr}];
f[ccf_, grr_, tr_, a_, b_, c_, d_] =
a*(1 + ccf)^b + (100 + grr)^c/(1 + tr)^d;
desigma =
100*Mean[Map[
Abs[(#[[1]] - f[#[[3]], #[[4]], #[[2]], a, b, c, d])/#[[1]]] &,
data]];
(* NMinimize*)
m1 = NMinimize[desigma, {a, b, c, d}][[1]]
(* NonlinearModelFit *)
m2 = Mean[Abs[fit["FitResiduals"]/fit["Response"]]]*100
