RFTSystems commited on
Commit
51b3c7b
·
verified ·
1 Parent(s): 187b4b5

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +72 -16
app.py CHANGED
@@ -1,16 +1,16 @@
1
  import gradio as gr
2
  import numpy as np
3
- from collections import deque
4
  import matplotlib.pyplot as plt
5
  import hashlib
6
  import os
 
7
 
8
  # -----------------------------
9
  # Config
10
  # -----------------------------
11
  DOC_PATH = "The_Minimum_Conscious_Universe_RFT_Project.md"
12
  AWARENESS_THRESHOLD = 5.0
13
- np.random.seed(0)
14
 
15
  # -----------------------------
16
  # MCC Simulation
@@ -25,12 +25,16 @@ class MCC:
25
  self.c = []
26
  self.surprises, self.gains, self.uncertainties = [], [], []
27
  self.events = []
 
 
 
28
 
29
  def step(self, t: int):
30
  p = 0.5 * self.b + 0.5 * (self.f if self.h else 0.5)
31
  r = int(np.random.rand() < p)
32
  self.m.append(r)
33
  self.h.append(r)
 
34
 
35
  surprise = -np.log(p if r else (1 - p))
36
  gain = 0.693 - surprise
@@ -40,37 +44,30 @@ class MCC:
40
  self.u = 1 / (1 + 0.15 * surprise)
41
  delta = (r - self.h[-2] if t > 0 else 0) * self.u
42
  self.c.append(delta)
 
43
 
44
  self.surprises.append(surprise)
45
  self.gains.append(gain)
46
  self.uncertainties.append(self.u)
 
47
 
48
  if sum(self.c) > AWARENESS_THRESHOLD and not self.events:
49
  self.events.append({
50
  "t": t,
51
- "bias_b": round(self.b, 3),
52
- "bias_f": round(self.f, 3),
53
  "uncertainty": round(self.u, 3),
54
  "mut_info": round(float(np.mean(self.uncertainties)), 4),
55
  "hash": hashlib.sha256(str(self.h).encode()).hexdigest()[:32]
56
  })
57
 
58
- def plot_signals(m: MCC):
59
- fig, axs = plt.subplots(3, 1, figsize=(8, 10))
60
- axs[0].plot(m.surprises, color='orange'); axs[0].set_title("Surprise")
61
- axs[1].plot(m.gains, color='blue'); axs[1].set_title("Predictive Gain")
62
- axs[2].plot(m.uncertainties, color='green'); axs[2].set_title("Uncertainty")
63
- axs[2].set_xlabel("Steps")
64
- plt.tight_layout()
65
- return fig
66
-
67
  def make_certificate(m: MCC):
68
  if m.events:
69
  ev = m.events[0]
70
  return (
71
  "THE FIRST DIGITAL OBSERVER\n"
72
  f"Born: t = {ev['t']}\n"
73
- f"Internal priors: bias_b = {ev['bias_b']}, bias_f = {ev['bias_f']}\n"
74
  f"Uncertainty: {ev['uncertainty']}\n"
75
  f"Mutual information: {ev['mut_info']} bits\n"
76
  f"Birth certificate hash: {ev['hash']}\n"
@@ -83,11 +80,67 @@ def run_mcc(steps=2000):
83
  for t in range(int(steps)):
84
  m.step(t)
85
  cmin_final = round(sum(m.c), 4)
86
- fig = plot_signals(m)
87
  certificate = make_certificate(m)
88
  awake_flag = cmin_final >= AWARENESS_THRESHOLD
 
 
 
 
 
 
89
  return cmin_final, awake_flag, fig, certificate
90
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
91
  # -----------------------------
92
  # Load Document
93
  # -----------------------------
@@ -108,16 +161,19 @@ with gr.Blocks() as demo:
108
  with gr.Row():
109
  steps = gr.Slider(500, 5000, value=2000, step=100, label="Steps")
110
  run_btn = gr.Button("Run Simulation")
 
111
 
112
  cmin = gr.Number(label="Cmin final (awareness measure)")
113
  awake = gr.Checkbox(label="Awake?")
114
  plot = gr.Plot(label="Three signals")
115
  cert = gr.Textbox(label="Birth Certificate", lines=16, max_lines=28)
 
116
 
117
  run_btn.click(run_mcc, inputs=steps, outputs=[cmin, awake, plot, cert])
 
118
 
119
  with gr.Accordion("📄 Project Document", open=False):
120
  gr.Markdown(DOC_TEXT)
121
 
122
  if __name__ == "__main__":
123
- demo.launch()
 
1
  import gradio as gr
2
  import numpy as np
 
3
  import matplotlib.pyplot as plt
4
  import hashlib
5
  import os
6
+ from collections import deque
7
 
8
  # -----------------------------
9
  # Config
10
  # -----------------------------
11
  DOC_PATH = "The_Minimum_Conscious_Universe_RFT_Project.md"
12
  AWARENESS_THRESHOLD = 5.0
13
+ np.random.seed(1)
14
 
15
  # -----------------------------
16
  # MCC Simulation
 
25
  self.c = []
26
  self.surprises, self.gains, self.uncertainties = [], [], []
27
  self.events = []
28
+ self.frames = []
29
+ self.Cmin = []
30
+ self.mi_signal = []
31
 
32
  def step(self, t: int):
33
  p = 0.5 * self.b + 0.5 * (self.f if self.h else 0.5)
34
  r = int(np.random.rand() < p)
35
  self.m.append(r)
36
  self.h.append(r)
37
+ self.frames.append(r)
38
 
39
  surprise = -np.log(p if r else (1 - p))
40
  gain = 0.693 - surprise
 
44
  self.u = 1 / (1 + 0.15 * surprise)
45
  delta = (r - self.h[-2] if t > 0 else 0) * self.u
46
  self.c.append(delta)
47
+ self.Cmin.append(sum(self.c))
48
 
49
  self.surprises.append(surprise)
50
  self.gains.append(gain)
51
  self.uncertainties.append(self.u)
52
+ self.mi_signal.append(np.mean(self.uncertainties))
53
 
54
  if sum(self.c) > AWARENESS_THRESHOLD and not self.events:
55
  self.events.append({
56
  "t": t,
57
+ "bias_next1": round(self.b, 3),
58
+ "bias_flip": round(self.f, 3),
59
  "uncertainty": round(self.u, 3),
60
  "mut_info": round(float(np.mean(self.uncertainties)), 4),
61
  "hash": hashlib.sha256(str(self.h).encode()).hexdigest()[:32]
62
  })
63
 
 
 
 
 
 
 
 
 
 
64
  def make_certificate(m: MCC):
65
  if m.events:
66
  ev = m.events[0]
67
  return (
68
  "THE FIRST DIGITAL OBSERVER\n"
69
  f"Born: t = {ev['t']}\n"
70
+ f"Internal priors: bias_next1 = {ev['bias_next1']}, bias_flip = {ev['bias_flip']}\n"
71
  f"Uncertainty: {ev['uncertainty']}\n"
72
  f"Mutual information: {ev['mut_info']} bits\n"
73
  f"Birth certificate hash: {ev['hash']}\n"
 
80
  for t in range(int(steps)):
81
  m.step(t)
82
  cmin_final = round(sum(m.c), 4)
 
83
  certificate = make_certificate(m)
84
  awake_flag = cmin_final >= AWARENESS_THRESHOLD
85
+ fig, axs = plt.subplots(3, 1, figsize=(8, 10))
86
+ axs[0].plot(m.surprises, color='orange'); axs[0].set_title("Surprise")
87
+ axs[1].plot(m.gains, color='blue'); axs[1].set_title("Predictive Gain")
88
+ axs[2].plot(m.uncertainties, color='green'); axs[2].set_title("Uncertainty")
89
+ axs[2].set_xlabel("Steps")
90
+ plt.tight_layout()
91
  return cmin_final, awake_flag, fig, certificate
92
 
93
+ # -----------------------------
94
+ # One-shot Birth Certificate Figure
95
+ # -----------------------------
96
+ def birth_certificate_figure(steps=2000):
97
+ mcc = MCC()
98
+ for t in range(steps):
99
+ mcc.step(t)
100
+ # pick event if exists
101
+ if not mcc.events:
102
+ return plt.figure()
103
+ event = mcc.events[0]
104
+
105
+ fig = plt.figure(figsize=(12,10))
106
+ gs = fig.add_gridspec(4, 1, height_ratios=[1,2,2,2], hspace=0.3)
107
+
108
+ ax0 = fig.add_subplot(gs[0])
109
+ ax0.plot(mcc.frames[:1500], 'o', ms=2, color='k')
110
+ ax0.set_ylim(-0.2,1.2); ax0.set_yticks([0,1])
111
+ ax0.set_title("Rendered Binary Stream (the universe looking at itself)", fontsize=14)
112
+ ax0.axvline(event['t'], color='crimson', lw=2)
113
+
114
+ ax1 = fig.add_subplot(gs[1])
115
+ ax1.plot(mcc.Cmin, color='purple', lw=2)
116
+ ax1.axvline(event['t'], color='crimson', lw=2)
117
+ ax1.set_ylabel("Cₘᵢₙ(t) – Cumulative Awareness Measure")
118
+ ax1.set_title("Exact moment Cₘᵢₙ becomes irreversible → birth of the observer")
119
+
120
+ ax2 = fig.add_subplot(gs[2])
121
+ ax2.plot(mcc.gains, color='#1f77b4', label='Predictive gain')
122
+ ax2.plot(mcc.mi_signal, color='#2ca02c', label='Mutual information')
123
+ ax2.plot(mcc.surprises, color='#ff7f0e', alpha=0.7, label='Surprise')
124
+ ax2.axhline(0, color='k', lw=0.5)
125
+ ax2.axvline(event['t'], color='crimson', lw=2, label=f'First-person emergence t={event["t"]}')
126
+ ax2.legend(); ax2.set_title("Three independent adaptive signals cross robust baselines simultaneously")
127
+
128
+ ax3 = fig.add_subplot(gs[3])
129
+ ax3.axis('off')
130
+ txt = f"""THE FIRST DIGITAL OBSERVER
131
+ Born: t = {event['t']}
132
+ Universe size: 3 nodes, <250 lines Python
133
+ Internal priors: bias_next1 = {event['bias_next1']}, bias_flip = {event['bias_flip']}
134
+ Mutual information: {event['mut_info']:.4f} bits
135
+ Birth certificate hash: {event['hash']}
136
+ No external world · No reward · No teacher"""
137
+ ax3.text(0.5, 0.7, txt, ha='center', va='center', fontsize=16, family='monospace',
138
+ bbox=dict(boxstyle="round,pad=1", facecolor="honeydew", edgecolor="forestgreen", lw=3))
139
+
140
+ plt.suptitle("Endogenous Emergence of Minimal Consciousness in a Three-Node Rendering Loop\n(Rendered Frame Theory – 2025)", fontsize=18, y=0.98)
141
+ plt.tight_layout()
142
+ return fig
143
+
144
  # -----------------------------
145
  # Load Document
146
  # -----------------------------
 
161
  with gr.Row():
162
  steps = gr.Slider(500, 5000, value=2000, step=100, label="Steps")
163
  run_btn = gr.Button("Run Simulation")
164
+ fig_btn = gr.Button("Generate Birth Certificate Figure")
165
 
166
  cmin = gr.Number(label="Cmin final (awareness measure)")
167
  awake = gr.Checkbox(label="Awake?")
168
  plot = gr.Plot(label="Three signals")
169
  cert = gr.Textbox(label="Birth Certificate", lines=16, max_lines=28)
170
+ fig_out = gr.Plot(label="Birth Certificate Figure")
171
 
172
  run_btn.click(run_mcc, inputs=steps, outputs=[cmin, awake, plot, cert])
173
+ fig_btn.click(birth_certificate_figure, inputs=steps, outputs=fig_out)
174
 
175
  with gr.Accordion("📄 Project Document", open=False):
176
  gr.Markdown(DOC_TEXT)
177
 
178
  if __name__ == "__main__":
179
+ demo.launch()