10
$\begingroup$

I made a simple cosine fit to some data:

NonlinearModelFit[
                    Data[[1;;]] /. a_Around :> a["Value"],
                    {
                        A Cos[ω x + ϕ] + c,
                        {-π <= ϕ <= +π}
                    }, 
                    {{A, -0.0017}, {ω, 400}, {c, 0.01}, {ϕ}}, x,
                    VarianceEstimatorFunction->(1&), 
                    Weights -> (1/(Data[[1;;,2]] /. a_Around :> a["Uncertainty"])^2),
                    ConfidenceLevel->0.95, MaxIterations->10000
                ];

I can provide the data if necessary. The fit seems to converge successfully and the plotted result makes sense, along with the resultant fit parameters. However I do get the error message/warning:

NonlinearModelFit::acceptlev: Solved to acceptable level.

Firstly, what does this mean? How can I remove this (improve my fitting routine)? Does it have any impact on the actual results on the fit.

I have one suspicion that it is because the fit is converging near a fit constraint boundary.

I'm using Mathematica 12, so possibly why some users haven't seen this error message before and also why I couldn't find any results when I searched the error message.

The data:

{{33322.984, Around[0.007816405492811665,  0.00027463653231123993]},
 {33322.988, Around[0.010073344779686584,  0.0007117756195902295]}, 
 {33322.991, Around[0.010108725016292291,  0.0009945416303385364]}, 
 {33322.992, Around[0.008967820799845302,  0.0013022059402730695]}, 
 {33322.994, Around[0.00802865952165009,   0.0012786303668924815]}, 
 {33322.997, Around[0.0068887219740959,    0.0007474404408052571]}, 
 {33323.,    Around[0.008130289312875589,  0.00022863757915000962]}, 
 {33323.003, Around[0.009914276423570985,  0.00030355873713380484]}, 
 {33323.006, Around[0.010214891502463226,  0.001117808525551174]}, 
 {33323.008, Around[0.009013144046862024,  0.0011652145970101099]}, 
 {33323.009, Around[0.008126883089375795,  0.0013667571907391915]}, 
 {33323.012, Around[0.0068149354267696815, 0.0009386542257803183]}, 
 {33323.016, Around[0.008337596520600767,  0.00020742323701885597]}}
$\endgroup$
6
  • 5
    $\begingroup$ For those of us who haven't seen that warning before, the associated data would be essential. $\endgroup$
    – JimB
    Feb 3, 2020 at 18:09
  • 2
    $\begingroup$ That message doesn't seem to exist on my system - what version are you using exactly? Also, please provide the data, as @JimB already mentioned. $\endgroup$
    – Lukas Lang
    Feb 3, 2020 at 18:24
  • $\begingroup$ I have added the data which causes the error. I am on Mathematica 12. $\endgroup$
    – user27119
    Feb 3, 2020 at 19:08
  • $\begingroup$ I think I'll put this question up for bounty. I'd like it answered and I think it will be useful for other users to have some reference on this error message. $\endgroup$
    – user27119
    Feb 4, 2020 at 16:01
  • 4
    $\begingroup$ Looks like this error is issued by the underlying optimizer used by NonlinearModelFit (IPOPT) - the message is described here as "This indicates that the algorithm did not converge to the ''desired'' tolerances, but that it was able to obtain a point satisfying the ''acceptable'' tolerance level as specified by acceptable-* options. This may happen if the desired tolerances are too small for the current problem.". (Note that I didn't look into whether Mathematica sets the relevant options explicitly, or whether they are left at their default) $\endgroup$
    – Lukas Lang
    Feb 4, 2020 at 22:32

2 Answers 2

5
$\begingroup$

It would be nice if there would be some control over the "acceptable-tol" parameter in IPOPT, which as @Lukas points out is the method being used in the OP as well as here. The "tol" parameter seems to be set to the maximum of PrecisionGoal and AccuracyGoal, but the "acceptable-tol" parameter is left at whatever value is the default.

The OP's example did not produce the warning message for me in V12.3, so I adapted an example so that it produces the message from Even though the fit seems correct, NonlinearModelFit throws a failed convergence error.

data = {{2, -2.99380668585}, {4, -2.99413053462}, {6, -2.99439488497}, {8, 
-2.99467836024}, {10, -2.99491958936}, {12, -2.99519218472}, {14, 
-2.99538900867}, {16, -2.99562768004}, {18, -2.99584876062}, {20, 
-2.99601713877}, {22, -2.99619549077}, {24, -2.99637350562}};

accTol = 1*^-12; (* does not produce NonlinearModelFit::acceptlev *)
accTol = 1*^-8;  (* produces NonlinearModelFit::acceptlev *)
WithCleanup[
 ipoptopts = Options[IPOPTLink`Private`IPOPTSolve]
 ; Options[IPOPTLink`Private`IPOPTSolve] = 
  Append[ipoptopts, "acceptable_tol" -> N@accTol]
 ,
 fit[accTol] = 
  NonlinearModelFit[
   data, {-a + ρ r^m Cos[m ϕ + ψ], 
    r > 0}, {a, ρ, ϕ, ψ, r}, m, MaxIterations -> 100, 
   PrecisionGoal -> 12, Method -> "IPOPT"]
 ,
 Options[IPOPTLink`Private`IPOPTSolve] = ipoptopts
 ]

NonlinearModelFit::acceptlev: Solved to acceptable level.

Here we can see it makes a difference, from which I infer that option is working. (Run the above code twice, once with each setting, accTol = 1*^-8 and accTol = 1*^-12.)

fit[1*^-8]@"BestFitParameters"
fit[1*^-12]@"BestFitParameters"
(*
{a -> 2.99862, ρ -> -0.358466, ϕ -> -47.1236, ψ -> -4.69809, r -> 0.952692}
{a -> 2.99857, ρ -> -0.358328, ϕ -> -47.1236, ψ -> -4.69824, r -> 0.951456}
*) 
$\endgroup$
3
$\begingroup$

Note that this is NOT an answer to the question but rather a critique of the model and data considered.

I get the same "acceptable" message with Mathematica 12.3 but there is a simple approach to avoid that message. There are really only 2 significant figures for the predictor variable. Subtracting 33322.98 from all predictor values gets one a more numerically stable result and avoids the "acceptable" message:

(* Original model *)
nlm = NonlinearModelFit[Data[[1 ;;]] /. a_Around :> a["Value"],
   {A Cos[ω x + ϕ] + c, {-π <= ϕ <= +π}}, {{A, -0.0017}, {ω, 400}, {c, 0.01}, {ϕ}}, x, 
   VarianceEstimatorFunction -> (1 &), 
   Weights -> (1/(Data[[1 ;;, 2]] /. a_Around :> a["Uncertainty"])^2),
    ConfidenceLevel -> 0.95, MaxIterations -> 10000];

(* Modified model *)
nlm2 = NonlinearModelFit[Data[[1 ;;]] /. a_Around :> a["Value"], 
  {A Cos[ω (x - 33322.98) + ϕ] + c, {-π <= ϕ <= +π}}, {{A, -0.0017}, {ω, 400}, {c, 0.01}, {ϕ}}, x,
  VarianceEstimatorFunction -> (1 &), 
  Weights -> (1/(Data[[1 ;;, 2]] /. a_Around :> a["Uncertainty"])^2),
  ConfidenceLevel -> 0.95, MaxIterations -> 10000];

nlm["CorrelationMatrix"] // MatrixForm

Correlation matrix for original analysis

nlm2["CorrelationMatrix"] // MatrixForm

Correlation for modified model

Both models give the same predictions (other than maybe very small round-off errors) but the modified model has a much better behaved parameter correlation matrix.

But!!! Looking at the fit of either model suggests that the precision values are way overestimated (i.e., they're no good).

Show[ListPlot[Data], Plot[nlm2[x], {x, Min[Data[[All, 1]]], Max[Data[[All, 1]]]}]]

Data and fit

The data points appear much closer to the fitted curve than any of the precision values would suggest (and I'm assuming that the precision values are standard errors associated with each observation).

Fitting without weights gets one a standard error of estimate much smaller than any of the precision values. Some appears wrong with the precision values or I've made some incorrect assumptions about the precision values.

nlm3 = NonlinearModelFit[Data[[1 ;;]] /. a_Around :> a["Value"], {A Cos[ω (x - 33322.98) + ϕ] +  c,
  {-π <= ϕ <= +π}}, {{A, -0.0017}, {ω, 400}, {c, 0.01}, {ϕ}}, x,
  ConfidenceLevel -> 0.95, MaxIterations -> 10000];
nlm3["EstimatedVariance"]^0.5
(* 0.000163099 *)
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.