{"record":{"id":"f0226828ddcfd4c8","repo":"stanfordnlp/CoreNLP","slug":"no-maximum-number-of-iterations-has-been-specified-f02268","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/StochasticMinimizer.java","lineNumber":390,"sourceCode":"      ArrayMath.add(initial, gen.nextDouble() ); // to make sure that priors are working.\n      sdft.testSumOfBatches(initial, 1e-4);\n      System.exit(1);\n    --- */\n\n    x = initial;\n    grad = new double[x.length];\n    newX = new double[x.length];\n    gradList = new ArrayList<>();\n    numBatches =  dfunction.dataDimension()/ bSize;\n    outputFrequency = (int) Math.ceil( ((double) numBatches) /( (double) outputFrequency) )  ;\n\n    init(dfunction);\n    initFiles();\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(\"       Batchsize of: \" + bSize);\n    sayln(\"       Data dimension of: \" + dfunction.dataDimension() );\n    sayln(\"       Batches per pass through data:  \" + numBatches );\n    sayln(\"       Max iterations is = \" + maxIterations);\n\n    if (outputIterationsToFile) {\n      infoFile.println(function.domainDimension() + \"; DomainDimension \" );\n      infoFile.println(bSize + \"; batchSize \");\n      infoFile.println(maxIterations + \"; maxIterations\");\n      infoFile.println(numBatches + \"; numBatches \");\n      infoFile.println(outputFrequency  + \"; outputFrequency\");\n    }\n\n    //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!","sourceCodeStart":372,"sourceCodeEnd":408,"githubUrl":"https://github.com/stanfordnlp/CoreNLP/blob/1b7edd19c4d0d7b1f13a2591425b9b60a0b1af7a/src/edu/stanford/nlp/optimization/StochasticMinimizer.java#L372-L408","documentation":"StochasticMinimizer.minimize() throws this UnsupportedOperationException when both maxIterations and numPasses are non-positive, meaning no stopping criterion was configured. Stochastic optimizers in this library are pass/iteration-driven and refuse to start without a bound.","triggerScenarios":"Subclassing or directly using StochasticMinimizer (e.g. SGD, InefficientStochasticMinimizer) and invoking minimize() without setMaxIterations(n) or setNumPasses(n).","commonSituations":"Building a trainer programmatically and forgetting the iteration setter; a refactored config pipeline dropping the iterations option; assuming the base class supplies a default.","solutions":["Call setMaxIterations(n) with n > 0 before minimize()","Or call setNumPasses(n) to run n full passes over the data","Verify your options file/flag parsing sets the iteration fields"],"exampleFix":"// before\nStochasticMinimizer m = new SGD();\nm.minimize(f, 1e-4, initial);\n// after\nStochasticMinimizer m = new SGD();\nm.setNumPasses(10);\nm.minimize(f, 1e-4, initial);","handlingStrategy":"validation","validationCode":"StochasticMinimizer m = new SGD();\nif (m.maxIterations <= 0 && m.numPasses <= 0) m.setNumPasses(10);","typeGuard":null,"tryCatchPattern":"try { m.minimize(f, 1e-4, initial); } catch (UnsupportedOperationException e) { m.setNumPasses(10); m.minimize(f, 1e-4, initial); }","preventionTips":["Set numPasses for any StochasticMinimizer subclass before training","Validate optimizer settings in a config object before handing them to the optimizer","Never rely on defaults for stopping criteria in stochastic training"],"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-17T20:17:13.540Z"}