# Print out parameters at every 100 iterations

I am fitting some data to my model. I would like to print out parameters values say every 100 iterations (or 500) to check values getting steady state. Actually, I have a larger data and more complicate model than this and I am planning to set MaxIteration->10^5 and print out values at every 10^4 step. I don't wanna plot result at every step. Is there a way to do it? Thanks in advance.

data1= {{1.*10^-10, 380.38}, {0.001, 457.448}, {0.00215443, 548.79}, {0.00464159, 7651.56}, {0.01, 13596.2}, {0.0215443,  16416.9}, {0.0464159, 16922.2}, {0.1, 18109.2}, {0.215443, 19106.4}, {0.464159, 19317.9}, {1., 19797.5}, {10., 20514.7}};

f1[i_] := (c1 i^p1)/(is1^p1 + i^p1) + \[Epsilon]1

parameters1 = {\[Epsilon]1, c1, p1, is1};

model1 = Sum[ (Log10[f1@data1[[i, 1]]] - Log10[data1[[i, 2]]])^2, {i,12}];

fit1 = NMinimize[{model1, c1 > 0 && \[Epsilon]1 > 0 && 0 < p1 < 10 && 10^-10 < is1 <= 10}, parameters1, Method -> "DifferentialEvolution", MaxIterations ->2000]

Thread[{\[Epsilon]1, c1, p1, is1} = parameters1 /. Last@fit1];

Show[LogLogPlot[f1[i], {i, 10^-4, 10.02}, PlotRange -> All,   Frame -> True, Axes -> False, ImageSize -> 400],  ListLogLogPlot[Rest@data1, PlotStyle -> Red]]


You can use StepMonitor or EvaluationMonitor together with Reap / Sow to extract intermediate results from fitting functions. See Collecting expressions during evaluation.

Below I am using your definitions of parameters1, model1, and f1, but I changed the definition of fit1, and added intermediates to collect the running values of the parameters. I also did not assign the values to the parameters, which would give you trouble when running the code more than once; instead I use a replacement rule to plot the fit (see argument of LogLogPlot).

{fit1, intermediates} = Reap[
NMinimize[
{model1,
c1 > 0 && ϵ1 > 0 && 0 < p1 < 10 && 10^-10 < is1 <= 10},
parameters1,
MaxIterations -> 1000, Method -> "DifferentialEvolution",
StepMonitor :> Sow[parameters1]
]
];

Show[
LogLogPlot[f1[i] /. Last@fit1, {i, 10^-4, 10.02}, PlotRange -> All,
Frame -> True, Axes -> False, ImageSize -> 400],
ListLogLogPlot[Rest@data1, PlotStyle -> Red]
] (Note that at least in this case the differential evolution method was much slower than the default chosen by NMinimize. You may want to experiment with your actual data.)

Now you can plot the evolution of the parameter values during the fit. You can post-select how many to plot as well; for instance, below I will plot one value for each 2nd iteration:

ListPlot /@ Transpose@intermediates[[1, ;; ;; 2]] • Wow!! This is awesome. Thank you so much. – OkkesDulgerci Jun 13 '17 at 17:01
• Quick question: How can I make sure I am finding global minimum? – OkkesDulgerci Jun 13 '17 at 17:02
• @OkkesDulgerci It can be very, very hard to know whether you found a global minimum, or you just got stuck in a local one. You might be interested in this tutorial: Numerical Nonlinear Global Optimization. – MarcoB Jun 13 '17 at 17:07
• Thank you for reference and kind help. – OkkesDulgerci Jun 13 '17 at 17:11