19package denoptim.utils;
36 public static double sum(
double[] numbers)
39 for (
double number : numbers) {
53 public static double mean(
double[] numbers)
56 return sum / numbers.length;
67 public static double min(
double[] numbers)
69 double min = Integer.MAX_VALUE;
70 for (
double number : numbers) {
85 public static double max(
double[] numbers)
87 double max = Integer.MIN_VALUE;
88 for (
double number : numbers) {
107 public static double stddev(
double[] numbers,
boolean biasCorrected)
109 double stddev = Double.NaN;
110 int n = numbers.length;
115 stddev = Math.sqrt(
var(numbers, biasCorrected));
145 public static double var(
double[] numbers,
boolean biasCorrected)
147 int n = numbers.length;
154 double[] squares =
new double[numbers.length];
155 for (
int i=0; i<numbers.length; i++)
157 double XminMean = numbers[i] -
mean;
158 squares[i] = Math.pow(XminMean, 2);
160 double sum =
sum(squares);
161 return sum / (biasCorrected ? (n - 1) : n);
174 int middle = m.length / 2;
175 if (m.length % 2 == 1)
184 return (m[middle-1] + m[middle]) / 2.0;
205 public static double kurtosis(
double[] m,
boolean biasCorrected)
207 double value = Double.NaN;
211 double variance =
var(m, biasCorrected);
212 if (N <= 3 || variance < 10E-20)
219 double f1 = (n*(n+1)) /((n -1) * (n - 2) * (n - 3));
220 double avg =
mean(m);
221 double f2 = 0, f3 = 0;
222 for (
int i=0; i<N; i++)
224 f2 += Math.pow((m[i] - avg), 4);
225 f3 += Math.pow((m[i] - avg), 2);
228 double f4 = (3 * (n-1) * (n -1)) / ((n-2)*(n-3));
230 value = (f1 * (Math.pow(f2, 4)/Math.pow(f3, 2))) - f4;
246 public static double skewness(
double[] m,
boolean biasCorrected)
252 double sampleSizeCorrectionTerm = Math.sqrt(n * (n - 1)) / (n - 2);
253 double biasedStandardDeviation = Math.sqrt(n / (n - 1))
254 *
stddev(m, biasCorrected);
255 double accDeviationFromMean = 0.0;
258 accDeviationFromMean += v -
mean;
260 return sampleSizeCorrectionTerm
261 * (accDeviationFromMean / (n * biasedStandardDeviation));
Utilities for calculating basic statistics.
static double mean(double[] numbers)
Returns the mean number in the numbers list.
static double sum(double[] numbers)
Returns the sum number in the numbers list.
static double kurtosis(double[] m, boolean biasCorrected)
Computes the Kurtosis of the available values.
static double stddev(double[] numbers, boolean biasCorrected)
Returns the standard deviation of the numbers.
static double skewness(double[] m, boolean biasCorrected)
Computes the skewness of the available values.
static double median(double[] m)
Calculates median value of a sorted list.
static double var(double[] numbers, boolean biasCorrected)
Computes the variance of the available values.
static double min(double[] numbers)
Returns the minimum value among the numbers .
static double max(double[] numbers)
Returns the maximum value among the numbers .