Skip to content

Commit 16f8c44

Browse files
committed
.
1 parent 416e015 commit 16f8c44

File tree

2 files changed

+38
-2
lines changed

2 files changed

+38
-2
lines changed

causalspyne/implicit_gen_Sigma.py

+6-2
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
from causalspyne.implicit_omega_condition_on_w import gen_joint_w_omega, get_max_degree
55
from causalspyne.implicit_omega import get_extreme_eigenvalue
66

7+
78
def cov_to_corr(covariance_matrix):
89
# Calculate the standard deviations
910
std_devs = np.sqrt(np.diag(covariance_matrix))
@@ -45,15 +46,18 @@ def gen_sigma_y(max_w=0.5):
4546
return mat_sigma, dmax, max_omega
4647

4748

48-
if __name__ == "__main__":
49+
def gen_spectrum():
4950
mat_sigma, dmax, max_omega = gen_sigma_y()
5051
print(f"sigma: {mat_sigma}")
5152
inv_sigma = np.linalg.inv(mat_sigma)
5253
eigv_max, _ = get_extreme_eigenvalue(inv_sigma)
5354
print(f"max eigen value: {eigv_max}")
5455
print(f"max degree: {dmax}, max_omega: {max_omega}")
55-
5656
mat_precision = cov_to_corr(inv_sigma)
5757
eigv_max, _ = get_extreme_eigenvalue(mat_precision)
5858
print(f"max eigen value: {eigv_max}")
59+
return eigv_max
5960

61+
62+
if __name__ == "__main__":
63+
gen_spectrum()
+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
import numpy as np
2+
import matplotlib.pyplot as plt
3+
from scipy import stats
4+
from causalspyne.implicit_gen_Sigma import gen_spectrum
5+
6+
7+
# Generate sample data
8+
9+
# samples = np.random.normal(size=10000)
10+
samples = [gen_spectrum() for _ in range(10000)]
11+
# Create histogram
12+
fig, ax = plt.subplots(figsize=(8, 6))
13+
14+
hist, bins, _ = ax.hist(samples, bins=30, density=True, alpha=0.7,
15+
label="Histogram")
16+
17+
# Calculate bin centers for PDF plotting
18+
bin_centers = 0.5 * (bins[1:] + bins[:-1])
19+
20+
# Compute PDF
21+
pdf = stats.norm.pdf(bin_centers)
22+
23+
# Plot PDF
24+
ax.plot(bin_centers, pdf, 'r-', label="PDF")
25+
26+
# Customize plot
27+
ax.set_xlabel('eigenvalue')
28+
ax.set_ylabel('Density')
29+
ax.set_title('Histogram of maximum eigenvalue distribution')
30+
ax.legend()
31+
32+
plt.show()

0 commit comments

Comments
 (0)