Class WeightedStats

java.lang.Object
microsim.dev.statistics.WeightedStats

public class WeightedStats extends Object

Weighted statistics over a collection of data.

Note that results are cached, for example calling

stats.sum();
stats.sum();
stats.mean();

calculates the weighted sum of elements only once and reuses the results in subsequent calls and to compute the mean.

  • Constructor Details

    • WeightedStats

      public WeightedStats(List<? extends Number> values, List<? extends Number> weights)

      Build a WeightedStats object for the given lists of values and weights.

      Each value and weight is converted to a Double internally.

    • WeightedStats

      public WeightedStats(WeightedValues<? extends Number> wvals)

      Build a Stats object for the given list of weighted values.

      Each value is converted to a Double internally.

  • Method Details

    • supplier

      public static Supplier<WeightedStats> supplier(Supplier<? extends WeightedValues<? extends Number>> supplier)
      Convenience method to work with the Supplier API.
    • count

      public int count()
      The number of values.
    • sum

      public double sum()
      The weighted sum of values.
    • weightSum

      public double weightSum()
      The sum of all weights.
    • mean

      public double mean()
      The weighted average of values.