source: src/main/java/agents/ai2014/group11/Statistics.java@ 126

Last change on this file since 126 was 126, checked in by Aron Hammond, 6 years ago

Added function to calculate opposition to MultiLateralAnalysis.java

Moved code to add RLBOA listeners to RLBOAUtils is misc package

Added input for strategyParameters to SessionPanel (gui)

!! close SessionInfo after tournament; this caused /tmp/ to fill up with GeniusData files

Our own package:

  • Added opponents and strategies that are mentioned in the report
  • Change class hierarchy, agents can now extend from RLBOAagentBilateral to inherit RL functionality.
  • States extend from AbstractState
File size: 1.2 KB
Line 
1package agents.ai2014.group11;
2
3import java.util.Arrays;
4
5/**
6 * Class to use for basic statistics.
7 *
8 * Source:
9 * http://stackoverflow.com/questions/7988486/how-do-you-calculate-the-variance-median-and-standard-deviation-in-c-or-java
10 */
11public class Statistics {
12
13 /**
14 * Get the mean of dataset
15 * @param data
16 * @return
17 */
18 public static double getMean(double[] data) {
19 double sum = 0.0;
20 for (double a : data)
21 sum += a;
22 return sum / data.length;
23 }
24
25 /**
26 * Get the variance of dataset
27 * @param data
28 * @return
29 */
30 public static double getVariance(double[] data) {
31 double mean = getMean(data);
32 double temp = 0;
33 for (double a : data)
34 temp += (mean - a) * (mean - a);
35 return temp / data.length;
36 }
37
38 /**
39 * Get the standard deviation of dataset
40 * @param data
41 * @return
42 */
43 public static double getStdDev(double[] data) {
44 return Math.sqrt(getVariance(data));
45 }
46
47 /**
48 * Get the median of dataset
49 * @param data
50 * @return
51 */
52 public static double median(double[] data) {
53 double[] b = new double[data.length];
54 System.arraycopy(data, 0, b, 0, b.length);
55 Arrays.sort(b);
56
57 if (data.length % 2 == 0) {
58 return (b[(b.length / 2) - 1] + b[b.length / 2]) / 2.0;
59 } else {
60 return b[b.length / 2];
61 }
62 }
63}
Note: See TracBrowser for help on using the repository browser.