Class FloatStats
java.lang.Object
nl.colorize.util.FloatStats
Immutable data set that contains numerical values with
float
precision. All operations in this class allow the data set to be empty,
and will return zero rather than throwing an exception.-
Method Summary
Modifier and TypeMethodDescriptionfloataverage()floatmax()floatmedian()floatmin()static floatmultiplyPercentage(float percentageA, float percentageB) Utility method that multiplies two percentages and returns the resulting percentage.static FloatStatsof(float... values) Creates aFloatStatsdata set that consists of the specified values.static FloatStatsof(Collection<? extends Number> values) Creates aFloatStatsdata set that consists of the specified values.floatpearsonCorrelation(FloatStats other) Calculates the Pearson correlation between this data set and the specified other data set.floatpercentage(float value) Calculates the specified value as a percentage of this data set's total.static floatpercentage(float value, float total) Utility method that returns a percentage for the specified value.floatpercentile(int n) Calculates the value of the Nth percentile within this data set.floatsum()toString()
-
Method Details
-
sum
public float sum() -
min
public float min() -
max
public float max() -
average
public float average() -
median
public float median() -
percentage
public float percentage(float value) Calculates the specified value as a percentage of this data set's total. For example, if this data set consists of [2, 2], then calculating the percentage for 1 would result in 25%. -
percentile
public float percentile(int n) Calculates the value of the Nth percentile within this data set. This method will interpolate between values if none of the values in the data set exactly matches the requested percentile.- Throws:
IllegalArgumentException- ifnis outside the range between 0 and 99 and therefore not a valid percentile.
-
pearsonCorrelation
Calculates the Pearson correlation between this data set and the specified other data set. A correlation of 1.0 indicates perfect correlation, -1.0 indicates a perfect inverse correlation, and 0.0 indicates no correlation.- Throws:
IllegalArgumentException- if the two data sets are of different length, as Pearson correlation is based on pairs.
-
toString
-
of
Creates aFloatStatsdata set that consists of the specified values. -
of
Creates aFloatStatsdata set that consists of the specified values. Each value will be converted to afloatby callingNumber.floatValue(). -
percentage
public static float percentage(float value, float total) Utility method that returns a percentage for the specified value. Returns zero iftotalis zero. -
multiplyPercentage
public static float multiplyPercentage(float percentageA, float percentageB) Utility method that multiplies two percentages and returns the resulting percentage. For example, multiplying 50% with 50% will return 25%.
-