Skip to content

Commit 0d7c25d

Browse files
authored
Add simulation for fermion interactions and visualizations
This script simulates interactions between fermions, calculates directional and symmetric variants of a matrix, saves results to CSV files, computes statistics by generation, and generates heatmaps for visualization.
1 parent 7cb44af commit 0d7c25d

1 file changed

Lines changed: 102 additions & 0 deletions

File tree

Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
import numpy as np
2+
import pandas as pd
3+
import matplotlib.pyplot as plt
4+
import csv
5+
6+
# --- Dane wejściowe ---
7+
fermions = ["e","mu","tau","u","d","s","c","b","t","nu1","nu2","nu3"]
8+
theta = np.array([np.pi/6, np.pi/4, np.pi/3,
9+
np.pi/8, np.pi/10, np.pi/5,
10+
np.pi/2, 2*np.pi/3, 5*np.pi/6,
11+
np.pi/12, np.pi/6, np.pi/4])
12+
I0 = 0.009
13+
N = len(fermions)
14+
15+
# --- 1) F kierunkowe ---
16+
F = np.zeros((N,N))
17+
for i in range(N):
18+
for j in range(N):
19+
delta_theta = theta[j] - theta[i]
20+
F[i,j] = np.exp(I0 * delta_theta)
21+
22+
# --- 2) Symetryczne warianty ---
23+
F_sym_abs = np.exp(I0 * np.abs(np.subtract.outer(theta, theta)))
24+
F_sym_cos = np.exp(I0 * np.cos(np.subtract.outer(theta, theta)))
25+
26+
# --- 3) Zapis do CSV ---
27+
def save_csv(mat, filename):
28+
with open(filename, 'w', newline='') as csvfile:
29+
writer = csv.writer(csvfile)
30+
writer.writerow([""] + fermions)
31+
for i, row in enumerate(mat):
32+
writer.writerow([fermions[i]] + list(np.round(row,8)))
33+
34+
save_csv(F, 'Fij_toy_S2_directional.csv')
35+
save_csv(F_sym_abs, 'Fij_toy_S2_sym_abs.csv')
36+
save_csv(F_sym_cos, 'Fij_toy_S2_sym_cos.csv')
37+
38+
# --- 4) Statystyki po generacjach ---
39+
generation_map = {
40+
"e":1, "mu":2, "tau":3,
41+
"u":1, "d":1, "s":2, "c":2, "b":3, "t":3,
42+
"nu1":1, "nu2":2, "nu3":3
43+
}
44+
gens = [generation_map[f] for f in fermions]
45+
unique_gens = sorted(set(gens))
46+
47+
inter_means = {}
48+
for ga in unique_gens:
49+
for gb in unique_gens:
50+
idx_a = [i for i,f in enumerate(fermions) if generation_map[f]==ga]
51+
idx_b = [j for j,f in enumerate(fermions) if generation_map[f]==gb]
52+
vals = [F[i,j] for i in idx_a for j in idx_b]
53+
inter_means[(ga,gb)] = np.mean(vals)
54+
55+
# DataFrame
56+
rows = []
57+
for ga in unique_gens:
58+
for gb in unique_gens:
59+
rows.append({
60+
"gen_i": ga,
61+
"gen_j": gb,
62+
"mean_F_dir": inter_means[(ga,gb)],
63+
"mean_F_sym_abs": np.mean([F_sym_abs[i,j] for i in range(N) for j in range(N)
64+
if generation_map[fermions[i]]==ga and generation_map[fermions[j]]==gb]),
65+
"mean_F_sym_cos": np.mean([F_sym_cos[i,j] for i in range(N) for j in range(N)
66+
if generation_map[fermions[i]]==ga and generation_map[fermions[j]]==gb])
67+
})
68+
stats_df = pd.DataFrame(rows)
69+
stats_df.to_csv('Fij_toy_S2_stats_by_generation.csv', index=False)
70+
71+
# --- 5) Heatmapy ---
72+
plt.figure(figsize=(6,5))
73+
plt.title("F_ij (directional)")
74+
plt.imshow(F, aspect='auto')
75+
plt.colorbar()
76+
plt.xticks(ticks=np.arange(N), labels=fermions, rotation=90)
77+
plt.yticks(ticks=np.arange(N), labels=fermions)
78+
plt.tight_layout()
79+
plt.savefig('heatmap_F_directional.png')
80+
plt.close()
81+
82+
plt.figure(figsize=(6,5))
83+
plt.title("F_ij (sym |Δθ|)")
84+
plt.imshow(F_sym_abs, aspect='auto')
85+
plt.colorbar()
86+
plt.xticks(ticks=np.arange(N), labels=fermions, rotation=90)
87+
plt.yticks(ticks=np.arange(N), labels=fermions)
88+
plt.tight_layout()
89+
plt.savefig('heatmap_F_sym_abs.png')
90+
plt.close()
91+
92+
plt.figure(figsize=(6,5))
93+
plt.title("F_ij (sym cos)")
94+
plt.imshow(F_sym_cos, aspect='auto')
95+
plt.colorbar()
96+
plt.xticks(ticks=np.arange(N), labels=fermions, rotation=90)
97+
plt.yticks(ticks=np.arange(N), labels=fermions)
98+
plt.tight_layout()
99+
plt.savefig('heatmap_F_sym_cos.png')
100+
plt.close()
101+
102+
print("Gotowe: CSV i PNG wygenerowane w bieżącym folderze.")

0 commit comments

Comments
 (0)