Spaces:
Sleeping
Sleeping
Upload 6 files
Browse files- .gitattributes +2 -0
- README.md +57 -0
- app.py +137 -0
- assets/interference_diagram.png +3 -0
- assets/loss_curve.png +3 -0
- model.py +70 -0
- requirements.txt +3 -0
.gitattributes
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
|
|
|
| 1 |
+
assets/interference_diagram.png filter=lfs diff=lfs merge=lfs -text
|
| 2 |
+
assets/loss_curve.png filter=lfs diff=lfs merge=lfs -text
|
README.md
ADDED
|
@@ -0,0 +1,57 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
---
|
| 2 |
+
title: OmegaCode — Holographic Master Code Demo
|
| 3 |
+
emoji: 🧬
|
| 4 |
+
colorFrom: indigo
|
| 5 |
+
colorTo: purple
|
| 6 |
+
sdk: gradio
|
| 7 |
+
app_file: app.py
|
| 8 |
+
pinned: false
|
| 9 |
+
license: mit
|
| 10 |
+
---
|
| 11 |
+
|
| 12 |
+
# OmegaCode — Holographic Master Code Demo
|
| 13 |
+
|
| 14 |
+
A research-oriented, physics-inspired neural prototype with an α-sensitive stability control and interference-based visualization.
|
| 15 |
+
|
| 16 |
+
## Live visual summary
|
| 17 |
+
|
| 18 |
+

|
| 19 |
+
|
| 20 |
+

|
| 21 |
+
|
| 22 |
+
## What this Space shows
|
| 23 |
+
|
| 24 |
+
- a lightweight **Master Code Ψ** prototype
|
| 25 |
+
- an **effective α parameter** that modulates phase and stability
|
| 26 |
+
- a **training-loss visualization** that changes near the nominal α value
|
| 27 |
+
- a **double-slit analogue** showing how phase coherence affects interference visibility
|
| 28 |
+
|
| 29 |
+
## How to use the demo
|
| 30 |
+
|
| 31 |
+
Move the **α slider** and compare:
|
| 32 |
+
|
| 33 |
+
- the training curve
|
| 34 |
+
- the interference pattern
|
| 35 |
+
- the model diagnostics panel
|
| 36 |
+
|
| 37 |
+
The demo updates interactively when you change **α**, epoch count, or input noise.
|
| 38 |
+
|
| 39 |
+
## Important note
|
| 40 |
+
|
| 41 |
+
This is an **experimental research prototype** and not a validated physical theory.
|
| 42 |
+
It is designed as a conceptual, physics-inspired demo for learning and exploration.
|
| 43 |
+
|
| 44 |
+
## How to run locally
|
| 45 |
+
|
| 46 |
+
```bash
|
| 47 |
+
pip install -r requirements.txt
|
| 48 |
+
python app.py
|
| 49 |
+
```
|
| 50 |
+
|
| 51 |
+
## Files
|
| 52 |
+
|
| 53 |
+
- `app.py` — Gradio interface with interactive α control
|
| 54 |
+
- `model.py` — lightweight demo model and synthetic curves
|
| 55 |
+
- `assets/loss_curve.png` — static visualization for the README
|
| 56 |
+
- `assets/interference_diagram.png` — double-slit analogue for the README
|
| 57 |
+
- `requirements.txt` — dependencies
|
app.py
ADDED
|
@@ -0,0 +1,137 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from __future__ import annotations
|
| 2 |
+
|
| 3 |
+
import numpy as np
|
| 4 |
+
import gradio as gr
|
| 5 |
+
import matplotlib.pyplot as plt
|
| 6 |
+
|
| 7 |
+
from model import HolographicMasterCodeTransformer, synthetic_loss_curve, alpha_to_label
|
| 8 |
+
|
| 9 |
+
|
| 10 |
+
def build_training_figure(alpha_value: float, epochs: int):
|
| 11 |
+
nominal_losses, nominal_regs = synthetic_loss_curve(1 / 137.035, epochs=epochs)
|
| 12 |
+
current_losses, current_regs = synthetic_loss_curve(alpha_value, epochs=epochs)
|
| 13 |
+
|
| 14 |
+
fig, ax = plt.subplots(figsize=(10, 5))
|
| 15 |
+
ax.plot(nominal_losses, label="Loss — nominal α", linewidth=2.2)
|
| 16 |
+
ax.plot(current_losses, label="Loss — selected α", linewidth=2.2)
|
| 17 |
+
ax.plot(nominal_regs, label="Reg — nominal α", linestyle="--")
|
| 18 |
+
ax.plot(current_regs, label="Reg — selected α", linestyle="--")
|
| 19 |
+
ax.set_title("OmegaCode training dynamics")
|
| 20 |
+
ax.set_xlabel("Epoch")
|
| 21 |
+
ax.set_ylabel("Value")
|
| 22 |
+
ax.grid(True, alpha=0.25)
|
| 23 |
+
ax.legend(loc="upper right")
|
| 24 |
+
fig.tight_layout()
|
| 25 |
+
return fig
|
| 26 |
+
|
| 27 |
+
|
| 28 |
+
def build_interference_figure(alpha_value: float):
|
| 29 |
+
x = np.linspace(-10, 10, 1200)
|
| 30 |
+
alpha_0 = 1 / 137.035
|
| 31 |
+
delta = alpha_value - alpha_0
|
| 32 |
+
|
| 33 |
+
# Coherence and phase shift are synthetic and only for visualization.
|
| 34 |
+
visibility = float(np.exp(-25000.0 * abs(delta)))
|
| 35 |
+
visibility = max(0.08, min(0.98, visibility))
|
| 36 |
+
phase = float(0.9 * np.sign(delta) * min(1.0, abs(delta) * 5e4))
|
| 37 |
+
|
| 38 |
+
coherent = 1.0 + 0.95 * np.cos(1.15 * x)
|
| 39 |
+
perturbed = 1.0 + visibility * np.cos(1.15 * x + phase)
|
| 40 |
+
|
| 41 |
+
fig, ax = plt.subplots(figsize=(10, 5))
|
| 42 |
+
ax.plot(x, coherent, label="Nominal α: coherent pattern", linewidth=2.2)
|
| 43 |
+
ax.plot(x, perturbed, label="Selected α: phase-modulated pattern", linewidth=2.2)
|
| 44 |
+
ax.set_title("Double-slit analogue: interference visibility vs α")
|
| 45 |
+
ax.set_xlabel("Screen coordinate")
|
| 46 |
+
ax.set_ylabel("Normalized intensity")
|
| 47 |
+
ax.grid(True, alpha=0.25)
|
| 48 |
+
ax.legend(loc="upper right")
|
| 49 |
+
fig.tight_layout()
|
| 50 |
+
return fig
|
| 51 |
+
|
| 52 |
+
|
| 53 |
+
def run_demo(alpha_value: float, epochs: int, noise: float):
|
| 54 |
+
model = HolographicMasterCodeTransformer()
|
| 55 |
+
|
| 56 |
+
x = np.random.randn(1, 8).astype(np.float32) * max(noise, 1e-6)
|
| 57 |
+
pred, psi, security, delta_phi = model.forward(x, alpha_value)
|
| 58 |
+
|
| 59 |
+
training_fig = build_training_figure(alpha_value, epochs)
|
| 60 |
+
interference_fig = build_interference_figure(alpha_value)
|
| 61 |
+
|
| 62 |
+
alpha_label = alpha_to_label(alpha_value)
|
| 63 |
+
alpha_0 = model.alpha_0
|
| 64 |
+
delta_alpha = alpha_value - alpha_0
|
| 65 |
+
|
| 66 |
+
summary = {
|
| 67 |
+
"alpha": alpha_value,
|
| 68 |
+
"alpha_label": alpha_label,
|
| 69 |
+
"delta_alpha": delta_alpha,
|
| 70 |
+
"prediction": float(pred.squeeze()),
|
| 71 |
+
"psi_mean": float(np.mean(psi)),
|
| 72 |
+
"security_factor": float(security),
|
| 73 |
+
"phase_shift": float(delta_phi),
|
| 74 |
+
"stability_score": float(max(0.0, 1.0 - abs(delta_alpha) * 5e4)),
|
| 75 |
+
}
|
| 76 |
+
|
| 77 |
+
return training_fig, interference_fig, summary
|
| 78 |
+
|
| 79 |
+
|
| 80 |
+
with gr.Blocks(title="OmegaCode Holographic Demo") as demo:
|
| 81 |
+
gr.Markdown(
|
| 82 |
+
"""
|
| 83 |
+
# OmegaCode — Holographic Master Code Demo
|
| 84 |
+
|
| 85 |
+
A research-oriented, physics-inspired neural prototype with an α-sensitive stability control and interference-based visualization.
|
| 86 |
+
It is designed for exploration and does **not** claim to be a validated physical theory.
|
| 87 |
+
|
| 88 |
+
## What to try
|
| 89 |
+
|
| 90 |
+
- Move **α** around the nominal value
|
| 91 |
+
- Watch the **loss curve** shift
|
| 92 |
+
- Compare the **double-slit analogue** as phase coherence changes
|
| 93 |
+
"""
|
| 94 |
+
)
|
| 95 |
+
|
| 96 |
+
with gr.Row():
|
| 97 |
+
alpha_value = gr.Slider(
|
| 98 |
+
minimum=1 / 137.08,
|
| 99 |
+
maximum=1 / 137.00,
|
| 100 |
+
value=1 / 137.035,
|
| 101 |
+
step=1e-7,
|
| 102 |
+
label="α / Fine-structure constant (effective control parameter)",
|
| 103 |
+
)
|
| 104 |
+
epochs = gr.Slider(50, 300, value=150, step=10, label="Simulated epochs")
|
| 105 |
+
noise = gr.Slider(0.0, 2.0, value=1.0, step=0.05, label="Input noise")
|
| 106 |
+
|
| 107 |
+
run_btn = gr.Button("Run simulation", variant="primary")
|
| 108 |
+
|
| 109 |
+
with gr.Row():
|
| 110 |
+
training_plot = gr.Plot(label="Training dynamics")
|
| 111 |
+
interference_plot = gr.Plot(label="Interference pattern")
|
| 112 |
+
|
| 113 |
+
out = gr.JSON(label="Model diagnostics")
|
| 114 |
+
|
| 115 |
+
run_btn.click(
|
| 116 |
+
run_demo,
|
| 117 |
+
inputs=[alpha_value, epochs, noise],
|
| 118 |
+
outputs=[training_plot, interference_plot, out],
|
| 119 |
+
)
|
| 120 |
+
alpha_value.change(
|
| 121 |
+
run_demo,
|
| 122 |
+
inputs=[alpha_value, epochs, noise],
|
| 123 |
+
outputs=[training_plot, interference_plot, out],
|
| 124 |
+
)
|
| 125 |
+
epochs.change(
|
| 126 |
+
run_demo,
|
| 127 |
+
inputs=[alpha_value, epochs, noise],
|
| 128 |
+
outputs=[training_plot, interference_plot, out],
|
| 129 |
+
)
|
| 130 |
+
noise.change(
|
| 131 |
+
run_demo,
|
| 132 |
+
inputs=[alpha_value, epochs, noise],
|
| 133 |
+
outputs=[training_plot, interference_plot, out],
|
| 134 |
+
)
|
| 135 |
+
|
| 136 |
+
if __name__ == "__main__":
|
| 137 |
+
demo.launch()
|
assets/interference_diagram.png
ADDED
|
Git LFS Details
|
assets/loss_curve.png
ADDED
|
Git LFS Details
|
model.py
ADDED
|
@@ -0,0 +1,70 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from __future__ import annotations
|
| 2 |
+
|
| 3 |
+
from dataclasses import dataclass
|
| 4 |
+
import numpy as np
|
| 5 |
+
|
| 6 |
+
|
| 7 |
+
@dataclass
|
| 8 |
+
class OmegaConfig:
|
| 9 |
+
alpha_0: float = 1 / 137.035
|
| 10 |
+
phase_scale: float = 800.0
|
| 11 |
+
security_scale: float = 300.0
|
| 12 |
+
n_harmonics: int = 4
|
| 13 |
+
|
| 14 |
+
|
| 15 |
+
def alpha_to_label(alpha: float) -> str:
|
| 16 |
+
alpha_0 = 1 / 137.035
|
| 17 |
+
alpha_physical = 1 / 137.035999
|
| 18 |
+
if abs(alpha - alpha_0) < 5e-7:
|
| 19 |
+
return "Nominal"
|
| 20 |
+
if abs(alpha - alpha_physical) < 5e-7:
|
| 21 |
+
return "Physical"
|
| 22 |
+
return "Perturbed"
|
| 23 |
+
|
| 24 |
+
|
| 25 |
+
class HolographicMasterCodeTransformer:
|
| 26 |
+
"""
|
| 27 |
+
Lightweight physics-inspired model for demo use.
|
| 28 |
+
It is intentionally simple so it runs fast inside a Hugging Face Space.
|
| 29 |
+
"""
|
| 30 |
+
|
| 31 |
+
def __init__(self, config: OmegaConfig | None = None):
|
| 32 |
+
self.cfg = config or OmegaConfig()
|
| 33 |
+
self.alpha_0 = self.cfg.alpha_0
|
| 34 |
+
rng = np.random.default_rng(42)
|
| 35 |
+
self.harmonic_weights = rng.normal(size=(self.cfg.n_harmonics, 8)).astype(np.float32)
|
| 36 |
+
|
| 37 |
+
def forward(self, x: np.ndarray, alpha: float):
|
| 38 |
+
x = np.asarray(x, dtype=np.float32)
|
| 39 |
+
h = np.tanh(x @ np.eye(x.shape[-1], dtype=np.float32))
|
| 40 |
+
|
| 41 |
+
delta_phi = 2 * np.pi * (alpha - self.alpha_0) * self.cfg.phase_scale
|
| 42 |
+
security = float(np.exp(-self.cfg.security_scale * abs(alpha - self.alpha_0)))
|
| 43 |
+
|
| 44 |
+
psi = np.zeros_like(h)
|
| 45 |
+
for n in range(self.cfg.n_harmonics):
|
| 46 |
+
psi += self.harmonic_weights[n] * np.cos(h * (n + 1) + delta_phi * (n + 1))
|
| 47 |
+
|
| 48 |
+
combined = h + 0.35 * psi * security
|
| 49 |
+
pred = combined.mean(axis=-1, keepdims=True)
|
| 50 |
+
|
| 51 |
+
return pred, psi, security, delta_phi
|
| 52 |
+
|
| 53 |
+
|
| 54 |
+
def synthetic_loss_curve(alpha_value: float, epochs: int = 150):
|
| 55 |
+
"""
|
| 56 |
+
Simulates a smooth loss curve. Near alpha_0, the curve is slightly better.
|
| 57 |
+
This is for visualization only; it is not a training result.
|
| 58 |
+
"""
|
| 59 |
+
cfg = OmegaConfig()
|
| 60 |
+
alpha_dev = abs(alpha_value - cfg.alpha_0)
|
| 61 |
+
alpha_quality = np.exp(-25000.0 * alpha_dev)
|
| 62 |
+
|
| 63 |
+
t = np.arange(epochs, dtype=np.float32)
|
| 64 |
+
base = 0.65 * np.exp(-t / (epochs / 5.0)) + 0.03
|
| 65 |
+
oscillation = 0.02 * np.sin(t / 8.0) * (1.0 - 0.7 * alpha_quality)
|
| 66 |
+
noise = 0.005 * np.exp(-t / (epochs / 3.0))
|
| 67 |
+
|
| 68 |
+
losses = np.maximum(0.0, base + oscillation + noise * (1.0 - alpha_quality))
|
| 69 |
+
regs = 0.12 * np.exp(-t / (epochs / 2.0)) + 0.02 * (1.0 - alpha_quality)
|
| 70 |
+
return losses, regs
|
requirements.txt
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
gradio>=4.44.0
|
| 2 |
+
numpy>=1.26.0
|
| 3 |
+
matplotlib>=3.8.0
|