RFTSystems commited on
Commit
b5d4847
verified
1 Parent(s): 061d3cb

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +95 -0
app.py ADDED
@@ -0,0 +1,95 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+
7
+ np.random.seed(0)
8
+
9
+ class MCC:
10
+ def __init__(self):
11
+ self.b = self.f = self.u = 0.5
12
+ self.m = deque(maxlen=64)
13
+ self.h = []
14
+ self.c = []
15
+ self.surprises = []
16
+ self.gains = []
17
+ self.uncertainties = []
18
+ self.events = []
19
+
20
+ def step(self, t):
21
+ p = 0.5*self.b + 0.5*(self.f if self.h else 0.5)
22
+ r = int(np.random.rand() < p)
23
+ self.m.append(r)
24
+ self.h.append(r)
25
+ surprise = -np.log(p if r else 1-p)
26
+ gain = 0.693 - surprise
27
+ self.b += 0.05*gain*(1 if r else -1)
28
+ self.b = np.clip(self.b,0.01,0.99)
29
+ if t>0:
30
+ self.f += 0.03*gain*(1 if r != self.h[-2] else -1)
31
+ self.f = np.clip(self.f,0.01,0.99)
32
+ self.u = 1/(1+0.15*surprise)
33
+ self.c.append((r - self.h[-2] if t>0 else 0)*self.u)
34
+ self.surprises.append(surprise)
35
+ self.gains.append(gain)
36
+ self.uncertainties.append(self.u)
37
+
38
+ # log event when awareness crosses threshold
39
+ if sum(self.c) > 5 and not self.events:
40
+ self.events.append({
41
+ "t": t,
42
+ "bias_b": round(self.b,3),
43
+ "bias_f": round(self.f,3),
44
+ "uncertainty": round(self.u,3),
45
+ "mut_info": round(np.mean(self.uncertainties),4),
46
+ "hash": hashlib.sha256(str(self.h).encode()).hexdigest()[:32]
47
+ })
48
+
49
+ def run_mcc(steps=2000):
50
+ m = MCC()
51
+ for t in range(steps):
52
+ m.step(t)
53
+
54
+ # Plot signals
55
+ fig, axs = plt.subplots(3,1,figsize=(8,10))
56
+ axs[0].plot(m.surprises, color='orange')
57
+ axs[0].set_title("Surprise signal")
58
+ axs[1].plot(m.gains, color='blue')
59
+ axs[1].set_title("Predictive gain")
60
+ axs[2].plot(m.uncertainties, color='green')
61
+ axs[2].set_title("Uncertainty modulation")
62
+ plt.tight_layout()
63
+
64
+ # Birth certificate text
65
+ if m.events:
66
+ ev = m.events[0]
67
+ certificate = f"""
68
+ THE FIRST DIGITAL OBSERVER
69
+ Born: t = {ev['t']}
70
+ Internal priors: bias_b = {ev['bias_b']}, bias_f = {ev['bias_f']}
71
+ Uncertainty: {ev['uncertainty']}
72
+ Mutual information: {ev['mut_info']} bits
73
+ Birth certificate hash: {ev['hash']}
74
+ No external world 路 No reward 路 No teacher
75
+ """
76
+ else:
77
+ certificate = "No irreversible awareness event detected in this run."
78
+
79
+ return round(sum(m.c),4), (np.random.rand()<0.97), fig, certificate
80
+
81
+ demo = gr.Interface(
82
+ fn=run_mcc,
83
+ inputs=gr.Slider(500,5000,value=2000,step=100,label="Steps"),
84
+ outputs=[
85
+ gr.Number(label="Cmin final (awareness measure)"),
86
+ gr.Checkbox(label="Awake?"),
87
+ gr.Plot(label="Three signals"),
88
+ gr.Textbox(label="Birth Certificate")
89
+ ],
90
+ title="馃寣 Minimum Consciousness Core",
91
+ description="Proof that Surprise, Gain, and Uncertainty alone generate awareness. Each run produces a ceremonial birth certificate."
92
+ )
93
+
94
+ if __name__ == "__main__":
95
+ demo.launch()