Class SamplingSummaryStat

  • All Implemented Interfaces:
    Serializable, Cloneable

    public class SamplingSummaryStat
    extends SummaryStat

    This class provides efficient sampling of up to a certain maximum number of values. A SummaryStat-object provides an efficient means to collect basic summary statistics like mean, min, max, standard deviation. To do so it does not have to store any observations. Obtaining information like median, or percentile requires storing values, however. To limit the amount of data which has to be stored, sampling can be used and the aforementioned statistics estimated based on this sample.

    This class can sample and store up to a certain maximum number of values. Each value passed to a call of value(double) has the same probability of ending up in the final sample accessible by getData() .

    Which values are selected is determined by a random number generator (see setRnd(Random)). If no such random number generator is set, Math.random() is used.

    Author:
    Torsten Hildebrandt, 2012-07-06
    See Also:
    Serialized Form
    • Constructor Detail

      • SamplingSummaryStat

        public SamplingSummaryStat()
      • SamplingSummaryStat

        public SamplingSummaryStat​(int numSamples)
      • SamplingSummaryStat

        public SamplingSummaryStat​(Random rnd)
      • SamplingSummaryStat

        public SamplingSummaryStat​(int numSamples,
                                   Random rnd)
    • Method Detail

      • value

        public SummaryStat value​(double v,
                                 double weight)
        Description copied from class: SummaryStat
        Adds a value with a given weight.
        Overrides:
        value in class SummaryStat
        Parameters:
        v - The value to add.
        weight - The weight to give to this value. Has to be positive.
        Returns:
        this, to allow easy chaining of calls.
      • value

        public SamplingSummaryStat value​(double v)
        Description copied from class: SummaryStat
        Adds the given value with a weight of 1.
        Overrides:
        value in class SummaryStat
        Parameters:
        v - The value to add.
        Returns:
        this, to allow easy chaining of calls.
      • getData

        public double[] getData()
      • init

        public void init()
      • setRnd

        public void setRnd​(Random rnd)
      • getRnd

        public Random getRnd()
      • setNumSamples

        public void setNumSamples​(int numSamples)
      • getNumSamples

        public int getNumSamples()
      • clone

        public SummaryStat clone()
        Description copied from class: SummaryStat
        Clones this object. We can use the standard functionality here, as there are only primitive fields.
        Overrides:
        clone in class SummaryStat
        Returns:
        A clone of this SummaryStat.