Class StdStats
- Object
-
- StdStats
-
public final class StdStats extends Object
TheStdStatsclass 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.
- Author:
- Robert Sedgewick, Kevin Wayne
-
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static voidmain(String[] args)Unit testsStdStats.static doublemax(double[] a)Returns the maximum value in the specified array.static doublemax(double[] a, int lo, int hi)Returns the maximum value in the specified subarray.static intmax(int[] a)Returns the maximum value in the specified array.static doublemean(double[] a)Returns the average value in the specified array.static doublemean(double[] a, int lo, int hi)Returns the average value in the specified subarray.static doublemean(int[] a)Returns the average value in the specified array.static doublemin(double[] a)Returns the minimum value in the specified array.static doublemin(double[] a, int lo, int hi)Returns the minimum value in the specified subarray.static intmin(int[] a)Returns the minimum value in the specified array.static voidplotBars(double[] a)Plots bars from (0, ai) to (ai) for each i to standard draw.static voidplotLines(double[] a)Plots the line segments connecting (i, ai) to (i+1, ai+1) for each i to standard draw.static voidplotPoints(double[] a)Plots the points (0, a0), (1, a1), ..., (n-1, an-1) to standard draw.static doublestddev(double[] a)Returns the sample standard deviation in the specified array.static doublestddev(double[] a, int lo, int hi)Returns the sample standard deviation in the specified subarray.static doublestddev(int[] a)Returns the sample standard deviation in the specified array.static doublestddevp(double[] a)Returns the population standard deviation in the specified array.static doublestddevp(double[] a, int lo, int hi)Returns the population standard deviation in the specified subarray.static doublevar(double[] a)Returns the sample variance in the specified array.static doublevar(double[] a, int lo, int hi)Returns the sample variance in the specified subarray.static doublevar(int[] a)Returns the sample variance in the specified array.static doublevarp(double[] a)Returns the population variance in the specified array.static doublevarp(double[] a, int lo, int hi)Returns the population variance in the specified subarray.
-
-
-
Method Detail
-
max
public static double max(double[] a)
Returns the maximum value in the specified array.- Parameters:
a- the array- Returns:
- the maximum value in the array
a[];Double.NEGATIVE_INFINITYif no such value
-
max
public static double max(double[] a, int lo, int hi)Returns the maximum value in the specified subarray.- Parameters:
a- the arraylo- the left endpoint of the subarray (inclusive)hi- the right endpoint of the subarray (exclusive)- Returns:
- the maximum value in the subarray
a[lo..hi);Double.NEGATIVE_INFINITYif no such value - Throws:
IllegalArgumentException- ifaisnullIllegalArgumentException- unless(0 <= lo) && (lo < hi) && (hi <= a.length)
-
max
public static int max(int[] a)
Returns the maximum value in the specified array.- Parameters:
a- the array- Returns:
- the maximum value in the array
a[];Integer.MIN_VALUEif no such value
-
min
public static double min(double[] a)
Returns the minimum value in the specified array.- Parameters:
a- the array- Returns:
- the minimum value in the array
a[];Double.POSITIVE_INFINITYif no such value
-
min
public static double min(double[] a, int lo, int hi)Returns the minimum value in the specified subarray.- Parameters:
a- the arraylo- the left endpoint of the subarray (inclusive)hi- the right endpoint of the subarray (exclusive)- Returns:
- the maximum value in the subarray
a[lo..hi);Double.POSITIVE_INFINITYif no such value - Throws:
IllegalArgumentException- ifaisnullIllegalArgumentException- unless(0 <= lo) && (lo < hi) && (hi <= a.length)
-
min
public static int min(int[] a)
Returns the minimum value in the specified array.- Parameters:
a- the array- Returns:
- the minimum value in the array
a[];Integer.MAX_VALUEif no such value
-
mean
public static double mean(double[] a)
Returns the average value in the specified array.- Parameters:
a- the array- Returns:
- the average value in the array
a[];Double.NaNif no such value
-
mean
public static double mean(double[] a, int lo, int hi)Returns the average value in the specified subarray.- Parameters:
a- the arraylo- the left endpoint of the subarray (inclusive)hi- the right endpoint of the subarray (exclusive)- Returns:
- the average value in the subarray
a[lo..hi);Double.NaNif no such value - Throws:
IllegalArgumentException- ifaisnullIllegalArgumentException- unless(0 <= lo) && (lo < hi) && (hi <= a.length)
-
mean
public static double mean(int[] a)
Returns the average value in the specified array.- Parameters:
a- the array- Returns:
- the average value in the array
a[];Double.NaNif no such value
-
var
public static double var(double[] a)
Returns the sample variance in the specified array.- Parameters:
a- the array- Returns:
- the sample variance in the array
a[];Double.NaNif no such value
-
var
public static double var(double[] a, int lo, int hi)Returns the sample variance in the specified subarray.- Parameters:
a- the arraylo- the left endpoint of the subarray (inclusive)hi- the right endpoint of the subarray (exclusive)- Returns:
- the sample variance in the subarray
a[lo..hi);Double.NaNif no such value - Throws:
IllegalArgumentException- ifaisnullIllegalArgumentException- unless(0 <= lo) && (lo < hi) && (hi <= a.length)
-
var
public static double var(int[] a)
Returns the sample variance in the specified array.- Parameters:
a- the array- Returns:
- the sample variance in the array
a[];Double.NaNif no such value
-
varp
public static double varp(double[] a)
Returns the population variance in the specified array.- Parameters:
a- the array- Returns:
- the population variance in the array
a[];Double.NaNif no such value
-
varp
public static double varp(double[] a, int lo, int hi)Returns the population variance in the specified subarray.- Parameters:
a- the arraylo- the left endpoint of the subarray (inclusive)hi- the right endpoint of the subarray (exclusive)- Returns:
- the population variance in the subarray
a[lo..hi);Double.NaNif no such value - Throws:
IllegalArgumentException- ifaisnullIllegalArgumentException- unless(0 <= lo) && (lo < hi) && (hi <= a.length)
-
stddev
public static double stddev(double[] a)
Returns the sample standard deviation in the specified array.- Parameters:
a- the array- Returns:
- the sample standard deviation in the array
a[];Double.NaNif no such value
-
stddev
public static double stddev(int[] a)
Returns the sample standard deviation in the specified array.- Parameters:
a- the array- Returns:
- the sample standard deviation in the array
a[];Double.NaNif no such value
-
stddev
public static double stddev(double[] a, int lo, int hi)Returns the sample standard deviation in the specified subarray.- Parameters:
a- the arraylo- the left endpoint of the subarray (inclusive)hi- the right endpoint of the subarray (exclusive)- Returns:
- the sample standard deviation in the subarray
a[lo..hi);Double.NaNif no such value - Throws:
IllegalArgumentException- ifaisnullIllegalArgumentException- unless(0 <= lo) && (lo < hi) && (hi <= a.length)
-
stddevp
public static double stddevp(double[] a)
Returns the population standard deviation in the specified array.- Parameters:
a- the array- Returns:
- the population standard deviation in the array;
Double.NaNif no such value
-
stddevp
public static double stddevp(double[] a, int lo, int hi)Returns the population standard deviation in the specified subarray.- Parameters:
a- the arraylo- the left endpoint of the subarray (inclusive)hi- the right endpoint of the subarray (exclusive)- Returns:
- the population standard deviation in the subarray
a[lo..hi);Double.NaNif no such value - Throws:
IllegalArgumentException- ifaisnullIllegalArgumentException- 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.- Parameters:
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.- Parameters:
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.- Parameters:
a- the array of values
-
main
public static void main(String[] args)
Unit testsStdStats. Convert command-line arguments to array of doubles and call various methods.- Parameters:
args- the command-line arguments
-
-