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
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-2024 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
-
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 thevalues
function on each object in a Collection) with a weight (obtained by calling theweights
function on the same object from the Collection).final AbstractMean<MT,
V, W> Adds each value with a weight obtained by calling the providedweights
function.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 double
getMean()
Returns the weighted mean of accumulated data.final double
getSum()
Returns the weighted sum of available data.final double
Returns the sum of the weights.(package private) final 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, 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 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, addW> (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<S>; collection of source objectsvalues
- Function<S, V>; valuesweights
- Function<S, W>; weights- Returns:
- this AbstractMean<MT, V, W>; for method chaining
-
add
Add values with weight 1.- Parameters:
values
- Iterable<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
-