-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathsimulation_main.py
More file actions
69 lines (54 loc) · 2.51 KB
/
simulation_main.py
File metadata and controls
69 lines (54 loc) · 2.51 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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
import numpy as np
def simulate_angles(num_samples=100000):
"""
Simulate the angles and calculate the probability that |pos_neg| > |pos_neutral| and |pos_neg| > |neg_neutral|.
Parameters:
num_samples (int): Number of random samples to generate.
Returns:
tuple: Probability that |pos_neg| > |pos_neutral| and |pos_neg| > |neg_neutral|,
and average angle differences.
"""
# Initialize counters and lists
conditions_met_count = 0
pos_neg_differences = []
pos_neutral_differences = []
neg_neutral_differences = []
for _ in range(num_samples):
# Generate random values in the range [0, π/2]
pos = np.random.uniform(0, np.pi/2)
neutral = np.random.uniform(0, np.pi/2)
neg = np.random.uniform(0, np.pi/2)
# Calculate absolute differences
pos_neg = np.abs(pos - neg)
pos_neutral = np.abs(pos - neutral)
neg_neutral = np.abs(neg - neutral)
# Convert angle differences to their sine equivalents (using 1 - cos)
pos_neg_degree = 1 - np.cos(pos_neg)
pos_neutral_degree = 1 - np.cos(pos_neutral)
neg_neutral_degree = 1 - np.cos(neg_neutral)
# Store the differences (use degree representation)
pos_neg_differences.append(pos_neg_degree)
pos_neutral_differences.append(pos_neutral_degree)
neg_neutral_differences.append(neg_neutral_degree)
# Check the conditions
if pos_neg_degree > pos_neutral_degree and pos_neg_degree > neg_neutral_degree:
conditions_met_count += 1
# Calculate the probability
probability = conditions_met_count / num_samples
# Calculate average angle differences (in terms of degree representation)
avg_pos_neg = np.mean(pos_neg_differences)
avg_pos_neutral = np.mean(pos_neutral_differences)
avg_neg_neutral = np.mean(neg_neutral_differences)
return probability, avg_pos_neg, avg_pos_neutral, avg_neg_neutral
def main():
# Set the number of samples
num_samples = 100000
# Run the simulation
probability_result, avg_pos_neg, avg_pos_neutral, avg_neg_neutral = simulate_angles(num_samples)
# Print the results
print(f"The probability that |pos_neg| > |pos_neutral| and |pos_neg| > |neg_neutral| is: {probability_result:.4f}")
print(f"Average pos_neg difference: {avg_pos_neg:.4f}")
print(f"Average pos_neutral difference: {avg_pos_neutral:.4f}")
print(f"Average neg_neutral difference: {avg_neg_neutral:.4f}")
if __name__ == "__main__":
main()