Package hep.aida.bin

Class MightyStaticBin1D

All Implemented Interfaces:
DoubleBufferConsumer, Serializable, Cloneable
Direct Known Subclasses:
QuantileBin1D

public class MightyStaticBin1D extends StaticBin1D
Static and the same as its superclass, except that it can do more: Additionally computes moments of arbitrary integer order, harmonic mean, geometric mean, etc. Constructors need to be told what functionality is required for the given use case. Only maintains aggregate measures (incrementally) - the added elements themselves are not kept.
Version:
0.9, 03-Jul-99
See Also:
  • Field Details

    • hasSumOfLogarithms

      protected boolean hasSumOfLogarithms
    • sumOfLogarithms

      protected double sumOfLogarithms
    • hasSumOfInversions

      protected boolean hasSumOfInversions
    • sumOfInversions

      protected double sumOfInversions
    • sumOfPowers

      protected double[] sumOfPowers
  • Constructor Details

    • MightyStaticBin1D

      public MightyStaticBin1D()
      Constructs and returns an empty bin with limited functionality but good performance; equivalent to MightyStaticBin1D(false,false,4).
    • MightyStaticBin1D

      public MightyStaticBin1D(boolean hasSumOfLogarithms, boolean hasSumOfInversions, int maxOrderForSumOfPowers)
      Constructs and returns an empty bin with the given capabilities.
      Parameters:
      hasSumOfLogarithms - Tells whether sumOfLogarithms() can return meaningful results. Set this parameter to false if measures of sum of logarithms, geometric mean and product are not required.

      hasSumOfInversions - Tells whether sumOfInversions() can return meaningful results. Set this parameter to false if measures of sum of inversions, harmonic mean and sumOfPowers(-1) are not required.

      maxOrderForSumOfPowers - The maximum order k for which sumOfPowers(int) can return meaningful results. Set this parameter to at least 3 if the skew is required, to at least 4 if the kurtosis is required. In general, if moments are required set this parameter at least as large as the largest required moment. This method always substitutes Math.max(2,maxOrderForSumOfPowers) for the parameter passed in. Thus, sumOfPowers(0..2) always returns meaningful results.
      See Also:
  • Method Details

    • addAllOfFromTo

      public void addAllOfFromTo(DoubleArrayList list, int from, int to)
      Adds the part of the specified list between indexes from (inclusive) and to (inclusive) to the receiver.
      Overrides:
      addAllOfFromTo in class StaticBin1D
      Parameters:
      list - the list of which elements shall be added.
      from - the index of the first element to be added (inclusive).
      to - the index of the last element to be added (inclusive).
      Throws:
      IndexOutOfBoundsException - if list.size()>0 invalid input: '&'invalid input: '&' (from<0 || from>to || to>=list.size()).
    • clearAllMeasures

      protected void clearAllMeasures()
      Resets the values of all measures.
      Overrides:
      clearAllMeasures in class StaticBin1D
    • clone

      public Object clone()
      Returns a deep copy of the receiver.
      Overrides:
      clone in class PersistentObject
      Returns:
      a deep copy of the receiver.
    • compareWith

      public String compareWith(AbstractBin1D other)
      Computes the deviations from the receiver's measures to another bin's measures.
      Overrides:
      compareWith in class AbstractBin1D
      Parameters:
      other - the other bin to compare with
      Returns:
      a summary of the deviations.
    • geometricMean

      public double geometricMean()
      Returns the geometric mean, which is Product( x[i] )1.0/size(). This method tries to avoid overflows at the expense of an equivalent but somewhat inefficient definition: geoMean = exp( Sum( Log(x[i]) ) / size()). Note that for a geometric mean to be meaningful, the minimum of the data sequence must not be less or equal to zero.
      Returns:
      the geometric mean; Double.NaN if !hasSumOfLogarithms().
    • getMaxOrderForSumOfPowers

      public int getMaxOrderForSumOfPowers()
      Returns the maximum order k for which sums of powers are retrievable, as specified upon instance construction.
      See Also:
    • getMinOrderForSumOfPowers

      public int getMinOrderForSumOfPowers()
      Returns the minimum order k for which sums of powers are retrievable, as specified upon instance construction.
      See Also:
    • harmonicMean

      public double harmonicMean()
      Returns the harmonic mean, which is size() / Sum( 1/x[i] ). Remember: If the receiver contains at least one element of 0.0, the harmonic mean is 0.0.
      Returns:
      the harmonic mean; Double.NaN if !hasSumOfInversions().
      See Also:
    • hasSumOfInversions

      public boolean hasSumOfInversions()
      Returns whether sumOfInversions() can return meaningful results.
      Returns:
      false if the bin was constructed with insufficient parametrization, true otherwise. See the constructors for proper parametrization.
    • hasSumOfLogarithms

      public boolean hasSumOfLogarithms()
      Tells whether sumOfLogarithms() can return meaningful results.
      Returns:
      false if the bin was constructed with insufficient parametrization, true otherwise. See the constructors for proper parametrization.
    • hasSumOfPowers

      public boolean hasSumOfPowers(int k)
      Tells whether sumOfPowers(k) can return meaningful results. Defined as hasSumOfPowers(k) invalid input: '<'==> getMinOrderForSumOfPowers() invalid input: '<'= k invalid input: '&'invalid input: '&' k invalid input: '<'= getMaxOrderForSumOfPowers(). A return value of true implies that hasSumOfPowers(k-1) .. hasSumOfPowers(0) will also return true. See the constructors for proper parametrization.

      Details: hasSumOfPowers(0..2) will always yield true. hasSumOfPowers(-1) invalid input: '<'==> hasSumOfInversions().

      Returns:
      false if the bin was constructed with insufficient parametrization, true otherwise.
      See Also:
    • kurtosis

      public double kurtosis()
      Returns the kurtosis (aka excess), which is -3 + moment(4,mean()) / standardDeviation()4.
      Returns:
      the kurtosis; Double.NaN if !hasSumOfPowers(4).
      See Also:
    • moment

      public double moment(int k, double c)
      Returns the moment of k-th order with value c, which is Sum( (x[i]-c)k ) / size().
      Parameters:
      k - the order; must be greater than or equal to zero.
      c - any number.
      Returns:
      Double.NaN if !hasSumOfPower(k).
      Throws:
      IllegalArgumentException - if k invalid input: '<' 0.
    • product

      public double product()
      Returns the product, which is Prod( x[i] ). In other words: x[0]*x[1]*...*x[size()-1].
      Returns:
      the product; Double.NaN if !hasSumOfLogarithms().
      See Also:
    • setMaxOrderForSumOfPowers

      protected void setMaxOrderForSumOfPowers(int max_k)
      Sets the range of orders in which sums of powers are to be computed. In other words, sumOfPower(k) will return Sum( x[i]^k ) if min_k invalid input: '<'= k invalid input: '<'= max_k || 0 invalid input: '<'= k invalid input: '<'= 2 and throw an exception otherwise.
      See Also:
      • invalid reference
        #isLegalOrder(int)
      • sumOfPowers(int)
      • invalid reference
        #getRangeForSumOfPowers()
    • skew

      public double skew()
      Returns the skew, which is moment(3,mean()) / standardDeviation()3.
      Returns:
      the skew; Double.NaN if !hasSumOfPowers(3).
      See Also:
    • sumOfInversions

      public double sumOfInversions()
      Returns the sum of inversions, which is Sum( 1 / x[i] ).
      Returns:
      the sum of inversions; Double.NaN if !hasSumOfInversions().
      See Also:
    • sumOfLogarithms

      public double sumOfLogarithms()
      Returns the sum of logarithms, which is Sum( Log(x[i]) ).
      Returns:
      the sum of logarithms; Double.NaN if !hasSumOfLogarithms().
      See Also:
    • sumOfPowers

      public double sumOfPowers(int k)
      Returns the k-th order sum of powers, which is Sum( x[i]k ).
      Parameters:
      k - the order of the powers.
      Returns:
      the sum of powers; Double.NaN if !hasSumOfPowers(k).
      See Also:
    • toString

      public String toString()
      Returns a String representation of the receiver.
      Overrides:
      toString in class AbstractBin1D
    • xcheckOrder

      protected void xcheckOrder(int k)
    • xequals

      protected boolean xequals(Object object)
      Returns whether two bins are equal; They are equal if the other object is of the same class or a subclass of this class and both have the same size, minimum, maximum, sum, sumOfSquares, sumOfInversions and sumOfLogarithms.
    • xhasSumOfPowers

      protected boolean xhasSumOfPowers(int fromK, int toK)
      Tells whether sumOfPowers(fromK) .. sumOfPowers(toK) can return meaningful results.
      Returns:
      false if the bin was constructed with insufficient parametrization, true otherwise. See the constructors for proper parametrization.
      Throws:
      IllegalArgumentException - if fromK > toK.
    • xisLegalOrder

      protected boolean xisLegalOrder(int k)
      Returns getMinOrderForSumOfPowers() invalid input: '<'= k invalid input: '&'invalid input: '&' k invalid input: '<'= getMaxOrderForSumOfPowers().