{"record":{"id":"9d92936b14e107c1","repo":"stanfordnlp/CoreNLP","slug":"exceeded-during-linesearch-function","errorCode":null,"errorMessage":"Exceeded during linesearch() Function.","messagePattern":"Exceeded during linesearch\\(\\) Function\\.","errorType":"exception","errorClass":"edu.stanford.nlp.optimization.QNMinimizer.MaxEvaluationsExceeded","httpStatus":null,"severity":"warning","filePath":"src/edu/stanford/nlp/optimization/QNMinimizer.java","lineNumber":1318,"sourceCode":"\n      if (newPoint[f] <= lastValue + c * dgtest)\n        break;\n      else {\n        if (newPoint[f] < lastValue) {\n          // an improvement, but not good enough... suspicious!\n          sb.append('!');\n        } else {\n          sb.append('.');\n        }\n      }\n\n      step = c1 * step;\n    }\n\n    newPoint[a] = step;\n    fevals += 1;\n    if (fevals > maxFevals) {\n      throw new MaxEvaluationsExceeded(\"Exceeded during linesearch() Function.\");\n    }\n\n    return newPoint;\n  }\n\n\n  /*\n   * lineSearchBacktrack is the original line search used for the first version\n   * of QNMinimizer. It only satisfies sufficient descent not the Wolfe conditions.\n   */\n  private double[] lineSearchBacktrack(Function func, double[] dir, double[] x,\n      double[] newX, double[] grad, double lastValue, StringBuilder sb)\n      throws MaxEvaluationsExceeded {\n\n    double normGradInDir = ArrayMath.innerProduct(dir, grad);\n    sb.append('(').append(nf.format(normGradInDir)).append(')');\n    if (normGradInDir > 0 && !quiet) {\n      log.info(\"{WARNING--- direction of positive gradient chosen!}\");","sourceCodeStart":1300,"sourceCodeEnd":1336,"githubUrl":"https://github.com/stanfordnlp/CoreNLP/blob/1b7edd19c4d0d7b1f13a2591425b9b60a0b1af7a/src/edu/stanford/nlp/optimization/QNMinimizer.java#L1300-L1336","documentation":"The backtracking lineSearch() helper throws MaxEvaluationsExceeded when the function evaluation counter fevals exceeds maxFevals during the line search phase. Same budget guard as the main loop, applied inside the (overloaded) backtracking search.","triggerScenarios":"A minimize() run whose line search performs many small-step evaluations (very small c1 multiplier, bad initial step) pushes fevals past maxFevals while still searching for a valid step length.","commonSituations":"Poorly scaled objectives or bad initial parameters forcing tiny steps; too-low maxFevals budgets; oscillating objectives where backtracking never satisfies the Armijo condition quickly.","solutions":["Raise maxFevals to accommodate line search evaluations.","Catch MaxEvaluationsExceeded and restart from a better-scaled initial point.","Normalize features / adjust functionTolerance so the line search succeeds in fewer evaluations."],"exampleFix":"// before\nminimizer.setMaxFevals(10); // exceeded inside lineSearch\n// after\nminimizer.setMaxFevals(1000);","handlingStrategy":"try-catch","validationCode":"if (maxFevals < 100) log.warning(\"maxFevals too low; line search alone can exceed it\");","typeGuard":null,"tryCatchPattern":"try {\n  x = minimizer.minimize(f, tol, init);\n} catch (MaxEvaluationsExceeded e) {\n  minimizer.setMaxFevals(maxFevals * 4);\n  x = minimizer.minimize(f, tol, init);\n}","preventionTips":["Reserve headroom in maxFevals for line search evaluations.","Normalize objective scaling so backtracking takes larger steps.","Catch MaxEvaluationsExceeded and resume/retry with a larger budget."],"tags":["optimization","line-search","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"}