stanfordnlp/CoreNLP · error · RuntimeException
Bad arguments: " + x + " and " + lambda
Error message
Bad arguments: " + x + " and " + lambda
What it means
SloppyMath.poisson(int x, double lambda) evaluates the Poisson probability mass function; it requires x >= 0 and lambda > 0. Violations make exp(-lambda)*lambda^x/factorial(x) meaningless, so a RuntimeException("Bad arguments: ...") is thrown with both values.
Solutions
- Validate inputs before the call: if (x < 0 || lambda <= 0) skip or handle
- Fix the upstream estimate so lambda > 0 (e.g. add a small epsilon floor)
- Replace -1 missing-value sentinels with proper filtering before the call
Example fix
// before
double p = SloppyMath.poisson(x, lambda); // lambda = 0.0
// after
if (x >= 0 && lambda > 0.0) {
double p = SloppyMath.poisson(x, lambda);
} else {
// handle degenerate case
} Defensive patterns
Strategy: validation
Validate before calling
if (x < 0 || lambda <= 0.0) { /* skip or floor lambda */ lambda = Math.max(lambda, Double.MIN_VALUE); } Type guard
static boolean validPoissonArgs(int x, double lambda) { return x >= 0 && lambda > 0.0; } Try / catch
try {
double p = SloppyMath.poisson(x, lambda);
} catch (RuntimeException e) {
log.warn("poisson args invalid: " + e.getMessage());
// handle degenerate case (p undefined)
} Prevention
- Filter missing-value sentinels (like -1) out of count data before modeling
- Floor estimated rates with a small epsilon so lambda can never be 0
- Bound parameter-search ranges to lambda > 0
When it happens
Trigger: Calling poisson with a negative observed count x, or lambda <= 0 — e.g. an estimated mean rate of 0 from an empty sample, or x computed as -1 by a sentinel/missing-value convention.
Common situations: Fitting a rate from no data, using -1 as a 'missing' marker for counts, or parameter search over an unbounded range touching lambda = 0 or negative values.
Understand the failure class
Background: "Must be a positive integer", "Invalid value", "Unsupported": the invalid-argument-value error family, when a library rejects the value you pass — this error's family across 35 libraries.
Related errors
- Invalid hypergeometric
- Invalid Fisher's exact: " + "k=" + k + " n=" + n + " r=" +…
- shuffleWithSideInformation: sideInformation not of same…
- conditionalLogProbGivenPrevious requires given one less…
- conditionalLogProbsGivenPrevious requires given one less…
AI-assisted analysis of stanfordnlp/CoreNLP@1b7edd19c4 (2026-09-10).
Data as JSON: /api/errors/df55b04d3efb63e8.
Report an issue: GitHub.
Appendix: source
Thrown at src/edu/stanford/nlp/math/SloppyMath.java:661
if (cosValue < -1.0 || cosValue > 1.0) {
throw new IllegalArgumentException("Cosine is not between -1 and 1: " + cosValue);
}
int numSamples = 10000;
if (acosCache == null) {
acosCache = new float[numSamples + 1];
for (int i = 0; i <= numSamples; ++i) {
double x = 2.0 / ((double) numSamples) * ((double) i) - 1.0;
acosCache[i] = (float) Math.acos(x);
}
}
int i = ((int) (((cosValue + 1.0) / 2.0) * ((double) numSamples)));
return acosCache[i];
}
public static double poisson(int x, double lambda) {
if (x<0 || lambda<=0.0) throw new RuntimeException("Bad arguments: " + x + " and " + lambda);
double p = (Math.exp(-lambda) * Math.pow(lambda, x)) / factorial(x);
if (Double.isInfinite(p) || p<=0.0) throw new RuntimeException(Math.exp(-lambda) +" "+ Math.pow(lambda, x) + ' ' + factorial(x));
return p;
}
/**
* Uses floating point so that it can represent the really big numbers that come up.
* @param x Argument to take factorial of
* @return Factorial of argument
*/
public static double factorial(int x) {
double result = 1.0;
for (int i=x; i>1; i--) {
result *= i;
}
return result;
}
View on GitHub (pinned to 1b7edd19c4)