Class AccumulatorStats

java.lang.Object
microsim.dev.statistics.AccumulatorStats

public class AccumulatorStats extends Object

Sampler that keeps statistical information about the samples.

This is an efficient way to compute simple statistics, e.g. over time, with a small constant memory usage.

  • Constructor Details

    • AccumulatorStats

      public AccumulatorStats(Supplier<? extends Number> source, Consumer<SideEffect> sampleHook)

      Build an accumulator that samples from the given Supplier, registered via the sampleHook.

      A common usage would be to collect a statistic at the end of every time step, leveraging SimulationEngine.hookStepEnd(SideEffect).

      For instance, to monitor the size of a population returned by popSize():

      var popSizeStats = new AccumulatorStats(popSize, engine::hookStepEnd);
      
      Parameters:
      source - The supplier for each sampled value. It will internally be converted to a double.
      sampleHook - The hook specifying when sampling is done.
  • Method Details

    • lastValue

      public double lastValue()
      Last sampled value.
    • min

      public double min()
      Sample minimum.
    • max

      public double max()
      Sample maximum.
    • sum

      public double sum()
      Sample sum.
    • count

      public int count()
      Sample counts.
    • mean

      public double mean()
      Sample average.
    • unbiasedVariance

      public double unbiasedVariance()
      Running unbiased variance (i.e. using Bessel's correction).