stanfordnlp/CoreNLP · error · java.lang.IllegalStateException
NO SAMPLING METHOD SELECTED
Error message
NO SAMPLING METHOD SELECTED
What it means
AbstractStochasticCachingDiffFunction.getBatch selects indices for a stochastic gradient batch according to the configured sampling method. If no recognized sampling method is set (the samplingMethod switch matches none of the supported cases), it throws this IllegalStateException, meaning the optimizer's stochastic configuration is incomplete.
Solutions
- Set a supported sampling method, e.g. StochasticCalculateMethods.InlineFiniteDifference or AlgorithmicGradientDeskstepMethod via setMethod()
- Use StochasticDifferenceMethod/CycleMethod values the class implements (e.g. SunMachineOrder, RandomOrder)
- Check the enum/switch in getBatch and add handling if you added a custom sampling method
Example fix
// before AbstractStochasticCachingDiffFunction f = new MyFunc(); // sampling unset // after f.setMethod(StochasticCalculateMethods.AlgorithmicGradientDeskstepMethod); f.setSamplingMethod(...); // one of the supported methods
Defensive patterns
Strategy: validation
Validate before calling
if (func.getSamplingMethod() == null || !isSupportedSamplingMethod(func.getSamplingMethod())) func.setSamplingMethod(StochasticDifferenceMethod.RandomOrder); // or another supported value
Try / catch
try { optimizer.train(); } catch (IllegalStateException e) { if (e.getMessage().equals("NO SAMPLING METHOD SELECTED")) { configureSampling(); optimizer.train(); } else throw e; } Prevention
- Always set the sampling/calculate method right after constructing stochastic functions/minimizers
- Copy complete optimizer setup blocks from working examples, not partial ones
- Assert the configuration is complete before training starts
When it happens
Trigger: Using a StochasticMinimizer/subclass with a StochasticCalculateMethods or sampling setting that getBatch's switch does not handle, or leaving sampling unconfigured before calling stochasticEnsure/getBatch.
Common situations: Extending or configuring the stochastic optimizer with a custom/renamed sampling method enum value; constructing the function object without setting the sampling method; version drift where an enum value was removed.
Understand the failure class
Background: "is required", "must be set", "missing required field": configuration validation errors across open-source libraries — this error's family across 36 libraries.
Related errors
- Attempt to use ExternalFiniteDifference without passing…
- Doesn't support floats yet
- Vector of incorrect size passed to applyInitialHessian in…
- LogPrior.valueAt is undefined for prior of type
- Not sure if RVFDataset runs correctly in this method…
AI-assisted analysis of stanfordnlp/CoreNLP@1b7edd19c4 (2026-09-10).
Data as JSON: /api/errors/6cc62b456c3e9ded.
Report an issue: GitHub.
Appendix: source
Thrown at src/edu/stanford/nlp/optimization/AbstractStochasticCachingDiffFunction.java:221
allIndices.add(i);
}
Collections.shuffle(allIndices,randGenerator);
}
for(int i = 0; i<batchSize;i++){
thisBatch[i] = allIndices.get((curElement + i) % allIndices.size()); //Grab the next batchSize indices
}
if (curElement + batchSize > this.dataDimension()){
Collections.shuffle(allIndices, randGenerator); //Shuffle if we got to the end of the list
}
//watch out for overflow
curElement = (curElement + batchSize) % allIndices.size(); //Rollover
} else {
throw new IllegalStateException("NO SAMPLING METHOD SELECTED");
}
}
private void stochasticEnsure(double[] x, double[] v, int batchSize) {
if (lastXBatch == null) {
lastXBatch = new double[domainDimension()];
log.info("Setting previous position (x).");
}
if (lastVBatch == null) {
lastVBatch = new double[domainDimension()];
log.info("Setting previous gain (v)");
}View on GitHub (pinned to 1b7edd19c4)