public void put(String key, Value<V> value){ ValueMap<String, V> values = getValues(); if(values.containsKey(key)){ throw new EvaluationException("Value for key " + PMMLException.formatKey(key) + " has already been defined"); } values.put(key, value); }
protected Set<Map.Entry<String, Value<V>>> entrySet(){ ValueMap<String, V> values = getValues(); return values.entrySet(); }
protected Value<V> ensureValue(K key){ Value<V> value = get(key); if(value == null){ ValueFactory<V> valueFactory = getValueFactory(); value = valueFactory.newValue(); put(key, value); } return value; } }
static public <K, V extends Number> ValueMap<K, V> computeBinomialProbabilities(RegressionModel.NormalizationMethod normalizationMethod, ValueMap<K, V> values){ if(values.size() != 2){ throw new IllegalArgumentException(); } Iterator<Value<V>> valueIt = values.iterator(); Value<V> firstValue = valueIt.next(); // The probability of the first category is calculated normalizeBinaryLogisticClassificationResult(normalizationMethod, firstValue); Value<V> secondValue = valueIt.next(); // The probability of the second category is obtained by subtracting the probability of the first category from 1.0 secondValue.residual(firstValue); return values; }
ValueMap<String, V> values = new ValueMap<>(2 * regressionTables.size()); values.put(targetCategory, value); if((OpType.CATEGORICAL).equals(opType)){ if(values.size() == 2){ RegressionModelUtil.computeBinomialProbabilities(normalizationMethod, values); } else if((values.size() == 2 && isDefault(regressionTables.get(1)) && (RegressionModel.NormalizationMethod.SOFTMAX).equals(normalizationMethod))){ RegressionModelUtil.computeBinomialProbabilities(RegressionModel.NormalizationMethod.LOGIT, values); } else if((OpType.CATEGORICAL).equals(opType)){ if(values.size() == 2){ RegressionModelUtil.computeBinomialProbabilities(normalizationMethod, values); } else if(values.size() > 2 && (RegressionModel.NormalizationMethod.LOGIT).equals(normalizationMethod)){ RegressionModelUtil.computeMultinomialProbabilities(normalizationMethod, values); } else
private <V extends Number> ClusterAffinityDistribution<V> createClusterAffinityDistribution(Classification.Type type, List<Cluster> clusters){ ClusterAffinityDistribution<V> result = new ClusterAffinityDistribution<V>(type, new ValueMap<String, V>(2 * clusters.size())){ @Override public BiMap<String, Cluster> getEntityRegistry(){ return ClusteringModelEvaluator.this.getEntityRegistry(); } }; return result; }
@Override public Double getConfidence(String category){ ValueMap<String, V> confidences = getConfidences(); Value<V> confidence = (confidences != null ? confidences.get(category) : null); return Type.CONFIDENCE.getValue(confidence); }
protected Set<String> keySet(){ ValueMap<String, V> values = getValues(); return values.keySet(); }
static public <K, V extends Number> ValueMap<K, V> computeOrdinalProbabilities(RegressionModel.NormalizationMethod normalizationMethod, ValueMap<K, V> values){ if(values.size() < 2){ throw new IllegalArgumentException(); Iterator<Value<V>> valueIt = values.iterator(); for(int i = 0, max = values.size() - 1; i < max; i++){ Value<V> value = valueIt.next();
public ValueMap<K, V> sumMap(){ return new ValueMap<>(asTransformedMap(Vector::sum)); }
public Report getValueReport(String key){ ValueMap<String, V> values = getValues(); Value<V> value = values.get(key); return ReportUtil.getReport(value); }
private <V extends Number> AffinityDistribution<V> createAffinityDistribution(List<InstanceResult<V>> instanceResults, Function<Integer, String> function, Object result){ NearestNeighborModel nearestNeighborModel = getModel(); ComparisonMeasure comparisonMeasure = nearestNeighborModel.getComparisonMeasure(); ValueMap<String, V> values = new ValueMap<>(2 * instanceResults.size()); for(InstanceResult<V> instanceResult : instanceResults){ values.put(function.apply(instanceResult.getId()), instanceResult.getValue()); } Measure measure = MeasureUtil.ensureMeasure(comparisonMeasure); if(measure instanceof Similarity){ return new AffinityDistribution<>(Classification.Type.SIMILARITY, values, result); } else if(measure instanceof Distance){ return new AffinityDistribution<>(Classification.Type.DISTANCE, values, result); } else { throw new UnsupportedElementException(measure); } }
static public <K, V extends Number> ValueMap<K, V> computeMultinomialProbabilities(RegressionModel.NormalizationMethod normalizationMethod, ValueMap<K, V> values){ if(values.size() < 2){ throw new IllegalArgumentException(); Iterator<Value<V>> valueIt = values.iterator(); for(int i = 0, max = values.size() - 1; i < max; i++){ Value<V> value = valueIt.next();
public ValueMap<String, V> averageMap(){ if(this.weights != null){ throw new IllegalStateException(); } Function<Vector<V>, Value<V>> function = new Function<Vector<V>, Value<V>>(){ private int size = ProbabilityAggregator.this.size; @Override public Value<V> apply(Vector<V> values){ if(this.size == 0){ throw new UndefinedResultException(); } return (values.sum()).divide(this.size); } }; return new ValueMap<>(asTransformedMap(function)); }
@Override public Report getConfidenceReport(String category){ ValueMap<String, V> confidences = getConfidences(); Value<V> confidence = (confidences != null ? confidences.get(category) : null); return ReportUtil.getReport(confidence); }
static private <V extends Number> ReasonCodeRanking<V> createReasonCodeRanking(TargetField targetField, Value<V> score, ValueMap<String, V> reasonCodePoints){ score = TargetUtil.evaluateRegressionInternal(targetField, score); Collection<Map.Entry<String, Value<V>>> entrySet = reasonCodePoints.entrySet(); for(Iterator<Map.Entry<String, Value<V>>> it = entrySet.iterator(); it.hasNext(); ){ Map.Entry<String, Value<V>> entry = it.next(); Value<V> value = entry.getValue(); if(value.compareTo(0d) < 0){ it.remove(); } } return new ReasonCodeRanking<>(score, reasonCodePoints); } }