Normally, reducing the optimization domain by adding constraints should reduce the time of execution. In my case however, this puts the NonlinearModelFit in a coma. Without constraints, 8 seconds suffice:
pobTotal = 4950738;
mu = 7*41157/365 // N(* weekly births *);
d = mu/pobTotal;
reported = {107, 135, 612, 195, 626, 619, 491, 1164, 1137, 511, 1036,
1144, 2650, 3162, 6074, 6693, 8253, 6639, 6148, 4345, 3141, 1958,
1130, 484, 356, 296, 195, 121, 208, 101, 67, 128, 20};
data = Thread[{Range[1, 33], reported}];
T = Length[reported ];
mod[\[Gamma]_?NumericQ, \[Beta]_?NumericQ, s0_?NumericQ,
i0_?NumericQ] :=
NDSolveValue[{s'[t] ==
mu - (\[Beta]*s[t]*i[t]/pobTotal) - d*s[t],
i'[t] == (\[Beta]*s[t]*i[t]/pobTotal) - (\[Gamma] + d)*i[t],
s[0] == s0,
i[0] == i0}, {s, i}, {t, 0, 33}, MaxStepSize -> 400][[2]];
Timing[nlm =
NonlinearModelFit[
data, { p*mod[\[Gamma], \[Beta], s0, i0][t]}, {\[Gamma], \[Beta],
s0, i0, p}, t]] // Quiet
{ \[Gamma]2, \[Beta]2, s02, i02,
p2} = { \[Gamma], \[Beta], s0, i0, p} /. nlm["BestFitParameters"]
With constraints:
Timing[nlm2 =
NonlinearModelFit[
data, {p* mod[\[Gamma], \[Beta], s0, i0][t], 1 < \[Gamma] < 1.4 ,
0 < \[Beta], s0 > 1, 1 < i0, 0 < p},
{\[Gamma], \[Beta], s0, i0, p}, t]] // Quiet
{\[Gamma]3, \[Beta]3, s03, i03,
p3} = {\[Gamma], \[Beta], s0, i0, p} /. nlm2["BestFitParameters"]
the execution times gets multiplied by a 100 (900 secs). How to explain this; is it possible to reduce this time?