Class FloatStats

java.lang.Object
nl.colorize.util.FloatStats

public final class FloatStats extends Object
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 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 - if n is outside the range between 0 and 99 and therefore not a valid percentile.
    • pearsonCorrelation

      public float pearsonCorrelation(FloatStats other)
      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

      public String toString()
      Overrides:
      toString in class Object
    • of

      public static FloatStats of(float... values)
      Creates a FloatStats data set that consists of the specified values.
    • of

      public static FloatStats of(Collection<? extends Number> values)
      Creates a FloatStats data set that consists of the specified values. Each value will be converted to a float by calling Number.floatValue().
    • percentage

      public static float percentage(float value, float total)
      Utility method that returns a percentage for the specified value. Returns zero if total is 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%.