{"record":{"id":"d87f68958231b6a8","repo":"stanfordnlp/CoreNLP","slug":"maxvalue-for-feature","errorCode":null,"errorMessage":"maxValue for feature ","messagePattern":"maxValue for feature ","errorType":"exception","errorClass":"RuntimeException","httpStatus":null,"severity":"error","filePath":"src/edu/stanford/nlp/classify/RVFDataset.java","lineNumber":199,"sourceCode":"\n    // first identify the max and min values for each feature.\n    // System.out.printf(\"number of datums: %d dataset size: %d\\n\",data.length,size());\n    for (int i = 0; i < size(); i++) {\n      // System.out.printf(\"datum %d length %d\\n\", i,data[i].length);\n      for (int j = 0; j < data[i].length; j++) {\n        int f = data[i][j];\n        if (values[i][j] < minValues[f])\n          minValues[f] = values[i][j];\n        if (values[i][j] > maxValues[f])\n          maxValues[f] = values[i][j];\n      }\n    }\n\n    for (int f = 0; f < featureIndex.size(); f++) {\n      if (minValues[f] == Double.POSITIVE_INFINITY)\n        throw new RuntimeException(\"minValue for feature \" + f + \" not assigned. \");\n      if (maxValues[f] == Double.NEGATIVE_INFINITY)\n        throw new RuntimeException(\"maxValue for feature \" + f + \" not assigned.\");\n    }\n\n    // now scale each value such that it's between 0 and 1.\n    for (int i = 0; i < size(); i++) {\n      for (int j = 0; j < data[i].length; j++) {\n        int f = data[i][j];\n        if (minValues[f] != maxValues[f])// the equality can happen for binary\n                                         // features which always take the value\n                                         // of 1.0\n          values[i][j] = (values[i][j] - minValues[f]) / (maxValues[f] - minValues[f]);\n      }\n    }\n\n    /*\n    for(int f = 0; f < featureIndex.size(); f++){\n      if(minValues[f] == maxValues[f])\n        throw new RuntimeException(\"minValue for feature \"+f+\" is equal to maxValue:\"+minValues[f]);\n    }","sourceCodeStart":181,"sourceCodeEnd":217,"githubUrl":"https://github.com/stanfordnlp/CoreNLP/blob/1b7edd19c4d0d7b1f13a2591425b9b60a0b1af7a/src/edu/stanford/nlp/classify/RVFDataset.java#L181-L217","documentation":"Companion check to the minValue failure: maxValues[f] starts at -Infinity and is updated while scanning values. If a feature exists in featureIndex but never appears in any datum's values, its max stays -Infinity and scaleFeatures throws, since scaling to [0,1] needs a defined maximum. The message identifies the offending feature index.","triggerScenarios":"Calling scaleFeatures (or scaleDatum which triggers it) on an RVFDataset containing features in featureIndex with no observed values anywhere in the dataset, leaving maxValues[f] unassigned.","commonSituations":"Datasets constructed programmatically with features added to the index but not used in datums; featureIndex locked/extended out-of-band; datums with empty feature maps; copied datasets sharing a stale featureIndex.","solutions":["Verify each featureIndex entry is present with a value in at least one datum before scaling","Compute scaling on the whole dataset once via scaleFeatures rather than per-datum scaleDatum calls with uninitialized bounds","Rebuild the dataset with a featureIndex derived only from observed features","Skip or prune unused features before scaling"],"exampleFix":"// before\nfeatureIndex.add(\"unusedFeature\"); // never appears in any datum\nds.scaleFeatures(); // throws: maxValue not assigned\n// after\n// only add features as they occur\nfor (String f : datumFeatures) featureIndex.add(f);\nds.scaleFeatures();","handlingStrategy":"validation","validationCode":"for (int f = 0; f < ds.featureIndex().size(); f++) {\n  boolean observed = false;\n  for (int i = 0; i < ds.size() && !observed; i++) observed = ds.getDatum(i).asFeatures().contains(ds.featureIndex().get(f));\n  if (!observed) throw new IllegalStateException(\"maxValue unassigned for feature \" + f);\n}","typeGuard":null,"tryCatchPattern":"try {\n  ds.scaleFeatures();\n} catch (RuntimeException e) {\n  if (e.getMessage().startsWith(\"maxValue\")) {\n    logger.warning(\"Feature never observed; prune featureIndex and rebuild\");\n  } else throw e;\n}","preventionTips":["Build featureIndex exclusively from observed datum features","Avoid locking/merging featureIndexes across datasets with divergent feature sets","Run scaling once over the complete dataset"],"tags":["java","stanford-nlp","machine-learning","feature-scaling"],"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-15T23:17:13.987Z"}