Class RunningStatistics

java.lang.Object
qupath.lib.analysis.stats.RunningStatistics

public class RunningStatistics extends Object
Helper class for computing basic statistics from values as they are added.

This is useful e.g. when iterating through pixels, computing statistics from masked/labelled values.

Warning! This maintains a sum as a double - for many pixels and/or 16-bit data this may lead to imprecision (although for small regions, and especially optical densities having low values, it should be fine).

A warning is logged for particularly large values.

Author:
Pete Bankhead
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    protected long
     
  • Constructor Summary

    Constructors
    Constructor
    Description
    Default constructor.
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    addValue(double val)
    Add another value; NaN values are counted but do not contribute to the statistics.
    double
    Get the maximum non-NaN value added.
    double
    Get the mean of all non-NaN values that were added.
    double
    Get the minimum non-NaN value added.
    long
    Get count of the number of NaN values added.
    double
    Get the range, i.e.
    double
    Get the standard deviation of all non-NaN values that were added.
    double
    Get the sum of all non-NaN values that were added.
    double
    Get the variance of all non-NaN values that were added.
    long
    Get count of the number of non-NaN values added.
     

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
  • Field Details

    • size

      protected long size
  • Constructor Details

    • RunningStatistics

      public RunningStatistics()
      Default constructor.
  • Method Details

    • size

      public long size()
      Get count of the number of non-NaN values added.
      Returns:
      See Also:
    • addValue

      public void addValue(double val)
      Add another value; NaN values are counted but do not contribute to the statistics.
      Parameters:
      val -
      See Also:
    • getNumNaNs

      public long getNumNaNs()
      Get count of the number of NaN values added.
      Returns:
      See Also:
    • getSum

      public double getSum()
      Get the sum of all non-NaN values that were added.
      Returns:
    • getMean

      public double getMean()
      Get the mean of all non-NaN values that were added.
      Returns:
    • getVariance

      public double getVariance()
      Get the variance of all non-NaN values that were added.
      Returns:
    • getStdDev

      public double getStdDev()
      Get the standard deviation of all non-NaN values that were added.
      Returns:
    • getMin

      public double getMin()
      Get the minimum non-NaN value added.
      Returns:
      the minimum value, or NaN if no values are available.
    • getMax

      public double getMax()
      Get the maximum non-NaN value added.
      Returns:
      the maximum value, or NaN if no values are available.
    • getRange

      public double getRange()
      Get the range, i.e. maximum - minimum values.
      Returns:
    • toString

      public String toString()
      Overrides:
      toString in class Object