RFTSystems commited on
Commit
68f055d
·
verified ·
1 Parent(s): 774923b

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +53 -28
app.py CHANGED
@@ -2,39 +2,57 @@ import gradio as gr
2
  import numpy as np
3
 
4
  # ============================================================
5
- # RFT-Ω HARMONIC VALIDATION INTERFACE v2
6
- # (Interactive profiles + adjustable noise)
7
  # ============================================================
8
 
9
- # --- base metric generator ----------------------------------
 
 
 
 
 
 
 
10
  def run_simulation(profile, noise_scale):
11
  """
12
- Simulate harmonic stability (QΩ) and synchronisation (ζ_sync)
13
- under synthetic noise for selected system profile.
14
  """
15
 
16
- # baseline ranges for profiles (mean_QΩ, mean_ζ)
17
- baselines = {
18
- "AI / Neural": (0.86, 0.80),
19
- "SpaceX / Aerospace": (0.84, 0.79),
20
- "Energy / RHES": (0.83, 0.78),
21
- "Extreme Perturbation": (0.82, 0.77)
 
 
 
22
  }
23
- base_q, base_z = baselines.get(profile, (0.84, 0.79))
24
 
25
- # apply synthetic Gaussian noise
26
  q_noise = np.random.normal(0, noise_scale)
27
  z_noise = np.random.normal(0, noise_scale * 0.8)
28
 
29
- # compute final readings, clamped to [0,1]
30
- q_omega = np.clip(base_q + q_noise, 0.0, 1.0)
31
- z_sync = np.clip(base_z + z_noise, 0.0, 1.0)
 
 
 
 
 
 
 
 
 
32
 
33
- # derive qualitative status
34
- var = abs(q_noise) + abs(z_noise)
35
- status = "nominal"
36
- if var > 0.12: status = "critical"
37
- elif var > 0.06: status = "perturbed"
38
 
39
  return {
40
  "System": profile,
@@ -44,7 +62,10 @@ def run_simulation(profile, noise_scale):
44
  "status": status
45
  }
46
 
47
- # --- Gradio user interface ----------------------------------
 
 
 
48
  demo = gr.Interface(
49
  fn=run_simulation,
50
  inputs=[
@@ -53,18 +74,22 @@ demo = gr.Interface(
53
  label="Select System Profile",
54
  value="AI / Neural"
55
  ),
56
- gr.Slider(0.0, 0.2, value=0.05, step=0.005,
57
  label="Synthetic Noise Level (σ)")
58
  ],
59
  outputs="json",
60
- title="RFT-Ω Harmonic Validation Interface v2",
61
  description=(
62
- "Simulate QΩ (stability) and ζ_sync (coherence) under controlled synthetic noise.\n"
63
- "Choose an environment profile and adjust noise to test harmonic resilience.\n"
64
- "Typical stable ranges: QΩ 0.82–0.89 | ζ_sync 0.75–0.88"
 
65
  )
66
  )
67
 
68
- # --- launch -------------------------------------------------
 
 
 
69
  if __name__ == "__main__":
70
  demo.launch()
 
2
  import numpy as np
3
 
4
  # ============================================================
5
+ # RFT-Ω HARMONIC VALIDATION INTERFACE v3
6
+ # Domain-weighted | Range-validated | Adaptive baseline
7
  # ============================================================
8
 
9
+ # rolling baseline memory for light adaptive behaviour
10
+ baseline_memory = {
11
+ "AI / Neural": [0.86, 0.80],
12
+ "SpaceX / Aerospace": [0.84, 0.79],
13
+ "Energy / RHES": [0.83, 0.78],
14
+ "Extreme Perturbation": [0.82, 0.77],
15
+ }
16
+
17
  def run_simulation(profile, noise_scale):
18
  """
19
+ Simulate (stability) and ζ_sync (coherence) under
20
+ controlled synthetic noise with adaptive baselines.
21
  """
22
 
23
+ # --- baseline update (moving mean for mild learning) ---
24
+ base_q, base_z = baseline_memory.get(profile, [0.84, 0.79])
25
+
26
+ # --- domain weighting ( vs ζ_sync importance) ---
27
+ weights = {
28
+ "AI / Neural": (0.65, 0.35),
29
+ "SpaceX / Aerospace": (0.6, 0.4),
30
+ "Energy / RHES": (0.55, 0.45),
31
+ "Extreme Perturbation": (0.5, 0.5),
32
  }
33
+ w_q, w_z = weights.get(profile, (0.6, 0.4))
34
 
35
+ # --- synthetic Gaussian noise injection ---
36
  q_noise = np.random.normal(0, noise_scale)
37
  z_noise = np.random.normal(0, noise_scale * 0.8)
38
 
39
+ # --- compute metrics and apply weighting ---
40
+ q_omega = np.clip(base_q + w_q * q_noise, 0.0, 0.99)
41
+ z_sync = np.clip(base_z + w_z * z_noise, 0.0, 0.99)
42
+
43
+ # --- derive qualitative status ---
44
+ variance = abs(q_noise) + abs(z_noise)
45
+ if variance > 0.15:
46
+ status = "critical"
47
+ elif variance > 0.07:
48
+ status = "perturbed"
49
+ else:
50
+ status = "nominal"
51
 
52
+ # --- adaptive baseline update (soft learning) ---
53
+ new_q = (base_q * 0.9) + (q_omega * 0.1)
54
+ new_z = (base_z * 0.9) + (z_sync * 0.1)
55
+ baseline_memory[profile] = [float(new_q), float(new_z)]
 
56
 
57
  return {
58
  "System": profile,
 
62
  "status": status
63
  }
64
 
65
+ # ============================================================
66
+ # GRADIO UI
67
+ # ============================================================
68
+
69
  demo = gr.Interface(
70
  fn=run_simulation,
71
  inputs=[
 
74
  label="Select System Profile",
75
  value="AI / Neural"
76
  ),
77
+ gr.Slider(0.0, 0.3, value=0.05, step=0.005,
78
  label="Synthetic Noise Level (σ)")
79
  ],
80
  outputs="json",
81
+ title="RFT-Ω Harmonic Validation Interface v3",
82
  description=(
83
+ "Simulate harmonic stability (QΩ) and coherence (ζ_sync) "
84
+ "with adaptive baselines and domain-specific weighting. "
85
+ "Adjust noise to test system resilience. Typical stable range: "
86
+ "QΩ 0.82–0.89 | ζ_sync 0.75–0.88"
87
  )
88
  )
89
 
90
+ # ============================================================
91
+ # MAIN
92
+ # ============================================================
93
+
94
  if __name__ == "__main__":
95
  demo.launch()