1

How can I override the AccuracyGoal parameter in NMinimize? Instead of the evaluation stopping at the required Accuracy, I want it to stop after a specific number of iterations, even if the AccuracyGoal is not reached. I tried the following example code, but it doesn't stop after 100 iterations.

NMaximize[{Norm[Array[c1, 10], Infinity]+Norm[Array[d1, 10], Infinity], 
   And @@ Table[-1 <= c1[i] <= 1, {i, 1,10}] && And @@ Table[-1 <= d1[i] <= 1, {i, 1, 10}]}, 
  Flatten[{Array[c1, 10], Array[d1, 10]}],Method -> "SimulatedAnnealing",MaxIterations -> 100];

This question is similar to my query, but is yet to be answered.

  • There is a typo in Table[-1 <= d1[i] <= 1, {i, 1, d10}] , change d10 to 10 and your code runs.! – Ulrich Neumann May 21 '21 at 14:45
  • Yes, the code runs, but it doesn't stop after 100 iterations. – blackbird_h71 May 21 '21 at 14:56
  • That means NMaxmize doesn't need 100 iterations to find the solution! – Ulrich Neumann May 21 '21 at 15:01
  • Yes for this particular toy example. But for a much more complex problem, I would like to stop the evaluation after say N iterations. – blackbird_h71 May 21 '21 at 15:06
  • NMaximize[{Norm[Array[c1, 10], Infinity] + Norm[Array[d1, 10], Infinity], And @@ Table[-1 <= c1[i] <= 1, {i, 1, 10}] && And @@ Table[-1 <= d1[i] <= 1, {i, 1, 10}]}, Flatten[{Array[c1, 10], Array[d1, 10]}], Method -> "SimulatedAnnealing", MaxIterations -> 10] performs a warning "NMaximize::cvmit: Failed to converge to the requested accuracy or precision within 10 iterations" and – user64494 May 21 '21 at 17:10
  • {2., {c1[1] -> -0.350629, c1[2] -> 0.887276, c1[3] -> 0.354475, c1[4] -> -0.337351, c1[5] -> 0.108962, c1[6] -> -0.835742, c1[7] -> -0.5555, c1[8] -> -0.571501, c1[9] -> -1., c1[10] -> 0.384825, d1[1] -> 0.1141, d1[2] -> -0.439006, d1[3] -> 0.505844, d1[4] -> -0.986217, d1[5] -> -0.313406, d1[6] -> -0.37064, d1[7] -> 0.0101464, d1[8] -> 1., d1[9] -> 0.885465, d1[10] -> -0.13678}} – user64494 May 21 '21 at 17:10
  • Yes exactly. That means AccuracyGoal is overriding the MaxIteration option, I would like this not to happen. – blackbird_h71 May 21 '21 at 17:13
  • Adding AccuracyGoal -> 5, PrecisionGoal -> 5 options to the above code, you obtain {2., {c1[1] -> -0.350629, c1[2] -> 0.887276, c1[3] -> 0.354475, c1[4] -> -0.337351, c1[5] -> 0.108962, c1[6] -> -0.835742, c1[7] -> -0.5555, c1[8] -> -0.571501, c1[9] -> -1., c1[10] -> 0.384825, d1[1] -> 0.1141, d1[2] -> -0.439006, d1[3] -> 0.505844, d1[4] -> -0.986217, d1[5] -> -0.313406, d1[6] -> -0.37064, d1[7] -> 0.0101464, d1[8] -> 1., d1[9] -> 0.885465, d1[10] -> -0.13678}} without any messages. – user64494 May 21 '21 at 17:16
  • Yes, I have tried this. But with this, the precision with which calculations are being done internally(i.e., in the case of simulated annealing, guesses are being made or probability of accept-reject is being calculated) decreases. These won't matter much when we look at this toy example, but this will lead to unexpected issues for a much more complex objective function. – blackbird_h71 May 21 '21 at 17:25
  • Also, if the AccuracyGoal mentioned is reached before the MaxIteration specified the code will stop without reaching the MaxIteration. And I want it to reach the specified number of Iterations. – blackbird_h71 May 21 '21 at 17:32
  • First, I think AccuracyGoal -> 5, PrecisionGoal -> 5 gguarantee enough precision. Second, I don't understand the purpose of your demand "And I want it to reach the specified number of Iterations ". Isn't it art for art's sake? – user64494 May 21 '21 at 17:44
  • So, I am testing an algorithm that uses this optimization using Simulated annealing as a sub-part. So, would like to evaluate my algorithm using different limits for the iterations allowed. – blackbird_h71 May 21 '21 at 17:47
  • Sorry, I don't find your explanation to be serious. – user64494 May 21 '21 at 17:52
  • I want to benchmark my algorithm for a particular optimization, and the benchmarking requires "accuracy vs no. of iterations used" data. – blackbird_h71 May 21 '21 at 18:02

0 Answers0