Package org.djutils.means
Class AbstractMean<MT,V extends Number,W extends Number>
java.lang.Object
org.djutils.means.AbstractMean<MT,V,W>
- Type Parameters:
MT
- mean typeV
- value typeW
- weight type
- Direct Known Subclasses:
ArithmeticMean
,GeometricMean
,HarmonicMean
public abstract class AbstractMean<MT,V extends Number,W extends Number> extends Object
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-2020 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands. All rights reserved.
BSD-style license. See OpenTrafficSim License.
- Version:
- $Revision$, $LastChangedDate$, by $Author$, initial version Oct 26, 2018
- Author:
- Alexander Verbraeck, Peter Knoppers, Wouter Schakel
-
Constructor Summary
Constructors Constructor Description AbstractMean()
Constructor. -
Method Summary
Modifier and Type Method Description AbstractMean<MT,V,W>
add(Iterable<V> values)
Add values with weight 1.AbstractMean<MT,V,W>
add(Iterable<V> values, Iterable<W> weights)
Adds weighted values.<S> AbstractMean<MT,V,W>
add(Collection<S> collection, Function<S,V> values, Function<S,W> weights)
Adds each value (obtained by calling thevalues
function on each object in a Collection) with a weight (obtained by calling theweights
function on the same object from the Collection).AbstractMean<MT,V,W>
add(Collection<V> collection, Function<V,W> weights)
Adds each value with a weight obtained by calling the providedweights
function.AbstractMean<MT,V,W>
add(Map<V,W> map)
Adds each key value from a map weighted with the mapped to value.AbstractMean<MT,V,W>
add(V value)
Add a value with weight 1.AbstractMean<MT,V,W>
add(V[] values)
Add values with weight 1.AbstractMean<MT,V,W>
add(V[] values, W[] weights)
Adds weighted values.AbstractMean<MT,V,W>
add(V value, W weight)
Adds a value with weight.protected abstract AbstractMean<MT,V,W>
addImpl(V value, Number weight)
Adds a value with weight.abstract double
getMean()
Returns the weighted mean of accumulated data.double
getSum()
Returns the weighted sum of available data.double
getSumOfWeights()
Returns the sum of the weights.(package private) void
increment(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:
- double; weighted mean of accumulated data
-
increment
final void increment(double value, double weight)Accumulate some data.- Parameters:
value
- double; the value to add to theweightedSumOfValues
weight
- double; 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:
- double; weighted sum of accumulated data
-
getSumOfWeights
public final double getSumOfWeights()Returns the sum of the weights.- Returns:
- double; sum of the weights
-
add
Adds a value with weight.- Parameters:
value
- V; the valueweight
- W; the weight- Returns:
- this AbstractMean<MT, V, W>; for method chaining
-
addImpl
Adds a value with weight.- Parameters:
value
- V; the valueweight
- Number; the weight- Returns:
- this AbstractMean<MT, V, W>; for method chaining
-
add
Add a value with weight 1.- Parameters:
value
- V; the value- Returns:
- this AbstractMean<MT, V, W>; for method chaining
-
add
public final AbstractMean<MT,V,W> add(Iterable<V> values, Iterable<W> weights) throws IllegalArgumentExceptionAdds weighted values. Note that iteration order is pivotal in correct operations. This method should not be used with instances ofHashMap
orHashSet
.- Parameters:
values
- Iterable<V>; valuesweights
- Iterable<W>; weights- Returns:
- this AbstractMean<MT, V, W>; for method chaining
- Throws:
IllegalArgumentException
- if the number of values is not equal to the number of weights
-
add
Adds weighted values.- Parameters:
values
- V[]; valuesweights
- W[]; weights- Returns:
- this AbstractMean<MT, V, W>; 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<V, W>; map- Returns:
- this AbstractMean<MT, V, W>; for method chaining
-
add
Adds each value with a weight obtained by calling the providedweights
function.- Parameters:
collection
- Collection<V>; valuesweights
- Function<V, W>; weights- Returns:
- this AbstractMean<MT, V, W>; for method chaining
-
add
public final <S> AbstractMean<MT,V,W> add(Collection<S> collection, Function<S,V> values, Function<S,W> weights)Adds each value (obtained by calling thevalues
function on each object in a Collection) with a weight (obtained by calling theweights
function on the same object from the Collection).- Type Parameters:
S
- type of source object- Parameters:
collection
- Collection<V>; collection of source objectsvalues
- Function<V, W>; valuesweights
- Function<V, W>; weights- Returns:
- this AbstractMean<MT, V, W>; for method chaining
-
add
Add values with weight 1.- Parameters:
values
- V[]; the values to add- Returns:
- this AbstractMean<MT, V, W>; for method chaining
-
add
Add values with weight 1.- Parameters:
values
- V[]; the values to add- Returns:
- this AbstractMean<MT, V, W>; for method chaining
-