Class ExactDoubleQuantileFinder

java.lang.Object
cern.colt.PersistentObject
cern.jet.stat.quantile.ExactDoubleQuantileFinder
All Implemented Interfaces:
DoubleQuantileFinder, Serializable, Cloneable

class ExactDoubleQuantileFinder extends PersistentObject implements DoubleQuantileFinder
Exact quantile finding algorithm for known and unknown N requiring large main memory; computes quantiles over a sequence of double elements. The folkore algorithm: Keeps all elements in main memory, sorts the list, then picks the quantiles.
Version:
1.0, 09/24/99
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    protected DoubleArrayList
     
    protected boolean
     

    Fields inherited from class cern.colt.PersistentObject

    serialVersionUID
  • Constructor Summary

    Constructors
    Constructor
    Description
    Constructs an empty exact quantile finder.
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    add(double value)
    Adds a value to the receiver.
    void
    Adds all values of the specified list to the receiver.
    void
    addAllOfFromTo(DoubleArrayList values, int from, int to)
    Adds the part of the specified list between indexes from (inclusive) and to (inclusive) to the receiver.
    void
    Removes all elements from the receiver.
    Returns a deep copy of the receiver.
    boolean
    contains(double element)
    Returns whether the specified element is contained in the receiver.
    boolean
    Applies a procedure to each element of the receiver, if any.
    long
    Returns the number of elements currently needed to store all contained elements.
    double
    phi(double element)
    Returns how many percent of the elements contained in the receiver are <= element.
    Computes the specified quantile elements over the values previously added.
    long
    Returns the number of elements currently contained in the receiver (identical to the number of values added so far).
    protected void
    Sorts the receiver.
    Returns a String representation of the receiver.
    long
    Returns the number of elements currently needed to store all contained elements.

    Methods inherited from class java.lang.Object

    equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
  • Field Details

    • buffer

      protected DoubleArrayList buffer
    • isSorted

      protected boolean isSorted
  • Constructor Details

    • ExactDoubleQuantileFinder

      public ExactDoubleQuantileFinder()
      Constructs an empty exact quantile finder.
  • Method Details

    • add

      public void add(double value)
      Adds a value to the receiver.
      Specified by:
      add in interface DoubleQuantileFinder
      Parameters:
      value - the value to add.
    • addAllOf

      public void addAllOf(DoubleArrayList values)
      Adds all values of the specified list to the receiver.
      Specified by:
      addAllOf in interface DoubleQuantileFinder
      Parameters:
      values - the list of which all values shall be added.
    • addAllOfFromTo

      public void addAllOfFromTo(DoubleArrayList values, int from, int to)
      Adds the part of the specified list between indexes from (inclusive) and to (inclusive) to the receiver.
      Specified by:
      addAllOfFromTo in interface DoubleQuantileFinder
      Parameters:
      values - 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).
    • clear

      public void clear()
      Removes all elements from the receiver. The receiver will be empty after this call returns, and its memory requirements will be close to zero.
      Specified by:
      clear in interface DoubleQuantileFinder
    • clone

      public Object clone()
      Returns a deep copy of the receiver.
      Specified by:
      clone in interface DoubleQuantileFinder
      Overrides:
      clone in class PersistentObject
      Returns:
      a deep copy of the receiver.
    • contains

      public boolean contains(double element)
      Returns whether the specified element is contained in the receiver.
    • forEach

      public boolean forEach(DoubleProcedure procedure)
      Applies a procedure to each element of the receiver, if any. Iterates over the receiver in no particular order.
      Specified by:
      forEach in interface DoubleQuantileFinder
      Parameters:
      procedure - the procedure to be applied. Stops iteration if the procedure returns false, otherwise continues.
      Returns:
      false if the procedure stopped before all elements where iterated over, true otherwise.
    • memory

      public long memory()
      Returns the number of elements currently needed to store all contained elements. This number usually differs from the results of method size(), according to the underlying datastructure.
      Specified by:
      memory in interface DoubleQuantileFinder
    • phi

      public double phi(double element)
      Returns how many percent of the elements contained in the receiver are <= element. Does linear interpolation if the element is not contained but lies in between two contained elements.
      Specified by:
      phi in interface DoubleQuantileFinder
      Parameters:
      the - element to search for.
      Returns:
      the percentage p of elements <= element (0.0 <= p <=1.0).
    • quantileElements

      public DoubleArrayList quantileElements(DoubleArrayList phis)
      Computes the specified quantile elements over the values previously added.
      Specified by:
      quantileElements in interface DoubleQuantileFinder
      Parameters:
      phis - the quantiles for which elements are to be computed. Each phi must be in the interval [0.0,1.0]. phis must be sorted ascending.
      Returns:
      the exact quantile elements.
    • size

      public long size()
      Returns the number of elements currently contained in the receiver (identical to the number of values added so far).
      Specified by:
      size in interface DoubleQuantileFinder
    • sort

      protected void sort()
      Sorts the receiver.
    • toString

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

      public long totalMemory()
      Returns the number of elements currently needed to store all contained elements. This number usually differs from the results of method size(), according to the underlying datastructure.
      Specified by:
      totalMemory in interface DoubleQuantileFinder