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 voidcollect(double value)Collect on the supplied valuevoidcollect(double[] x, double[] w)Collects the passed in arrays.voidcollect(double x, double weight)static WeightedStatisticcollectStatistics(double[] x, double[] w)Returns a statistic that summarizes the passed in arrays.doublegetAverage()Gets the weighted average of the collected observations.doublegetCount()Gets the count of the number of the observations.java.lang.StringgetCSVStatistic()java.lang.StringgetCSVStatisticHeader()The header string for the CVS representationintgetId()doublegetLastValue()Gets the last observed data pointdoublegetLastWeight()Gets the last observed weightdoublegetMax()Gets the maximum of the observations.doublegetMin()Gets the minimum of the observations.java.lang.StringgetName()doublegetNumberMissing()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 = statisticvoidgetStatistics(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";doublegetSumOfWeights()Gets the sum of the observed weights.doublegetUnWeightedSum()doublegetWeightedSum()Gets the weighted sum of observations observed.doublegetWeightedSumOfSquares()Gets the weighted sum of squares for observations observed.WeightedStatisticnewInstance()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 WeightedStatisticnewInstance(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 Statisticvoidreset()Resets the collector as if no observations had been collected.voidsetName(java.lang.String str)Sets the namejava.lang.StringtoString()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:CollectorIfcCollect on the supplied value- Specified by:
collectin interfaceCollectorIfc- Parameters:
value- a double representing the observation
-
reset
public final void reset()
Description copied from interface:CollectorIfcResets the collector as if no observations had been collected.- Specified by:
resetin interfaceCollectorIfc- Specified by:
resetin interfaceWeightedStatisticIfc
-
getLastValue
public final double getLastValue()
Description copied from interface:WeightedStatisticIfcGets the last observed data point- Specified by:
getLastValuein interfaceWeightedStatisticIfc- Returns:
- A double representing the last observed observation
-
getLastWeight
public final double getLastWeight()
Description copied from interface:WeightedStatisticIfcGets the last observed weight- Specified by:
getLastWeightin interfaceWeightedStatisticIfc- Returns:
- A double representing the last observed weight
-
getAverage
public final double getAverage()
Description copied from interface:WeightedStatisticIfcGets the weighted average of the collected observations.- Specified by:
getAveragein interfaceWeightedStatisticIfc- Returns:
- A double representing the weighted average or Double.NaN if no observations.
-
getCount
public final double getCount()
Description copied from interface:WeightedStatisticIfcGets the count of the number of the observations.- Specified by:
getCountin interfaceWeightedStatisticIfc- Returns:
- A double representing the count
-
getWeightedSum
public final double getWeightedSum()
Description copied from interface:WeightedStatisticIfcGets the weighted sum of observations observed.- Specified by:
getWeightedSumin interfaceWeightedStatisticIfc- Returns:
- A double representing the weighted sum
-
getSumOfWeights
public final double getSumOfWeights()
Description copied from interface:WeightedStatisticIfcGets the sum of the observed weights.- Specified by:
getSumOfWeightsin interfaceWeightedStatisticIfc- Returns:
- A double representing the sum of the weights
-
getWeightedSumOfSquares
public final double getWeightedSumOfSquares()
Description copied from interface:WeightedStatisticIfcGets the weighted sum of squares for observations observed.- Specified by:
getWeightedSumOfSquaresin interfaceWeightedStatisticIfc- Returns:
- A double representing the weighted sum of squares
-
getMin
public final double getMin()
Description copied from interface:WeightedStatisticIfcGets the minimum of the observations.- Specified by:
getMinin interfaceWeightedStatisticIfc- Returns:
- A double representing the minimum
-
getMax
public final double getMax()
Description copied from interface:WeightedStatisticIfcGets the maximum of the observations.- Specified by:
getMaxin interfaceWeightedStatisticIfc- Returns:
- A double representing the maximum
-
getNumberMissing
public double getNumberMissing()
Description copied from interface:WeightedStatisticIfcWhen 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:
getNumberMissingin interfaceWeightedStatisticIfc- Returns:
- the number missing
-
getUnWeightedSum
public final double getUnWeightedSum()
- Specified by:
getUnWeightedSumin 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:
toStringin 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:
getCSVStatisticin interfaceGetCSVStatisticIfc- Returns:
- the CSV string for the values of the statistics
-
getCSVStatisticHeader
public java.lang.String getCSVStatisticHeader()
Description copied from interface:GetCSVStatisticIfcThe header string for the CVS representation- Specified by:
getCSVStatisticHeaderin interfaceGetCSVStatisticIfc- Returns:
- the CVS header string
-
getName
public final java.lang.String getName()
- Specified by:
getNamein 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:
getIdin interfaceIdentityIfc- Returns:
- an int representing the id of the object
-
-