-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSimulationAlgorithm.java
More file actions
38 lines (30 loc) · 1.05 KB
/
Copy pathSimulationAlgorithm.java
File metadata and controls
38 lines (30 loc) · 1.05 KB
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
import java.util.ArrayList;
public class SimulationAlgorithm extends AbstractSimulation{
public static void main(String[] args){
ArrayList<Integer> data = simulateSamples(1000);
drawHistogram(3000,data);
System.out.println("MEAN-> "+calculateMean(data));
System.out.println("DEVIATION-> "+calculateDeviation(data));
}
public static ArrayList<Integer> simulateSamples(int numSamples){
ArrayList<Integer> scores = new ArrayList();
Algorithm r = new Algorithm();
for (int i = 1; i <= numSamples; i++){
r.playGame();
scores.add(r.getScore());
}
return scores;
}
public static ArrayList<Integer> samplingDistribution(){
ArrayList<Integer> vals = new ArrayList();
for (int i = 0; i < 100; i++){
ArrayList<Integer> a = simulateSamples(100);
int sum = 0;
for (int j : a){
sum += j;
}
vals.add(sum/a.size());
}
return vals;
}
}