{"record":{"id":"6cc62b456c3e9ded","repo":"stanfordnlp/CoreNLP","slug":"no-sampling-method-selected","errorCode":null,"errorMessage":"NO SAMPLING METHOD SELECTED","messagePattern":"NO SAMPLING METHOD SELECTED","errorType":"exception","errorClass":"java.lang.IllegalStateException","httpStatus":null,"severity":"error","filePath":"src/edu/stanford/nlp/optimization/AbstractStochasticCachingDiffFunction.java","lineNumber":221,"sourceCode":"          allIndices.add(i);\n        }\n        Collections.shuffle(allIndices,randGenerator);\n      }\n\n      for(int i = 0; i<batchSize;i++){\n        thisBatch[i] = allIndices.get((curElement + i) % allIndices.size());  //Grab the next batchSize indices\n      }\n\n      if (curElement + batchSize > this.dataDimension()){\n        Collections.shuffle(allIndices, randGenerator);    //Shuffle if we got to the end of the list\n      }\n\n      //watch out for overflow\n      curElement = (curElement + batchSize) % allIndices.size();          //Rollover\n\n\n    } else {\n      throw new IllegalStateException(\"NO SAMPLING METHOD SELECTED\");\n    }\n\n  }\n\n\n\n\n  private void stochasticEnsure(double[] x, double[] v, int batchSize) {\n\n    if (lastXBatch == null) {\n      lastXBatch = new double[domainDimension()];\n      log.info(\"Setting previous position (x).\");\n    }\n\n    if (lastVBatch == null) {\n      lastVBatch = new double[domainDimension()];\n      log.info(\"Setting previous gain (v)\");\n    }","sourceCodeStart":203,"sourceCodeEnd":239,"githubUrl":"https://github.com/stanfordnlp/CoreNLP/blob/1b7edd19c4d0d7b1f13a2591425b9b60a0b1af7a/src/edu/stanford/nlp/optimization/AbstractStochasticCachingDiffFunction.java#L203-L239","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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"],"exampleFix":"// before\nAbstractStochasticCachingDiffFunction f = new MyFunc(); // sampling unset\n// after\nf.setMethod(StochasticCalculateMethods.AlgorithmicGradientDeskstepMethod);\nf.setSamplingMethod(...); // one of the supported methods","handlingStrategy":"validation","validationCode":"if (func.getSamplingMethod() == null || !isSupportedSamplingMethod(func.getSamplingMethod()))\n  func.setSamplingMethod(StochasticDifferenceMethod.RandomOrder); // or another supported value","typeGuard":null,"tryCatchPattern":"try { optimizer.train(); } catch (IllegalStateException e) { if (e.getMessage().equals(\"NO SAMPLING METHOD SELECTED\")) { configureSampling(); optimizer.train(); } else throw e; }","preventionTips":["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"],"tags":["java","stanford-nlp","optimization","uninitialized-state"],"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-15T23:17:13.987Z"}