Spaces:
Sleeping
Sleeping
Regenerate 9-vertex LLM benchmark with Bloch-Wigner and correct vertex config
Browse filesKey improvements:
- Use Bloch-Wigner dilogarithm for precise volume computation
- Fix vertex configuration: 0, 1, β + 6 free (was incorrectly 0, 1, i, β + 5)
- Add use_bloch_wigner parameter to ideal_poly_volume_via_delaunay()
- Update optimization script with correct vertex counts and improved docs
- New optimal volume: 8.162538347504972 (precise to 15 digits)
Bloch-Wigner is ~2Γ10β»β΅ more accurate than Lobachevsky with 256 terms.
π€ Generated with Claude Code
Co-Authored-By: Claude <noreply@anthropic.com>
examples/optimization/9vertex/optimize_9vertex_for_llm_test.py
CHANGED
|
@@ -2,7 +2,9 @@
|
|
| 2 |
"""
|
| 3 |
Find optimal 9-vertex ideal polyhedron for LLM benchmark test.
|
| 4 |
|
| 5 |
-
9 vertices = 0, 1,
|
|
|
|
|
|
|
| 6 |
"""
|
| 7 |
|
| 8 |
import numpy as np
|
|
@@ -20,12 +22,15 @@ from ideal_poly_volume_toolkit.geometry import ideal_poly_volume_via_delaunay
|
|
| 20 |
|
| 21 |
|
| 22 |
def compute_volume_objective(params, n_free):
|
| 23 |
-
"""Objective function: negative volume for minimization.
|
|
|
|
|
|
|
|
|
|
| 24 |
real_parts = params[:n_free]
|
| 25 |
imag_parts = params[n_free:]
|
| 26 |
|
| 27 |
-
# Fixed vertices: 0, 1
|
| 28 |
-
z_fixed = np.array([0.0 + 0.0j, 1.0 + 0.0j
|
| 29 |
|
| 30 |
# Free vertices
|
| 31 |
z_free = np.array([complex(r, i) for r, i in zip(real_parts, imag_parts)])
|
|
@@ -34,7 +39,8 @@ def compute_volume_objective(params, n_free):
|
|
| 34 |
z_all = np.concatenate([z_fixed, z_free])
|
| 35 |
|
| 36 |
try:
|
| 37 |
-
|
|
|
|
| 38 |
return -vol # Negative for maximization
|
| 39 |
except:
|
| 40 |
return 1e10 # Penalty for invalid configurations
|
|
@@ -42,12 +48,12 @@ def compute_volume_objective(params, n_free):
|
|
| 42 |
|
| 43 |
def main():
|
| 44 |
print("=" * 70)
|
| 45 |
-
print("Optimizing 9-vertex ideal polyhedron (
|
| 46 |
print("=" * 70)
|
| 47 |
|
| 48 |
-
n_free_vertices =
|
| 49 |
n_params = n_free_vertices * 2
|
| 50 |
-
n_trials =
|
| 51 |
|
| 52 |
# Bounds for optimization
|
| 53 |
bounds = [(-2, 2)] * n_params
|
|
@@ -97,15 +103,15 @@ def main():
|
|
| 97 |
real_parts = best_config[:n_free]
|
| 98 |
imag_parts = best_config[n_free:]
|
| 99 |
|
| 100 |
-
z_fixed = np.array([0.0 + 0.0j, 1.0 + 0.0j
|
| 101 |
z_free = np.array([complex(r, i) for r, i in zip(real_parts, imag_parts)])
|
| 102 |
z_all = np.concatenate([z_fixed, z_free])
|
| 103 |
|
| 104 |
print("\nVertices:")
|
| 105 |
-
print(" Fixed: 0, 1,
|
| 106 |
print(" Free:")
|
| 107 |
for i, z in enumerate(z_free):
|
| 108 |
-
print(f" z{i+
|
| 109 |
|
| 110 |
# Save results
|
| 111 |
result_data = {
|
|
@@ -114,15 +120,15 @@ def main():
|
|
| 114 |
"date": datetime.now().strftime("%Y-%m-%d %H:%M:%S"),
|
| 115 |
"n_vertices": 9,
|
| 116 |
"n_trials": n_trials,
|
| 117 |
-
"best_seed": int(best_seed)
|
|
|
|
| 118 |
},
|
| 119 |
"optimal_configuration": {
|
| 120 |
"volume": float(best_volume),
|
| 121 |
"vertices": {
|
| 122 |
"fixed": [
|
| 123 |
{"real": 0.0, "imag": 0.0},
|
| 124 |
-
{"real": 1.0, "imag": 0.0}
|
| 125 |
-
{"real": 0.0, "imag": 1.0}
|
| 126 |
],
|
| 127 |
"free": [
|
| 128 |
{"real": float(z.real), "imag": float(z.imag)}
|
|
|
|
| 2 |
"""
|
| 3 |
Find optimal 9-vertex ideal polyhedron for LLM benchmark test.
|
| 4 |
|
| 5 |
+
9 vertices = 0, 1, β + 6 free vertices = 12 real parameters
|
| 6 |
+
|
| 7 |
+
Uses Bloch-Wigner dilogarithm for precise volume computation.
|
| 8 |
"""
|
| 9 |
|
| 10 |
import numpy as np
|
|
|
|
| 22 |
|
| 23 |
|
| 24 |
def compute_volume_objective(params, n_free):
|
| 25 |
+
"""Objective function: negative volume for minimization.
|
| 26 |
+
|
| 27 |
+
Uses Bloch-Wigner dilogarithm for precise, fast volume computation.
|
| 28 |
+
"""
|
| 29 |
real_parts = params[:n_free]
|
| 30 |
imag_parts = params[n_free:]
|
| 31 |
|
| 32 |
+
# Fixed vertices: 0, 1 (β is implicit in the triangulation)
|
| 33 |
+
z_fixed = np.array([0.0 + 0.0j, 1.0 + 0.0j])
|
| 34 |
|
| 35 |
# Free vertices
|
| 36 |
z_free = np.array([complex(r, i) for r, i in zip(real_parts, imag_parts)])
|
|
|
|
| 39 |
z_all = np.concatenate([z_fixed, z_free])
|
| 40 |
|
| 41 |
try:
|
| 42 |
+
# Use Bloch-Wigner dilogarithm for precise computation
|
| 43 |
+
vol = ideal_poly_volume_via_delaunay(z_all, use_bloch_wigner=True)
|
| 44 |
return -vol # Negative for maximization
|
| 45 |
except:
|
| 46 |
return 1e10 # Penalty for invalid configurations
|
|
|
|
| 48 |
|
| 49 |
def main():
|
| 50 |
print("=" * 70)
|
| 51 |
+
print("Optimizing 9-vertex ideal polyhedron (6 free + 0,1,β)")
|
| 52 |
print("=" * 70)
|
| 53 |
|
| 54 |
+
n_free_vertices = 6 # 9 total = 0, 1, β + 6 free
|
| 55 |
n_params = n_free_vertices * 2
|
| 56 |
+
n_trials = 10 # More trials for better optimization
|
| 57 |
|
| 58 |
# Bounds for optimization
|
| 59 |
bounds = [(-2, 2)] * n_params
|
|
|
|
| 103 |
real_parts = best_config[:n_free]
|
| 104 |
imag_parts = best_config[n_free:]
|
| 105 |
|
| 106 |
+
z_fixed = np.array([0.0 + 0.0j, 1.0 + 0.0j])
|
| 107 |
z_free = np.array([complex(r, i) for r, i in zip(real_parts, imag_parts)])
|
| 108 |
z_all = np.concatenate([z_fixed, z_free])
|
| 109 |
|
| 110 |
print("\nVertices:")
|
| 111 |
+
print(" Fixed: 0, 1, β")
|
| 112 |
print(" Free:")
|
| 113 |
for i, z in enumerate(z_free):
|
| 114 |
+
print(f" z{i+2}: {z.real:.6f} + {z.imag:.6f}i")
|
| 115 |
|
| 116 |
# Save results
|
| 117 |
result_data = {
|
|
|
|
| 120 |
"date": datetime.now().strftime("%Y-%m-%d %H:%M:%S"),
|
| 121 |
"n_vertices": 9,
|
| 122 |
"n_trials": n_trials,
|
| 123 |
+
"best_seed": int(best_seed),
|
| 124 |
+
"computation_method": "Bloch-Wigner dilogarithm"
|
| 125 |
},
|
| 126 |
"optimal_configuration": {
|
| 127 |
"volume": float(best_volume),
|
| 128 |
"vertices": {
|
| 129 |
"fixed": [
|
| 130 |
{"real": 0.0, "imag": 0.0},
|
| 131 |
+
{"real": 1.0, "imag": 0.0}
|
|
|
|
| 132 |
],
|
| 133 |
"free": [
|
| 134 |
{"real": float(z.real), "imag": float(z.imag)}
|
ideal_poly_volume_toolkit/geometry.py
CHANGED
|
@@ -306,10 +306,34 @@ def ideal_poly_volume_via_hull_project_back(W, index_inf=0, mode="fast", dps=120
|
|
| 306 |
total += triangle_volume_from_points(z1, z2, z3, mode=mode, series_terms=series_terms, dps=dps)
|
| 307 |
return total
|
| 308 |
|
| 309 |
-
def ideal_poly_volume_via_delaunay(z_finite_complex: np.ndarray, mode="fast", dps=120, series_terms=64):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 310 |
idx_tris = delaunay_triangulation_indices(z_finite_complex)
|
| 311 |
total = 0.0
|
| 312 |
-
|
| 313 |
-
|
| 314 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 315 |
return total
|
|
|
|
| 306 |
total += triangle_volume_from_points(z1, z2, z3, mode=mode, series_terms=series_terms, dps=dps)
|
| 307 |
return total
|
| 308 |
|
| 309 |
+
def ideal_poly_volume_via_delaunay(z_finite_complex: np.ndarray, mode="fast", dps=120, series_terms=64, use_bloch_wigner=False):
|
| 310 |
+
"""
|
| 311 |
+
Compute volume of ideal polyhedron using Delaunay triangulation.
|
| 312 |
+
|
| 313 |
+
Args:
|
| 314 |
+
z_finite_complex: Array of finite vertices (complex numbers)
|
| 315 |
+
mode: "fast" (series) or "exact" (mpmath) - only used if use_bloch_wigner=False
|
| 316 |
+
dps: Decimal precision for exact mode
|
| 317 |
+
series_terms: Number of terms for fast mode
|
| 318 |
+
use_bloch_wigner: If True, use Bloch-Wigner dilogarithm (most accurate)
|
| 319 |
+
|
| 320 |
+
Returns:
|
| 321 |
+
Total volume as float
|
| 322 |
+
"""
|
| 323 |
idx_tris = delaunay_triangulation_indices(z_finite_complex)
|
| 324 |
total = 0.0
|
| 325 |
+
|
| 326 |
+
if use_bloch_wigner:
|
| 327 |
+
# Use Bloch-Wigner dilogarithm (most accurate and fast)
|
| 328 |
+
for (i,j,k) in idx_tris:
|
| 329 |
+
z1 = torch.tensor(z_finite_complex[i], dtype=torch.complex128)
|
| 330 |
+
z2 = torch.tensor(z_finite_complex[j], dtype=torch.complex128)
|
| 331 |
+
z3 = torch.tensor(z_finite_complex[k], dtype=torch.complex128)
|
| 332 |
+
total += triangle_volume_bloch_wigner(z1, z2, z3).item()
|
| 333 |
+
else:
|
| 334 |
+
# Use Lobachevsky function (series or exact)
|
| 335 |
+
for (i,j,k) in idx_tris:
|
| 336 |
+
z1, z2, z3 = z_finite_complex[i], z_finite_complex[j], z_finite_complex[k]
|
| 337 |
+
total += triangle_volume_from_points(z1, z2, z3, mode=mode, series_terms=series_terms, dps=dps)
|
| 338 |
+
|
| 339 |
return total
|
results/data/9vertex_optimal_for_llm_test.json
CHANGED
|
@@ -1,3 +1,3 @@
|
|
| 1 |
version https://git-lfs.github.com/spec/v1
|
| 2 |
-
oid sha256:
|
| 3 |
-
size
|
|
|
|
| 1 |
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:0eed32f8c44a298fce4d90b50bac935a636ea379e32d101a51c487b178197e25
|
| 3 |
+
size 1608
|