RegressionModelUtil { static public <K, V extends Number> ValueMap<K, V> computeMultinomialProbabilities(RegressionModel.NormalizationMethod normalizationMethod, ValueMap<K, V> values){ if(values.size() < 2){ throw new IllegalArgumentException(); } switch(normalizationMethod){ case NONE: { Value<V> sum = null; Iterator<Value<V>> valueIt = values.iterator(); for(int i = 0, max = values.size() - 1; i < max; i++){ Value<V> value = valueIt.next(); if(sum == null){ sum = value.copy(); } else { sum.add(value); } } Value<V> lastValue = valueIt.next(); lastValue.residual(sum); } break; case LOGIT: { for(Value<V> value : values){ value.inverseLogit(); } } case SIMPLEMAX: { ValueUtil.normalizeSimpleMax(values); } break; case SOFTMAX: { ValueUtil.normalizeSoftMax(values); } break; default: throw new IllegalArgumentException(); } return values; } private  RegressionModelUtil(); static ValueMap<K, V> computeBinomialProbabilities(RegressionModel.NormalizationMethod normalizationMethod, ValueMap<K, V> values); static ValueMap<K, V> computeMultinomialProbabilities(RegressionModel.NormalizationMethod normalizationMethod, ValueMap<K, V> values); static ValueMap<K, V> computeOrdinalProbabilities(RegressionModel.NormalizationMethod normalizationMethod, ValueMap<K, V> values); static Value<V> normalizeRegressionResult(RegressionModel.NormalizationMethod normalizationMethod, Value<V> value); static Value<V> normalizeBinaryLogisticClassificationResult(RegressionModel.NormalizationMethod normalizationMethod, Value<V> value);  }
@Test public void computeMultinomialProbabilities(){ ValueMap<String, Float> values = new ValueMap<>(); values.put("red", new FloatValue(0.3f)); values.put("yellow", new FloatValue(0.5f)); values.put("green", new FloatValue(Float.MAX_VALUE)); RegressionModelUtil.computeMultinomialProbabilities(RegressionModel.NormalizationMethod.NONE, values); assertEquals(new FloatValue(0.3f), values.get("red")); assertEquals(new FloatValue(0.5f), values.get("yellow")); assertEquals(new FloatValue(1f - (0.3f + 0.5f)), values.get("green")); }