-
Notifications
You must be signed in to change notification settings - Fork 58
/
Central_Limit_Theorem_Visualization_in_the_Bizarrely_Universe.java
57 lines (48 loc) · 2.34 KB
/
Central_Limit_Theorem_Visualization_in_the_Bizarrely_Universe.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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
import java.util.Random;
import org.apache.commons.math3.stat.descriptive.moment.Mean;
import org.apache.commons.math3.distribution.NormalDistribution;
public class CentralLimitTheoremAnimation {
public static double[][] generateBizarrelyUniverse(int numGalaxies, int numDimensions) {
Random random = new Random();
double[][] galaxies = new double[numGalaxies][numDimensions];
for (int i = 0; i < numGalaxies; i++) {
for (int j = 0; j < numDimensions; j++) {
galaxies[i][j] = random.nextGaussian();
}
}
return galaxies;
}
public static double[] centralLimitTheorem(int numGalaxies, int numDimensions, int numSamples, int sampleSize) {
double[] sampleMeans = new double[numSamples];
for (int s = 0; s < numSamples; s++) {
double[][] galaxies = generateBizarrelyUniverse(numGalaxies, numDimensions);
double[] sample = new double[sampleSize];
for (int i = 0; i < sampleSize; i++) {
sample[i] = galaxies[i][0]; // Take the first dimension for simplicity
}
Mean mean = new Mean();
sampleMeans[s] = mean.evaluate(sample);
}
return sampleMeans;
}
public static void main(String[] args) {
int numGalaxies = 1000;
int numDimensions = 3;
int numSamples = 100;
int sampleSize = 10;
// Step 5: Explanation
System.out.println("Welcome to the CLT Bizarrely Universe!");
System.out.println("In this universe, galaxies are randomly scattered in a 3D space.");
System.out.println("Let's visualize the Bizarrely Universe:");
double[][] galaxies = generateBizarrelyUniverse(numGalaxies, numDimensions);
// Visualization of the Bizarrely Universe
// Your Java plotting code goes here
System.out.println("\nNow, let's apply the Central Limit Theorem.");
System.out.println("We'll take " + numSamples + " samples of size " + sampleSize +
" and observe how their means converge to a Gaussian distribution.");
System.out.println("Creating the animation...");
double[] sampleMeans = centralLimitTheorem(numGalaxies, numDimensions, numSamples, sampleSize);
// Animation of the Central Limit Theorem
// Your Java plotting code goes here
}
}