{"record":{"id":"2a52c0ce1e3b5fca","repo":"stanfordnlp/CoreNLP","slug":"no-maximum-number-of-iterations-has-been-specified-2a52c0","errorCode":null,"errorMessage":"No maximum number of iterations has been specified.","messagePattern":"No maximum number of iterations has been specified\\.","errorType":"exception","errorClass":"java.lang.UnsupportedOperationException","httpStatus":null,"severity":"error","filePath":"src/edu/stanford/nlp/optimization/SGDWithAdaGradAndFOBOS.java","lineNumber":343,"sourceCode":"      }\n      featureGrouping = ((HasFeatureGrouping)f).getFeatureGrouping();\n    }\n    if (prior == Prior.sgLASSO) {\n      bCache = new double[initial.length];\n    }\n\n    System.arraycopy(initial, 0, x, 0, x.length);\n\n    int numBatches =  1;\n    if (f instanceof AbstractStochasticCachingDiffUpdateFunction) {\n      if (totalSamples > 0)\n        numBatches = totalSamples / bSize;\n    }\n\n    boolean have_max = (maxIterations > 0 || numPasses > 0);\n\n    if (!have_max){\n      throw new UnsupportedOperationException(\"No maximum number of iterations has been specified.\");\n    } else{\n      maxIterations = Math.max(maxIterations, numPasses*numBatches);\n    }\n\n    sayln(\"       Batch size of: \" + bSize);\n    sayln(\"       Data dimension of: \" + totalSamples );\n    sayln(\"       Batches per pass through data:  \" + numBatches );\n    sayln(\"       Number of passes is = \" + numPasses);\n    sayln(\"       Max iterations is = \" + maxIterations);\n\n    //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n    //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n    //            Loop\n    //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n    //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n\n    Timing total = new Timing();\n    Timing current = new Timing();","sourceCodeStart":325,"sourceCodeEnd":361,"githubUrl":"https://github.com/stanfordnlp/CoreNLP/blob/1b7edd19c4d0d7b1f13a2591425b9b60a0b1af7a/src/edu/stanford/nlp/optimization/SGDWithAdaGradAndFOBOS.java#L325-L361","documentation":"SGDWithAdaGradAndFOBOS.minimize() throws this UnsupportedOperationException when neither maxIterations nor numPasses has been set to a positive value, so the optimizer has no defined stopping point. SGD cannot run indefinitely, so this fail-fast check prevents an infinite training loop.","triggerScenarios":"Constructing SGDWithAdaGradAndFOBOS and calling minimize() without calling setMaxIterations(n) or setNumPasses(n) (or leaving both at their defaults of 0).","commonSituations":"Programmatic optimizer setup where the required setter was omitted; converting from batch optimizers (which converge on their own) to stochastic ones that require an iteration budget; properties/config file not supplying the iteration field.","solutions":["Call optimizer.setMaxIterations(n) with a positive n before minimize()","Or call optimizer.setNumPasses(n) to specify passes over the data","Check the options/properties parsing actually populates maxIterations or numPasses"],"exampleFix":"// before\nSGDWithAdaGradAndFOBOS opt = new SGDWithAdaGradAndFOBOS();\nopt.minimize(f, 1e-4, initial);\n// after\nSGDWithAdaGradAndFOBOS opt = new SGDWithAdaGradAndFOBOS();\nopt.setMaxIterations(50000);\nopt.minimize(f, 1e-4, initial);","handlingStrategy":"validation","validationCode":"SGDWithAdaGradAndFOBOS opt = new SGDWithAdaGradAndFOBOS();\nif (opt.maxIterations <= 0 && opt.numPasses <= 0) opt.setMaxIterations(50000);","typeGuard":null,"tryCatchPattern":"try { opt.minimize(f, 1e-4, initial); } catch (UnsupportedOperationException e) { opt.setMaxIterations(50000); opt.minimize(f, 1e-4, initial); }","preventionTips":["Always set maxIterations or numPasses immediately after constructing a stochastic optimizer","Use a shared options-parsing helper so iteration settings are never dropped","Add a default iteration budget in your training harness"],"tags":["java","optimization","missing-configuration"],"backgroundTag":"missing-required-config-field","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"}