类 StdStats


  • public final class StdStats
    extends java.lang.Object
    The StdStats class provides static methods for computing statistics such as min, max, mean, sample standard deviation, and sample variance.

    For additional documentation, see Section 2.2 of Computer Science: An Interdisciplinary Approach by Robert Sedgewick and Kevin Wayne.

    • 方法概要

      修饰符和类型 方法 说明
      static void main​(java.lang.String[] args)
      Unit tests StdStats.
      static double max​(double[] a)
      Returns the maximum value in the specified array.
      static double max​(double[] a, int lo, int hi)
      Returns the maximum value in the specified subarray.
      static int max​(int[] a)
      Returns the maximum value in the specified array.
      static double mean​(double[] a)
      Returns the average value in the specified array.
      static double mean​(double[] a, int lo, int hi)
      Returns the average value in the specified subarray.
      static double mean​(int[] a)
      Returns the average value in the specified array.
      static double min​(double[] a)
      Returns the minimum value in the specified array.
      static double min​(double[] a, int lo, int hi)
      Returns the minimum value in the specified subarray.
      static int min​(int[] a)
      Returns the minimum value in the specified array.
      static void plotBars​(double[] a)
      Plots bars from (0, ai) to (ai) for each i to standard draw.
      static void plotLines​(double[] a)
      Plots the line segments connecting (i, ai) to (i+1, ai+1) for each i to standard draw.
      static void plotPoints​(double[] a)
      Plots the points (0, a0), (1, a1), ..., (n-1, an-1) to standard draw.
      static double stddev​(double[] a)
      Returns the sample standard deviation in the specified array.
      static double stddev​(double[] a, int lo, int hi)
      Returns the sample standard deviation in the specified subarray.
      static double stddev​(int[] a)
      Returns the sample standard deviation in the specified array.
      static double stddevp​(double[] a)
      Returns the population standard deviation in the specified array.
      static double stddevp​(double[] a, int lo, int hi)
      Returns the population standard deviation in the specified subarray.
      static double var​(double[] a)
      Returns the sample variance in the specified array.
      static double var​(double[] a, int lo, int hi)
      Returns the sample variance in the specified subarray.
      static double var​(int[] a)
      Returns the sample variance in the specified array.
      static double varp​(double[] a)
      Returns the population variance in the specified array.
      static double varp​(double[] a, int lo, int hi)
      Returns the population variance in the specified subarray.
      • 从类继承的方法 java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • 方法详细资料

      • max

        public static double max​(double[] a)
        Returns the maximum value in the specified array.
        参数:
        a - the array
        返回:
        the maximum value in the array a[]; Double.NEGATIVE_INFINITY if no such value
      • max

        public static double max​(double[] a,
                                 int lo,
                                 int hi)
        Returns the maximum value in the specified subarray.
        参数:
        a - the array
        lo - the left endpoint of the subarray (inclusive)
        hi - the right endpoint of the subarray (exclusive)
        返回:
        the maximum value in the subarray a[lo..hi); Double.NEGATIVE_INFINITY if no such value
        抛出:
        java.lang.IllegalArgumentException - if a is null
        java.lang.IllegalArgumentException - unless (0 <= lo) && (lo < hi) && (hi <= a.length)
      • max

        public static int max​(int[] a)
        Returns the maximum value in the specified array.
        参数:
        a - the array
        返回:
        the maximum value in the array a[]; Integer.MIN_VALUE if no such value
      • min

        public static double min​(double[] a)
        Returns the minimum value in the specified array.
        参数:
        a - the array
        返回:
        the minimum value in the array a[]; Double.POSITIVE_INFINITY if no such value
      • min

        public static double min​(double[] a,
                                 int lo,
                                 int hi)
        Returns the minimum value in the specified subarray.
        参数:
        a - the array
        lo - the left endpoint of the subarray (inclusive)
        hi - the right endpoint of the subarray (exclusive)
        返回:
        the maximum value in the subarray a[lo..hi); Double.POSITIVE_INFINITY if no such value
        抛出:
        java.lang.IllegalArgumentException - if a is null
        java.lang.IllegalArgumentException - unless (0 <= lo) && (lo < hi) && (hi <= a.length)
      • min

        public static int min​(int[] a)
        Returns the minimum value in the specified array.
        参数:
        a - the array
        返回:
        the minimum value in the array a[]; Integer.MAX_VALUE if no such value
      • mean

        public static double mean​(double[] a)
        Returns the average value in the specified array.
        参数:
        a - the array
        返回:
        the average value in the array a[]; Double.NaN if no such value
      • mean

        public static double mean​(double[] a,
                                  int lo,
                                  int hi)
        Returns the average value in the specified subarray.
        参数:
        a - the array
        lo - the left endpoint of the subarray (inclusive)
        hi - the right endpoint of the subarray (exclusive)
        返回:
        the average value in the subarray a[lo..hi); Double.NaN if no such value
        抛出:
        java.lang.IllegalArgumentException - if a is null
        java.lang.IllegalArgumentException - unless (0 <= lo) && (lo < hi) && (hi <= a.length)
      • mean

        public static double mean​(int[] a)
        Returns the average value in the specified array.
        参数:
        a - the array
        返回:
        the average value in the array a[]; Double.NaN if no such value
      • var

        public static double var​(double[] a)
        Returns the sample variance in the specified array.
        参数:
        a - the array
        返回:
        the sample variance in the array a[]; Double.NaN if no such value
      • var

        public static double var​(double[] a,
                                 int lo,
                                 int hi)
        Returns the sample variance in the specified subarray.
        参数:
        a - the array
        lo - the left endpoint of the subarray (inclusive)
        hi - the right endpoint of the subarray (exclusive)
        返回:
        the sample variance in the subarray a[lo..hi); Double.NaN if no such value
        抛出:
        java.lang.IllegalArgumentException - if a is null
        java.lang.IllegalArgumentException - unless (0 <= lo) && (lo < hi) && (hi <= a.length)
      • var

        public static double var​(int[] a)
        Returns the sample variance in the specified array.
        参数:
        a - the array
        返回:
        the sample variance in the array a[]; Double.NaN if no such value
      • varp

        public static double varp​(double[] a)
        Returns the population variance in the specified array.
        参数:
        a - the array
        返回:
        the population variance in the array a[]; Double.NaN if no such value
      • varp

        public static double varp​(double[] a,
                                  int lo,
                                  int hi)
        Returns the population variance in the specified subarray.
        参数:
        a - the array
        lo - the left endpoint of the subarray (inclusive)
        hi - the right endpoint of the subarray (exclusive)
        返回:
        the population variance in the subarray a[lo..hi); Double.NaN if no such value
        抛出:
        java.lang.IllegalArgumentException - if a is null
        java.lang.IllegalArgumentException - unless (0 <= lo) && (lo < hi) && (hi <= a.length)
      • stddev

        public static double stddev​(double[] a)
        Returns the sample standard deviation in the specified array.
        参数:
        a - the array
        返回:
        the sample standard deviation in the array a[]; Double.NaN if no such value
      • stddev

        public static double stddev​(int[] a)
        Returns the sample standard deviation in the specified array.
        参数:
        a - the array
        返回:
        the sample standard deviation in the array a[]; Double.NaN if no such value
      • stddev

        public static double stddev​(double[] a,
                                    int lo,
                                    int hi)
        Returns the sample standard deviation in the specified subarray.
        参数:
        a - the array
        lo - the left endpoint of the subarray (inclusive)
        hi - the right endpoint of the subarray (exclusive)
        返回:
        the sample standard deviation in the subarray a[lo..hi); Double.NaN if no such value
        抛出:
        java.lang.IllegalArgumentException - if a is null
        java.lang.IllegalArgumentException - unless (0 <= lo) && (lo < hi) && (hi <= a.length)
      • stddevp

        public static double stddevp​(double[] a)
        Returns the population standard deviation in the specified array.
        参数:
        a - the array
        返回:
        the population standard deviation in the array; Double.NaN if no such value
      • stddevp

        public static double stddevp​(double[] a,
                                     int lo,
                                     int hi)
        Returns the population standard deviation in the specified subarray.
        参数:
        a - the array
        lo - the left endpoint of the subarray (inclusive)
        hi - the right endpoint of the subarray (exclusive)
        返回:
        the population standard deviation in the subarray a[lo..hi); Double.NaN if no such value
        抛出:
        java.lang.IllegalArgumentException - if a is null
        java.lang.IllegalArgumentException - unless (0 <= lo) && (lo < hi) && (hi <= a.length)
      • plotPoints

        public static void plotPoints​(double[] a)
        Plots the points (0, a0), (1, a1), ..., (n-1, an-1) to standard draw.
        参数:
        a - the array of values
      • plotLines

        public static void plotLines​(double[] a)
        Plots the line segments connecting (i, ai) to (i+1, ai+1) for each i to standard draw.
        参数:
        a - the array of values
      • plotBars

        public static void plotBars​(double[] a)
        Plots bars from (0, ai) to (ai) for each i to standard draw.
        参数:
        a - the array of values
      • main

        public static void main​(java.lang.String[] args)
        Unit tests StdStats. Convert command-line arguments to array of doubles and call various methods.
        参数:
        args - the command-line arguments