{"record":{"id":"a54981f48f825909","repo":"stanfordnlp/CoreNLP","slug":"exceeded-in-minimize-loop","errorCode":null,"errorMessage":"Exceeded in minimize() loop.","messagePattern":"Exceeded in minimize\\(\\) loop\\.","errorType":"exception","errorClass":"edu.stanford.nlp.optimization.QNMinimizer.MaxEvaluationsExceeded","httpStatus":null,"severity":"warning","filePath":"src/edu/stanford/nlp/optimization/QNMinimizer.java","lineNumber":1068,"sourceCode":"        // Add the current value and gradient to the records, this also monitors\n        // X and writes to output\n        rec.add(newValue, newGrad, newX, fevals, evalScore, sb);\n\n        // If you want to call a function and do whatever with the information ...\n        if (iterCallbackFunction != null) {\n          iterCallbackFunction.callback(newX, its, newValue, newGrad);\n        }\n\n        // shift\n        value = newValue;\n        // double[] temp = x;\n        // x = newX;\n        // newX = temp;\n        System.arraycopy(newX, 0, x, 0, x.length);\n        System.arraycopy(newGrad, 0, grad, 0, newGrad.length);\n\n        if (fevals > maxFevals) {\n          throw new MaxEvaluationsExceeded(\"Exceeded in minimize() loop.\");\n        }\n      } catch (SurpriseConvergence s) {\n        if (!quiet) log.info(\"QNMinimizer aborted due to surprise convergence\");\n        break;\n      } catch (MaxEvaluationsExceeded m) {\n        if (!quiet) {\n          log.info(\"QNMinimizer aborted due to maximum number of function evaluations\");\n          log.info(m.toString());\n          log.info(\"** This is not an acceptable termination of QNMinimizer, consider\");\n          log.info(\"** increasing the max number of evaluations, or safeguarding your\");\n          log.info(\"** program by checking the QNMinimizer.wasSuccessful() method.\");\n        }\n        break;\n      } catch (OutOfMemoryError oome) {\n        if (qn.used > 1) {\n          qn.removeFirst();\n          sb.append(\"{Caught OutOfMemory, changing m from \").append(qn.mem).append(\" to \").append(qn.used).append(\"}]\");\n          qn.mem = qn.used;","sourceCodeStart":1050,"sourceCodeEnd":1086,"githubUrl":"https://github.com/stanfordnlp/CoreNLP/blob/1b7edd19c4d0d7b1f13a2591425b9b60a0b1af7a/src/edu/stanford/nlp/optimization/QNMinimizer.java#L1050-L1086","documentation":"The main minimize() loop of QNMinimizer throws MaxEvaluationsExceeded when the number of function evaluations (fevals) exceeds maxFevals. It stops the optimizer when the evaluation budget is exhausted before convergence.","triggerScenarios":"Calling minimize() on a hard/ill-conditioned objective so convergence takes more than maxFevals function evaluations (or maxFevals was set very low, or never raised above its default).","commonSituations":"Very large feature spaces, poorly scaled data, extremely tight tolerances, or an intentionally small maxFevals for quick experiments that then fails to converge.","solutions":["Increase maxFevals (constructor argument or setter) to a larger budget.","Loosen the function tolerance so convergence is detected earlier.","Catch MaxEvaluationsExceeded and use the last iterate (the exception is thrown after x/grad were updated); improve scaling/normalization of the objective."],"exampleFix":"// before\nQNMinimizer m = new QNMinimizer(); // default maxFevals\nm.minimize(f, 1e-6, init); // MaxEvaluationsExceeded\n// after\nQNMinimizer m = new QNMinimizer(new QNMinimizer.Record(), 100000);\nm.minimize(f, 1e-4, init);","handlingStrategy":"try-catch","validationCode":"if (maxFevals <= 0 || maxFevals < 1000)\n  log.warning(\"Low maxFevals budget (\" + maxFevals + \"); QN may throw MaxEvaluationsExceeded\");","typeGuard":null,"tryCatchPattern":"try {\n  x = minimizer.minimize(f, tol, init);\n} catch (MaxEvaluationsExceeded e) {\n  log.warning(\"QN hit evaluation budget; using last iterate\");\n  x = minimizer.getBest();\n}","preventionTips":["Set maxFevals generously (>= a few thousand) for large problems.","Monitor function evaluations during development.","Loosen functionTolerance when feasible.","Scale/normalize features to speed convergence."],"tags":["optimization","convergence","max-evaluations"],"backgroundTag":"value-out-of-range","analyzedSha":"1b7edd19c4d0d7b1f13a2591425b9b60a0b1af7a","analyzedAt":"2026-09-10T02:24:07.274Z","contentChangedAt":"2026-09-10T02:24:07.274Z","schemaVersion":2},"datasetVersion":"2026-09-17T15:17:12.973Z"}