-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathStatistics.java
41 lines (41 loc) · 1.06 KB
/
Statistics.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
/**
* Created by Paul on 5/3/2015.
*/
public class Statistics {
public static double mean(int[] a){
double sum = 0.0;
for(int i = 0; i < a.length; ++i){
sum += a[i];
}
return sum / a.length;
}
public static double mean(double[] a){
double sum = 0.0;
for(int i = 0; i < a.length; ++i){
sum += a[i];
}
return sum / a.length;
}
public static double var(int[] a){
double avg = mean(a);
double sum = 0.0;
for(int i = 0; i < a.length; ++i){
sum += (a[i] - avg) * (a[i] - avg);
}
return sum / (a.length - 1);
}
public static double var(double[] a){
double avg = mean(a);
double sum = 0.0;
for(int i = 0; i < a.length; ++i){
sum += (a[i] - avg) * (a[i] - avg);
}
return sum / (a.length - 1);
}
public static double stddev(int[] a){
return Math.sqrt(var(a));
}
public static double stddev(double[] a){
return Math.sqrt(var(a));
}
}