Class WeightedStatistic

  • All Implemented Interfaces:
    GetNameIfc, IdentityIfc, CollectorIfc, GetCSVStatisticIfc, WeightedStatisticIfc

    public class WeightedStatistic
    extends java.lang.Object
    implements CollectorIfc, WeightedStatisticIfc
    Collects a basic weighted statistical summary. If the observation or the weight is infinite or NaN, then the observation is not recorded and the number of missing observations is incremented. If the observed weight is negative or 0.0, then the observation is not recorded and the number of missing observations is incremented.
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void collect​(double value)
      Collect on the supplied value
      void collect​(double[] x, double[] w)
      Collects the passed in arrays.
      void collect​(double x, double weight)  
      static WeightedStatistic collectStatistics​(double[] x, double[] w)
      Returns a statistic that summarizes the passed in arrays.
      double getAverage()
      Gets the weighted average of the collected observations.
      double getCount()
      Gets the count of the number of the observations.
      java.lang.String getCSVStatistic()  
      java.lang.String getCSVStatisticHeader()
      The header string for the CVS representation
      int getId()  
      double getLastValue()
      Gets the last observed data point
      double getLastWeight()
      Gets the last observed weight
      double getMax()
      Gets the maximum of the observations.
      double getMin()
      Gets the minimum of the observations.
      java.lang.String getName()  
      double getNumberMissing()
      When a data point having the value of (Double.NaN, Double.POSITIVE_INFINITY, Double.NEGATIVE_INFINITY) are presented it is excluded from the summary statistics and the number of missing points is noted.
      double[] getStatistics()
      Returns an array with the statistics defined by index = statistic
      void getStatistics​(double[] statistics)
      Fills up the supplied array with the statistics defined by index = statistic
      java.lang.String[] getStatisticsHeader()
      s[0] = "Count"; s[1] = "Average"; s[2] = "Minimum"; s[3] = "Maximum"; s[4] = "Weighted Sum"; s[5] = "Sum of Weights"; s[6] = "Weighted sum of squares"; s[7] = "Last Value"; s[8] = "Last Weight"; s[9] = "Unweighted Sum"; s[10] = "Unweighted Average";
      double getSumOfWeights()
      Gets the sum of the observed weights.
      double getUnWeightedSum()  
      double getWeightedSum()
      Gets the weighted sum of observations observed.
      double getWeightedSumOfSquares()
      Gets the weighted sum of squares for observations observed.
      WeightedStatistic newInstance()
      Creates a instance of Statistic that is a copy of this Statistic All internal state is the same except for the id of the returned Statistic
      static WeightedStatistic newInstance​(WeightedStatistic stat)
      Creates a instance of Statistic that is a copy of the supplied Statistic All internal state is the same except for the id of the returned Statistic
      void reset()
      Resets the collector as if no observations had been collected.
      void setName​(java.lang.String str)
      Sets the name
      java.lang.String toString()
      Returns a String representation of the WeightedStatistic
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
    • Constructor Detail

      • WeightedStatistic

        public WeightedStatistic()
      • WeightedStatistic

        public WeightedStatistic​(java.lang.String name)
        Parameters:
        name - the name of the statistic
    • Method Detail

      • collect

        public final void collect​(double x,
                                  double weight)
        Parameters:
        x - the value to collect
        weight - the weight associated with the value
      • collect

        public void collect​(double[] x,
                            double[] w)
        Collects the passed in arrays. The lengths of the arrays must be the same.
        Parameters:
        x - the values
        w - the weights
      • collectStatistics

        public static WeightedStatistic collectStatistics​(double[] x,
                                                          double[] w)
        Returns a statistic that summarizes the passed in arrays. The lengths of the arrays must be the same.
        Parameters:
        x - the values
        w - the weights
        Returns:
        a weighted statistic based on the arrays
      • newInstance

        public static WeightedStatistic newInstance​(WeightedStatistic stat)
        Creates a instance of Statistic that is a copy of the supplied Statistic All internal state is the same except for the id of the returned Statistic
        Parameters:
        stat - the instance that needs to be copied
        Returns:
        the copy
      • newInstance

        public final WeightedStatistic newInstance()
        Creates a instance of Statistic that is a copy of this Statistic All internal state is the same except for the id of the returned Statistic
        Returns:
        a new instance based on the current state of this instance
      • collect

        public void collect​(double value)
        Description copied from interface: CollectorIfc
        Collect on the supplied value
        Specified by:
        collect in interface CollectorIfc
        Parameters:
        value - a double representing the observation
      • getLastValue

        public final double getLastValue()
        Description copied from interface: WeightedStatisticIfc
        Gets the last observed data point
        Specified by:
        getLastValue in interface WeightedStatisticIfc
        Returns:
        A double representing the last observed observation
      • getAverage

        public final double getAverage()
        Description copied from interface: WeightedStatisticIfc
        Gets the weighted average of the collected observations.
        Specified by:
        getAverage in interface WeightedStatisticIfc
        Returns:
        A double representing the weighted average or Double.NaN if no observations.
      • getCount

        public final double getCount()
        Description copied from interface: WeightedStatisticIfc
        Gets the count of the number of the observations.
        Specified by:
        getCount in interface WeightedStatisticIfc
        Returns:
        A double representing the count
      • getWeightedSum

        public final double getWeightedSum()
        Description copied from interface: WeightedStatisticIfc
        Gets the weighted sum of observations observed.
        Specified by:
        getWeightedSum in interface WeightedStatisticIfc
        Returns:
        A double representing the weighted sum
      • getWeightedSumOfSquares

        public final double getWeightedSumOfSquares()
        Description copied from interface: WeightedStatisticIfc
        Gets the weighted sum of squares for observations observed.
        Specified by:
        getWeightedSumOfSquares in interface WeightedStatisticIfc
        Returns:
        A double representing the weighted sum of squares
      • getMin

        public final double getMin()
        Description copied from interface: WeightedStatisticIfc
        Gets the minimum of the observations.
        Specified by:
        getMin in interface WeightedStatisticIfc
        Returns:
        A double representing the minimum
      • getMax

        public final double getMax()
        Description copied from interface: WeightedStatisticIfc
        Gets the maximum of the observations.
        Specified by:
        getMax in interface WeightedStatisticIfc
        Returns:
        A double representing the maximum
      • getNumberMissing

        public double getNumberMissing()
        Description copied from interface: WeightedStatisticIfc
        When a data point having the value of (Double.NaN, Double.POSITIVE_INFINITY, Double.NEGATIVE_INFINITY) are presented it is excluded from the summary statistics and the number of missing points is noted. If the weight is infinite or less than or equal to zero, then the data point should not be recorded. This method reports the number of missing points that occurred during the collection.
        Specified by:
        getNumberMissing in interface WeightedStatisticIfc
        Returns:
        the number missing
      • getUnWeightedSum

        public final double getUnWeightedSum()
        Specified by:
        getUnWeightedSum in interface WeightedStatisticIfc
        Returns:
        the unweighted sum of all of the observed data
      • toString

        public final java.lang.String toString()
        Returns a String representation of the WeightedStatistic
        Overrides:
        toString in class java.lang.Object
        Returns:
        A String with basic summary statistics
      • getStatistics

        public final void getStatistics​(double[] statistics)
        Fills up the supplied array with the statistics defined by index = statistic

        statistics[0] = getCount();

        statistics[1] = getAverage();

        statistics[2] = getMin();

        statistics[3] = getMax();

        statistics[4] = getWeightedSum();

        statistics[5] = getSumOfWeights();

        statistics[6] = getWeightedSumOfSquares();

        statistics[7] = getLastValue();

        statistics[8] = getLastWeight();

        statistics[9] = getUnWeightedSum();

        statistics[10] = getUnWeightedAverage();

        The array must be of size 9 or an exception will be thrown

        Parameters:
        statistics - the array to fill
      • getStatistics

        public final double[] getStatistics()
        Returns an array with the statistics defined by index = statistic

        statistics[0] = getCount();

        statistics[1] = getAverage();

        statistics[2] = getMin();

        statistics[3] = getMax();

        statistics[4] = getSum();

        statistics[5] = getSumOfWeights();

        statistics[6] = getWeightedSumOfSquares();

        statistics[7] = getLastValue();

        statistics[8] = getLastWeight();

        statistics[9] = getUnWeightedSum();

        statistics[10] = getUnWeightedAverage();

        Returns:
        the array of statistics
      • getStatisticsHeader

        public java.lang.String[] getStatisticsHeader()
        s[0] = "Count"; s[1] = "Average"; s[2] = "Minimum"; s[3] = "Maximum"; s[4] = "Weighted Sum"; s[5] = "Sum of Weights"; s[6] = "Weighted sum of squares"; s[7] = "Last Value"; s[8] = "Last Weight"; s[9] = "Unweighted Sum"; s[10] = "Unweighted Average";
        Returns:
        the headers
      • getCSVStatistic

        public java.lang.String getCSVStatistic()
        Specified by:
        getCSVStatistic in interface GetCSVStatisticIfc
        Returns:
        the CSV string for the values of the statistics
      • getName

        public final java.lang.String getName()
        Specified by:
        getName in interface GetNameIfc
        Returns:
        a string representing the name of the object
      • setName

        public final void setName​(java.lang.String str)
        Sets the name
        Parameters:
        str - The name as a string.
      • getId

        public final int getId()
        Specified by:
        getId in interface IdentityIfc
        Returns:
        an int representing the id of the object