public final class StdStats extends Object
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.
Modifier and Type | Method and Description |
---|---|
static void |
main(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.
|
public static double max(double[] a)
a
- the arraya[]
;
Double.NEGATIVE_INFINITY
if no such valuepublic static double max(double[] a, int lo, int hi)
a
- the arraylo
- the left endpoint of the subarray (inclusive)hi
- the right endpoint of the subarray (exclusive)a[lo..hi)
;
Double.NEGATIVE_INFINITY
if no such valueIllegalArgumentException
- if a
is null
IllegalArgumentException
- unless (0 <= lo) && (lo < hi) && (hi <= a.length)
public static int max(int[] a)
a
- the arraya[]
;
Integer.MIN_VALUE
if no such valuepublic static double min(double[] a)
a
- the arraya[]
;
Double.POSITIVE_INFINITY
if no such valuepublic static double min(double[] a, int lo, int hi)
a
- the arraylo
- the left endpoint of the subarray (inclusive)hi
- the right endpoint of the subarray (exclusive)a[lo..hi)
;
Double.POSITIVE_INFINITY
if no such valueIllegalArgumentException
- if a
is null
IllegalArgumentException
- unless (0 <= lo) && (lo < hi) && (hi <= a.length)
public static int min(int[] a)
a
- the arraya[]
;
Integer.MAX_VALUE
if no such valuepublic static double mean(double[] a)
a
- the arraya[]
;
Double.NaN
if no such valuepublic static double mean(double[] a, int lo, int hi)
a
- the arraylo
- the left endpoint of the subarray (inclusive)hi
- the right endpoint of the subarray (exclusive)a[lo..hi)
;
Double.NaN
if no such valueIllegalArgumentException
- if a
is null
IllegalArgumentException
- unless (0 <= lo) && (lo < hi) && (hi <= a.length)
public static double mean(int[] a)
a
- the arraya[]
;
Double.NaN
if no such valuepublic static double var(double[] a)
a
- the arraya[]
;
Double.NaN
if no such valuepublic static double var(double[] a, int lo, int hi)
a
- the arraylo
- the left endpoint of the subarray (inclusive)hi
- the right endpoint of the subarray (exclusive)a[lo..hi)
;
Double.NaN
if no such valueIllegalArgumentException
- if a
is null
IllegalArgumentException
- unless (0 <= lo) && (lo < hi) && (hi <= a.length)
public static double var(int[] a)
a
- the arraya[]
;
Double.NaN
if no such valuepublic static double varp(double[] a)
a
- the arraya[]
;
Double.NaN
if no such valuepublic static double varp(double[] a, int lo, int hi)
a
- the arraylo
- the left endpoint of the subarray (inclusive)hi
- the right endpoint of the subarray (exclusive)a[lo..hi)
;
Double.NaN
if no such valueIllegalArgumentException
- if a
is null
IllegalArgumentException
- unless (0 <= lo) && (lo < hi) && (hi <= a.length)
public static double stddev(double[] a)
a
- the arraya[]
;
Double.NaN
if no such valuepublic static double stddev(int[] a)
a
- the arraya[]
;
Double.NaN
if no such valuepublic static double stddev(double[] a, int lo, int hi)
a
- the arraylo
- the left endpoint of the subarray (inclusive)hi
- the right endpoint of the subarray (exclusive)a[lo..hi)
;
Double.NaN
if no such valueIllegalArgumentException
- if a
is null
IllegalArgumentException
- unless (0 <= lo) && (lo < hi) && (hi <= a.length)
public static double stddevp(double[] a)
a
- the arrayDouble.NaN
if no such valuepublic static double stddevp(double[] a, int lo, int hi)
a
- the arraylo
- the left endpoint of the subarray (inclusive)hi
- the right endpoint of the subarray (exclusive)a[lo..hi)
;
Double.NaN
if no such valueIllegalArgumentException
- if a
is null
IllegalArgumentException
- unless (0 <= lo) && (lo < hi) && (hi <= a.length)
public static void plotPoints(double[] a)
a
- the array of valuespublic static void plotLines(double[] a)
a
- the array of valuespublic static void plotBars(double[] a)
a
- the array of valuespublic static void main(String[] args)
StdStats
.
Convert command-line arguments to array of doubles and call various methods.args
- the command-line arguments