import numpy as np
import time
np.random.seed(int(time.time()))
# =========================================================
# GLOBAL CONSTANTS
# =========================================================
dtau = 0.01
WINDOW = 20
STEPS = 200
PRINT_INTERVAL = 10
kappa_fast = 1.0
kappa_slow = 0.3
ENTROPY_ALERT = 0.06
OBS_HORIZON = 2.0
# =========================================================
# BLOCK UNIVERSE LAYER
# =========================================================
class Metric:
def proper_time_step(self, v):
return np.sqrt(max(1 - v**2, 0)) * dtau
class Event:
def __init__(self, t, x):
self.t = t
self.x = x
class Manifold:
def __init__(self):
self.dt = 0.02
self.dx = 0.1
self.t_vals = np.arange(0, 20, self.dt)
self.x_vals = np.arange(-10, 10, self.dx)
class ScalarField:
def __init__(self, manifold):
self.values = np.zeros(
(len(manifold.t_vals), len(manifold.x_vals))
)
def evolve(self, entropy_feedback=0.0):
drift = np.sin(time.time()) * 0.001
noise = np.random.normal(
0, 0.004 + entropy_feedback, self.values.shape
)
self.values += drift + noise
def sample(self, ti, xi):
return self.values[ti, xi]
class Worldline:
def __init__(self, x0):
self.t = 0.0
self.x = x0
def step(self, v, metric):
self.t += dtau
self.x += v * dtau
return Event(self.t, self.x), metric.proper_time_step(v)
# =========================================================
# PERCEPTION + BUFFER
# =========================================================
def sensory_map(state):
return state + np.random.normal(0, 0.05)
def now_window(obs):
if len(obs) < WINDOW:
return np.mean(obs)
return np.mean(obs[-WINDOW:])
# =========================================================
# ENTROPY
# =========================================================
def entropy_rate(p_old, p_new):
eps = 1e-9
p_old = np.clip(p_old, eps, 1)
p_new = np.clip(p_new, eps, 1)
return np.sum(p_old * np.log(p_old / p_new))
# =========================================================
# MULTI CLOCK MEMORY
# =========================================================
class Memory:
def __init__(self):
b = np.random.rand()
self.fast_belief = np.array([b, 1 - b])
self.slow_belief = np.array([0.5, 0.5])
self.history = []
def update(self, obs):
likelihood = np.array([1 - obs, obs])
# FAST belief update
f_new = self.fast_belief * likelihood
f_new += np.random.normal(0, 0.01, 2)
f_new = np.clip(f_new, 1e-6, None)
f_new /= np.sum(f_new)
# SLOW belief update (inertia)
s_new = 0.9 * self.slow_belief + 0.1 * f_new
s_new /= np.sum(s_new)
sigma_fast = entropy_rate(self.fast_belief, f_new)
sigma_slow = entropy_rate(self.slow_belief, s_new)
self.fast_belief = f_new
self.slow_belief = s_new
self.history.append((f_new.copy(), s_new.copy()))
return sigma_fast, sigma_slow
# =========================================================
# GUI CLOCKS
# =========================================================
class GUIClock:
def __init__(self, k):
self.t_hat = 0.0
self.k = k
def integrate(self, sigma):
self.t_hat += self.k * sigma
return self.t_hat
# =========================================================
# INITIALIZATION
# =========================================================
metric = Metric()
manifold = Manifold()
field = ScalarField(manifold)
# Two observers
obsA = Worldline(x0=-1.0)
obsB = Worldline(x0=1.5)
memA = Memory()
memB = Memory()
clockA_fast = GUIClock(kappa_fast)
clockA_slow = GUIClock(kappa_slow)
clockB_fast = GUIClock(kappa_fast)
clockB_slow = GUIClock(kappa_slow)
bufferA = []
bufferB = []
tauA = 0.0
tauB = 0.0
entropy_feedback = 0.0
print("\n>>> MULTI OBSERVER TEMPORAL SIMULATION\n")
# =========================================================
# MAIN LOOP
# =========================================================
def sample_obs(event):
if abs(event.x) > OBS_HORIZON:
return None
ti = min(int(event.t / manifold.dt), len(manifold.t_vals) - 1)
xi = min(
int((event.x - manifold.x_vals[0]) / manifold.dx),
len(manifold.x_vals) - 1
)
return field.sample(ti, xi)
for step in range(STEPS):
field.evolve(entropy_feedback)
eA, dA = obsA.step(0.6, metric)
eB, dB = obsB.step(0.4, metric)
tauA += dA
tauB += dB
sA = sample_obs(eA)
sB = sample_obs(eB)
if sA is not None:
bufferA.append(sensory_map(sA))
if sB is not None:
bufferB.append(sensory_map(sB))
if len(bufferA) > 2 and len(bufferB) > 2:
nowA = now_window(bufferA)
nowB = now_window(bufferB)
sigAf, sigAs = memA.update(np.clip(nowA, 0, 1))
sigBf, sigBs = memB.update(np.clip(nowB, 0, 1))
tAf = clockA_fast.integrate(sigAf)
tAs = clockA_slow.integrate(sigAs)
tBf = clockB_fast.integrate(sigBf)
tBs = clockB_slow.integrate(sigBs)
entropy_feedback = (sigAf + sigBf) * 0.05
if step % PRINT_INTERVAL == 0:
print(
f"Step {step:03d} | "
f"τA={tauA:.2f} τB={tauB:.2f} | "
f"A_fast={tAf:.2f} B_fast={tBf:.2f}"
)
if sigAf > ENTROPY_ALERT or sigBf > ENTROPY_ALERT:
print("⚡ PHASE TRANSITION EVENT")
# =========================================================
# SUMMARY
# =========================================================
print("\n===== COMPLETE =====")
print("Observer A GUI fast:", clockA_fast.t_hat)
print("Observer A GUI slow:", clockA_slow.t_hat)
print("Observer B GUI fast:", clockB_fast.t_hat)
print("Observer B GUI slow:", clockB_slow.t_hat)
Comments
Post a Comment