Class AbstractMean<MT,V extends Number,W extends Number>

java.lang.Object
org.djutils.means.AbstractMean<MT,V,W>
Type Parameters:
MT - mean type
V - value type
W - 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-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 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 the weightedSumOfValues
      weight - double; the weight to assign to the value
    • 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

      public final AbstractMean<MT,V,W> add(V value, W weight)
      Adds a value with weight.
      Parameters:
      value - V; the value
      weight - W; the weight
      Returns:
      this AbstractMean<MT, V, W>; for method chaining
    • addImpl

      protected abstract AbstractMean<MT,V,W> addImpl(V value, Number weight)
      Adds a value with weight.
      Parameters:
      value - V; the value
      weight - Number; the weight
      Returns:
      this AbstractMean<MT, V, W>; for method chaining
    • add

      public final AbstractMean<MT,V,W> add(V value)
      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 IllegalArgumentException
      Adds weighted values. Note that iteration order is pivotal in correct operations. This method should not be used with instances of HashMap or HashSet.
      Parameters:
      values - Iterable<V>; values
      weights - 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

      public final AbstractMean<MT,V,W> add(V[] values, W[] weights) throws IllegalArgumentException
      Adds weighted values.
      Parameters:
      values - V[]; values
      weights - 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

      public final AbstractMean<MT,V,W> add(Map<V,W> map)
      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

      public final AbstractMean<MT,V,W> add(Collection<V> collection, Function<V,W> weights)
      Adds each value with a weight obtained by calling the provided weights function.
      Parameters:
      collection - Collection<V>; values
      weights - 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 the values function on each object in a Collection) with a weight (obtained by calling the weights function on the same object from the Collection).
      Type Parameters:
      S - type of source object
      Parameters:
      collection - Collection<S>; collection of source objects
      values - Function<S, V>; values
      weights - Function<S, W>; weights
      Returns:
      this AbstractMean<MT, V, W>; for method chaining
    • add

      public final AbstractMean<MT,V,W> add(Iterable<V> values)
      Add values with weight 1.
      Parameters:
      values - Iterable<V>; the values to add
      Returns:
      this AbstractMean<MT, V, W>; for method chaining
    • add

      public final AbstractMean<MT,V,W> add(V[] values)
      Add values with weight 1.
      Parameters:
      values - V[]; the values to add
      Returns:
      this AbstractMean<MT, V, W>; for method chaining