Scandiumlabs commited on
Commit
6714b41
·
verified ·
1 Parent(s): c191181

Upload folder using huggingface_hub

Browse files
examples/benchmark/run_evaluation.py ADDED
@@ -0,0 +1,30 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """Example: Run benchmark evaluation with baseline."""
2
+ import json, sys
3
+
4
+ # Use the benchmark evaluate script
5
+ sys.path.insert(0, "benchmark")
6
+ from evaluate import load_dataset, load_split, generate_baseline, evaluate_predictions, per_family_metrics
7
+
8
+ # Load dataset and split
9
+ entries = load_dataset()
10
+ split = load_split("random_80_10_10")
11
+ print(f"Loaded {len(entries):,} entries")
12
+ print(f"Split: train={len(split['train']):,} val={len(split['val']):,} test={len(split['test']):,}")
13
+
14
+ # Generate mean baseline
15
+ predictions = generate_baseline(entries, split, "mean")
16
+ print(f"\nGenerated mean baseline predictions")
17
+
18
+ # Evaluate
19
+ overall = evaluate_predictions(entries, split, predictions)
20
+ print(f"\nOverall Results:")
21
+ for target, metrics in overall.items():
22
+ print(f" {target}: MAE={metrics['mae']:.4f} R²={metrics['r2']:.4f} RMSE={metrics['rmse']:.4f}")
23
+
24
+ # Per-family
25
+ family_results = per_family_metrics(entries, split, predictions)
26
+ print(f"\nPer-Family FE MAE:")
27
+ for fam in sorted(family_results.keys()):
28
+ fe = family_results[fam].get("FE", {})
29
+ mae = fe.get("mae", float("nan"))
30
+ print(f" {fam:25s}: {mae:.4f}")
examples/filter/filter_by_tier.py ADDED
@@ -0,0 +1,42 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """Example: Filter entries by tier and family."""
2
+ import json
3
+ from collections import Counter
4
+
5
+ with open("dataset/entries_final_v3.json") as f:
6
+ entries = json.load(f)
7
+
8
+ # Filter by tier
9
+ gold = [e for e in entries if e.get("tier") == "gold"]
10
+ strict_gold = [e for e in entries
11
+ if e.get("strict_gold", {}).get("is_strict_gold", False)]
12
+ validated = [e for e in entries if e.get("tier") == "validated"]
13
+
14
+ print(f"Gold: {len(gold):>8,}")
15
+ print(f"Strict Gold: {len(strict_gold):>8,}")
16
+ print(f"Validated: {len(validated):>8,}")
17
+
18
+ # Filter by battery family
19
+ battery_families = {"layered_oxide", "sulfide_sse", "halide_sse",
20
+ "polyanion", "nasicon", "garnet", "borohydride"}
21
+ battery = [e for e in entries
22
+ if set(e.get("families", [])) & battery_families]
23
+
24
+ print(f"\nBattery subset: {len(battery):,}")
25
+
26
+ # Filter by source
27
+ for src in ["mp", "oqmd", "jarvis"]:
28
+ subset = [e for e in entries if e.get("source") == src]
29
+ print(f" {src}: {len(subset):,} entries")
30
+
31
+ # Combine filters
32
+ battery_gold = [e for e in gold
33
+ if set(e.get("families", [])) & battery_families]
34
+ print(f"\nBattery + Gold: {len(battery_gold):,}")
35
+
36
+ # Quality score distribution
37
+ scores = Counter()
38
+ for e in gold:
39
+ scores[(e.get("quality_score", 0) // 10) * 10] += 1
40
+ print(f"\nGold quality score distribution:")
41
+ for k in sorted(scores.keys()):
42
+ print(f" {k}-{k+9}: {scores[k]:,}")
examples/load/load_dataset.py ADDED
@@ -0,0 +1,28 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """Example: Load and explore the Scandium Dataset."""
2
+ import json
3
+ from collections import Counter
4
+
5
+ # Load the full dataset
6
+ with open("dataset/entries_final_v3.json") as f:
7
+ entries = json.load(f)
8
+
9
+ print(f"Loaded {len(entries):,} entries")
10
+
11
+ # Quick statistics
12
+ tiers = Counter(e.get("tier", "unknown") for e in entries)
13
+ sources = Counter(e.get("source", "unknown") for e in entries)
14
+ formulas = len(set(e.get("formula", "") for e in entries))
15
+
16
+ print(f"\nStatistics:")
17
+ print(f" Sources: {dict(sources)}")
18
+ print(f" Tiers: {dict(tiers)}")
19
+ print(f" Unique formulas: {formulas:,}")
20
+ print(f" Families: {len(set(f for e in entries for f in e.get('families', [])))}")
21
+
22
+ # Sample entries
23
+ print(f"\nSample entries:")
24
+ for i in range(3):
25
+ e = entries[i]
26
+ print(f" {e['formula']:20s} | source={e['source']:6s} | "
27
+ f"FE={e.get('formation_energy_per_atom', 0):.3f} | "
28
+ f"tier={e.get('tier', '?')}")
examples/statistics/compute_statistics.py ADDED
@@ -0,0 +1,32 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """Example: Compute per-family and per-source statistics."""
2
+ import json
3
+ import numpy as np
4
+ from collections import Counter
5
+
6
+ with open("dataset/entries_final_v3.json") as f:
7
+ entries = json.load(f)
8
+
9
+ # Per-family statistics
10
+ families = Counter(f for e in entries for f in e.get("families", ["unknown"]))
11
+ print("Family Distribution:")
12
+ for fam, count in families.most_common():
13
+ pct = 100 * count / len(entries)
14
+ print(f" {fam:25s}: {count:>7,} ({pct:.1f}%)")
15
+
16
+ # Per-source FE distribution
17
+ print("\nFE Distribution by Source:")
18
+ for src in ["mp", "oqmd", "jarvis"]:
19
+ subset = [e for e in entries if e.get("source") == src]
20
+ fe_vals = [e.get("formation_energy_per_atom", 0) for e in subset
21
+ if e.get("formation_energy_per_atom") is not None]
22
+ print(f" {src:8s}: mean={np.mean(fe_vals):.3f} "
23
+ f"median={np.median(fe_vals):.3f} "
24
+ f"std={np.std(fe_vals):.3f} "
25
+ f"N={len(fe_vals):,}")
26
+
27
+ # Coverage analysis
28
+ print("\nProperty Coverage:")
29
+ for prop in ["formation_energy_per_atom", "energy_above_hull", "band_gap"]:
30
+ present = sum(1 for e in entries if e.get(prop) is not None)
31
+ print(f" {prop:35s}: {present:>7,} / {len(entries):,} "
32
+ f"({100*present/len(entries):.1f}%)")
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}%)")
Free AI Image Generator No sign-up. Instant results. Open Now