Scandiumlabs commited on
Commit
165db58
·
verified ·
1 Parent(s): 76f711c

Upload examples/visualization/plot_distributions.py with huggingface_hub

Browse files
examples/visualization/plot_distributions.py ADDED
@@ -0,0 +1,41 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """Example: Visualize dataset distributions.
2
+
3
+ Requires: matplotlib, numpy
4
+ """
5
+ import json, numpy as np
6
+ from collections import Counter
7
+
8
+ with open("dataset/entries_final_v3.json") as f:
9
+ entries = json.load(f)
10
+
11
+ # FE histogram
12
+ fe_vals = np.array([e.get("formation_energy_per_atom", 0)
13
+ for e in entries if e.get("formation_energy_per_atom") is not None])
14
+
15
+ print("FE Distribution (eV/atom):")
16
+ fe_range = (-5, 3)
17
+ bins = np.linspace(fe_range[0], fe_range[1], 40)
18
+ hist, edges = np.histogram(fe_vals, bins=bins)
19
+ max_bar = max(hist)
20
+ for i in range(len(hist)):
21
+ if hist[i] < max_bar * 0.01:
22
+ continue
23
+ bar_len = int(60 * hist[i] / max_bar)
24
+ print(f" {edges[i]:+5.2f}: {'█' * bar_len} ({hist[i]:,})")
25
+
26
+ # BG histogram
27
+ bg_vals = np.array([e.get("band_gap", 0)
28
+ for e in entries if e.get("band_gap") is not None])
29
+ bg_nonzero = bg_vals[bg_vals > 0.01]
30
+ print(f"\nBand Gap Distribution:")
31
+ print(f" Zero gap (metals): {np.sum(bg_vals <= 0.01):,} "
32
+ f"({100*np.sum(bg_vals <= 0.01)/len(bg_vals):.0f}%)")
33
+ print(f" Non-zero mean: {np.mean(bg_nonzero):.3f} eV")
34
+ print(f" Non-zero median: {np.median(bg_nonzero):.3f} eV")
35
+ print(f" Max: {np.max(bg_vals):.2f} eV")
36
+
37
+ # Tier pie
38
+ tiers = Counter(e.get("tier", "unknown") for e in entries)
39
+ print(f"\nTier Distribution:")
40
+ for tier, count in tiers.most_common():
41
+ print(f" {tier:12s}: {count:>7,} ({100*count/len(entries):.1f}%)")