Package org.djutils.math.means
Class AbstractMean<MT,V extends Number,W extends Number>  
java.lang.Object
org.djutils.math.means.AbstractMean<MT,V,W>  
- Type Parameters:
 MT- mean typeV- value typeW- weight type
- Direct Known Subclasses:
 ArithmeticMean,GeometricMean,HarmonicMean
Methods and fields common to all implementations of Mean. Mean implements various kinds of mean. For an excellent discussion
 on this subject read On Average, You’re Using the Wrong Average: Geometric & Harmonic Means in Data Analysis
 
 Copyright (c) 2013-2025 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands. All rights reserved. 
 BSD-style license. See DJUTILS License.
 
- Author:
 - Alexander Verbraeck, Peter Knoppers
 
- 
Constructor Summary
Constructors - 
Method Summary
Modifier and TypeMethodDescriptionfinal AbstractMean<MT,V, W> Add values with weight 1.final AbstractMean<MT,V, W> Adds weighted values.final <S> AbstractMean<MT,V, W> Adds each value (obtained by calling thevaluesfunction on each object in a Collection) with a weight (obtained by calling theweightsfunction on the same object from the Collection).final AbstractMean<MT,V, W> Adds each value with a weight obtained by calling the providedweightsfunction.final AbstractMean<MT,V, W> Adds each key value from a map weighted with the mapped to value.final AbstractMean<MT,V, W> Add a value with weight 1.final AbstractMean<MT,V, W> Add values with weight 1.final AbstractMean<MT,V, W> Adds weighted values.final AbstractMean<MT,V, W> Adds a value with weight.protected abstract AbstractMean<MT,V, W> Adds a value with weight.abstract doublegetMean()Returns the weighted mean of accumulated data.final doublegetSum()Returns the weighted sum of available data.final doubleReturns the sum of the weights.(package private) final voidincrement(double value, double weight) Accumulate some data. 
- 
Constructor Details
- 
AbstractMean
public AbstractMean()Constructor. 
 - 
 - 
Method Details
- 
getMean
public abstract double getMean()Returns the weighted mean of accumulated data.- Returns:
 - weighted mean of accumulated data
 
 - 
increment
final void increment(double value, double weight) Accumulate some data.- Parameters:
 value- the value to add to theweightedSumOfValuesweight- the weight to assign to thevalue
 - 
getSum
public final double getSum()Returns the weighted sum of available data. Meaning varies per type of mean.- Returns:
 - weighted sum of accumulated data
 
 - 
getSumOfWeights
public final double getSumOfWeights()Returns the sum of the weights.- Returns:
 - sum of the weights
 
 - 
add
Adds a value with weight.- Parameters:
 value- the valueweight- the weight- Returns:
 - for method chaining
 
 - 
addImpl
Adds a value with weight.- Parameters:
 value- the valueweight- the weight- Returns:
 - for method chaining
 
 - 
add
Add a value with weight 1.- Parameters:
 value- the value- Returns:
 - for method chaining
 
 - 
add
public final AbstractMean<MT,V, addW> (Iterable<V> values, Iterable<W> weights) throws IllegalArgumentException Adds weighted values. Note that iteration order is pivotal in correct operations. This method should not be used with instances ofHashMaporHashSet.- Parameters:
 values- valuesweights- weights- Returns:
 - for method chaining
 - Throws:
 IllegalArgumentException- if the number of values is not equal to the number of weights
 - 
add
Adds weighted values.- Parameters:
 values- valuesweights- weights- Returns:
 - for method chaining
 - Throws:
 IllegalArgumentException- if the number of values is not equal to the number of weights
 - 
add
Adds each key value from a map weighted with the mapped to value.- Parameters:
 map- map- Returns:
 - for method chaining
 
 - 
add
Adds each value with a weight obtained by calling the providedweightsfunction.- Parameters:
 collection- valuesweights- weights- Returns:
 - for method chaining
 
 - 
add
public final <S> AbstractMean<MT,V, addW> (Collection<S> collection, Function<S, V> values, Function<S, W> weights) Adds each value (obtained by calling thevaluesfunction on each object in a Collection) with a weight (obtained by calling theweightsfunction on the same object from the Collection).- Type Parameters:
 S- type of source object- Parameters:
 collection- collection of source objectsvalues- valuesweights- weights- Returns:
 - for method chaining
 
 - 
add
Add values with weight 1.- Parameters:
 values- the values to add- Returns:
 - for method chaining
 
 - 
add
Add values with weight 1.- Parameters:
 values- the values to add- Returns:
 - for method chaining
 
 
 -