{"record":{"id":"f98ddf672366310a","repo":"stanfordnlp/CoreNLP","slug":"variable-n-can-t-have-as-assignment-assignm","errorCode":null,"errorMessage":"Variable ${n}: Can't have as assignment (${assignment}) that is out of bounds for dimension size (${deterministic.length})","messagePattern":"Variable (.+?): Can't have as assignment \\((.+?)\\) that is out of bounds for dimension size \\((.+?)\\)","errorType":"exception","errorClass":"IllegalStateException","httpStatus":null,"severity":"error","filePath":"src/edu/stanford/nlp/loglinear/inference/CliqueTree.java","lineNumber":542,"sourceCode":"      cachedCliqueList = cliques;\n      cachedMessages = messages;\n      cachedBackwardPassedMessages = backwardPassedMessages;\n    }\n\n    // Calculate final marginals for each variable\n\n    double[][] marginals = new double[maxVar + 1][];\n\n    // Include observed variables as deterministic\n\n    for (GraphicalModel.Factor fac : model.factors) {\n      for (int i = 0; i < fac.neigborIndices.length; i++) {\n        int n = fac.neigborIndices[i];\n        if (model.getVariableMetaDataByReference(n).containsKey(VARIABLE_OBSERVED_VALUE)) {\n          double[] deterministic = new double[fac.featuresTable.getDimensions()[i]];\n          int assignment = Integer.parseInt(model.getVariableMetaDataByReference(n).get(VARIABLE_OBSERVED_VALUE));\n          if (assignment > deterministic.length) {\n            throw new IllegalStateException(\"Variable \" + n + \": Can't have as assignment (\" + assignment + \") that is out of bounds for dimension size (\" + deterministic.length + \")\");\n          }\n          deterministic[assignment] = 1.0;\n          marginals[n] = deterministic;\n        }\n      }\n    }\n\n    Map<GraphicalModel.Factor, TableFactor> jointMarginals = new IdentityHashMap<>();\n\n    if (marginalize == MarginalizationMethod.SUM && includeJointMarginalsAndPartition) {\n      boolean[] partitionIncludesTrees = new boolean[treeIndex + 1];\n      double[] treePartitionFunctions = new double[treeIndex + 1];\n\n      for (int i = 0; i < cliques.length; i++) {\n        TableFactor convergedClique = cliques[i];\n\n        for (int j = 0; j < cliques.length; j++) {\n          if (i == j) continue;","sourceCodeStart":524,"sourceCodeEnd":560,"githubUrl":"https://github.com/stanfordnlp/CoreNLP/blob/1b7edd19c4d0d7b1f13a2591425b9b60a0b1af7a/src/edu/stanford/nlp/loglinear/inference/CliqueTree.java#L524-L560","documentation":"CliqueTree.messagePassing builds a deterministic indicator vector for an observed variable using its observed assignment as an index into the factor's dimension. If the parsed VARIABLE_OBSERVED_VALUE metadata exceeds the dimension size, the index would fall outside the array, so an IllegalStateException is thrown.","triggerScenarios":"Setting variable metadata VARIABLE_OBSERVED_VALUE (e.g. via Conditioning) to an integer >= the variable's number of states/dimension size before computing marginals.","commonSituations":"Data files assigning observed values like '2' to binary variables; off-by-one usage where users pass 1-based indices into 0-based assignment space (assignment == length already triggers because the check uses >, but length-sized value for a length dimension writes at index length in the 0..length-1 space when equal... the check rejects assignment > length).","solutions":["Verify the observed value is within [0, dimensionSize-1] for the variable and fix the input metadata.","Remember assignments are 0-based; subtract 1 if your data is 1-based.","Catch IllegalStateException during calculateMarginals/result/mapMarginals and report the offending variable to the data pipeline."],"exampleFix":"// before\nmetaData.put(\"OBSERVED\", \"2\"); // binary variable\n// after\nmetaData.put(\"OBSERVED\", \"1\"); // valid 0-based index","handlingStrategy":"validation","validationCode":"int dim = model.getVariableMetaDataByReference(varId).size(); // or featuresTable dimension\nint obs = Integer.parseInt(meta.get(\"OBSERVED\"));\nif (obs < 0 || obs >= dim) throw new IllegalArgumentException(\"observed value out of range for var \" + varId);","typeGuard":"boolean isValidAssignment(int assignment, int dimensionSize) { return assignment >= 0 && assignment < dimensionSize; }","tryCatchPattern":"try { marginals = cliqueTree.calculateMarginals(); } catch (IllegalStateException e) { if (e.getMessage().contains(\"out of bounds\")) { /* fix conditioning metadata */ } else throw e; }","preventionTips":["Validate observed-value metadata against variable cardinality before inference","Use 0-based assignments consistently in training data","Log the variable ID and dimension when conditioning fails"],"tags":["loglinear","inference","index-out-of-range"],"backgroundTag":"value-out-of-range","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"}