@Override public Value<V> apply(Vector<V> values){ if(this.size == 0){ throw new UndefinedResultException(); } return (values.sum()).divide(this.size); } };
public Value<V> average(){ if(this.weights != null){ throw new IllegalStateException(); } int size = this.values.size(); if(size == 0){ throw new UndefinedResultException(); } return (this.values.sum()).divide(size); }
@Override public Value<V> apply(Vector<V> values){ if(this.weightSum.equals(0d)){ throw new UndefinedResultException(); } return (values.sum()).divide(this.weightSum); } };
public Value<V> weightedAverage(){ if(this.weights == null || this.weightedValues == null){ throw new IllegalStateException(); } Value<V> weightSum = this.weights.sum(); if(weightSum.equals(0d)){ throw new UndefinedResultException(); } return (this.weightedValues.sum()).divide(weightSum); }
static public <V extends Number> Value<V> calculateAdjustment(ValueFactory<V> valueFactory, List<FieldValue> values, List<? extends Number> adjustmentValues){ Value<V> sum = valueFactory.newValue(); Value<V> nonmissingSum = valueFactory.newValue(); for(int i = 0; i < values.size(); i++){ FieldValue value = values.get(i); double adjustmentValue = (adjustmentValues != null ? (adjustmentValues.get(i)).doubleValue() : 1d); if(adjustmentValue != 0d){ sum.add(adjustmentValue); if(value != null){ nonmissingSum.add(adjustmentValue); } } } if(nonmissingSum.equals(0d)){ throw new UndefinedResultException(); } return sum.divide(nonmissingSum); } }
static public <V extends Number> void normalizeSimpleMax(Iterable<Value<V>> values){ Value<V> sum = sum(values); if(sum == null || sum.equals(1d)){ return; } else if(sum.equals(0d)){ throw new UndefinedResultException(); } for(Value<V> value : values){ value.divide(sum); } }
private Value<V> computeProbability(String category){ ValueMap<String, V> values = getValues(); if(this.sum == null){ throw new EvaluationException("Vote distribution result has not been computed"); } Value<V> probability = values.get(category); if(probability != null){ probability = probability.copy(); if(this.sum.equals(0d)){ throw new UndefinedResultException(); } probability.divide(this.sum); } return probability; } }
value.divide(sum);
return numerator.divide(denominator);
value.divide(sum);
value.divide(sum);
Value<V> value = totalWeight.divide(firedRules.size());