Class WeightedStatistic
- java.lang.Object
-
- jsl.utilities.statistic.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.
-
-
Constructor Summary
Constructors Constructor Description WeightedStatistic()
WeightedStatistic(java.lang.String name)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description void
collect(double value)
Collect on the supplied valuevoid
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 representationint
getId()
double
getLastValue()
Gets the last observed data pointdouble
getLastWeight()
Gets the last observed weightdouble
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 = statisticvoid
getStatistics(double[] statistics)
Fills up the supplied array with the statistics defined by index = statisticjava.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 Statisticstatic 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 Statisticvoid
reset()
Resets the collector as if no observations had been collected.void
setName(java.lang.String str)
Sets the namejava.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
-
Methods inherited from interface jsl.utilities.statistic.CollectorIfc
collect, collect, collect
-
Methods inherited from interface jsl.utilities.statistic.WeightedStatisticIfc
getUnWeightedAverage
-
-
-
-
Method Detail
-
collect
public final void collect(double x, double weight)
- Parameters:
x
- the value to collectweight
- 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 valuesw
- 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 valuesw
- 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 interfaceCollectorIfc
- Parameters:
value
- a double representing the observation
-
reset
public final void reset()
Description copied from interface:CollectorIfc
Resets the collector as if no observations had been collected.- Specified by:
reset
in interfaceCollectorIfc
- Specified by:
reset
in interfaceWeightedStatisticIfc
-
getLastValue
public final double getLastValue()
Description copied from interface:WeightedStatisticIfc
Gets the last observed data point- Specified by:
getLastValue
in interfaceWeightedStatisticIfc
- Returns:
- A double representing the last observed observation
-
getLastWeight
public final double getLastWeight()
Description copied from interface:WeightedStatisticIfc
Gets the last observed weight- Specified by:
getLastWeight
in interfaceWeightedStatisticIfc
- Returns:
- A double representing the last observed weight
-
getAverage
public final double getAverage()
Description copied from interface:WeightedStatisticIfc
Gets the weighted average of the collected observations.- Specified by:
getAverage
in interfaceWeightedStatisticIfc
- 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 interfaceWeightedStatisticIfc
- 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 interfaceWeightedStatisticIfc
- Returns:
- A double representing the weighted sum
-
getSumOfWeights
public final double getSumOfWeights()
Description copied from interface:WeightedStatisticIfc
Gets the sum of the observed weights.- Specified by:
getSumOfWeights
in interfaceWeightedStatisticIfc
- Returns:
- A double representing the sum of the weights
-
getWeightedSumOfSquares
public final double getWeightedSumOfSquares()
Description copied from interface:WeightedStatisticIfc
Gets the weighted sum of squares for observations observed.- Specified by:
getWeightedSumOfSquares
in interfaceWeightedStatisticIfc
- 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 interfaceWeightedStatisticIfc
- 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 interfaceWeightedStatisticIfc
- 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 interfaceWeightedStatisticIfc
- Returns:
- the number missing
-
getUnWeightedSum
public final double getUnWeightedSum()
- Specified by:
getUnWeightedSum
in interfaceWeightedStatisticIfc
- 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 classjava.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 = statisticstatistics[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 = statisticstatistics[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 interfaceGetCSVStatisticIfc
- Returns:
- the CSV string for the values of the statistics
-
getCSVStatisticHeader
public java.lang.String getCSVStatisticHeader()
Description copied from interface:GetCSVStatisticIfc
The header string for the CVS representation- Specified by:
getCSVStatisticHeader
in interfaceGetCSVStatisticIfc
- Returns:
- the CVS header string
-
getName
public final java.lang.String getName()
- Specified by:
getName
in interfaceGetNameIfc
- 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 interfaceIdentityIfc
- Returns:
- an int representing the id of the object
-
-