-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathixtal
More file actions
executable file
·74 lines (62 loc) · 2.23 KB
/
ixtal
File metadata and controls
executable file
·74 lines (62 loc) · 2.23 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
#!/usr/bin/env python3
# nexus_resonance.py — small deterministic projection→resonance→reflection sim
import hashlib, time, math, json
from typing import List
# --- vector helpers ---
def dot(u: List[float], v: List[float]) -> float:
return sum(x*y for x,y in zip(u,v))
def norm(u: List[float]) -> float:
return math.sqrt(dot(u,u)) or 1e-12
def normalize(u: List[float]) -> List[float]:
n = norm(u)
return [x / n for x in u]
def add(u,v):
return [x+y for x,y in zip(u,v)]
def scale(u, s):
return [x*s for x in u]
# deterministic hash→vector: hash input (v + t) to pseudo-random small vector
def hash_to_vector(v: List[float], t: int, dim: int):
# build keyed bytes from vector + time
b = json.dumps({'v': v, 't': t}).encode('utf-8')
h = hashlib.sha256(b).digest()
out = []
for i in range(dim):
# take two bytes per entry, signed-like
a = h[(2*i) % len(h)]
b_ = h[(2*i+1) % len(h)]
val = ((a << 8) | b_) - 32768
out.append(val / 32768.0) # in ~[-1,1]
return out
def proj(a,b):
bb = dot(b,b) or 1e-12
factor = dot(a,b)/bb
return scale(b, factor)
def cosine_sim(a,b):
return dot(a,b)/(norm(a)*norm(b))
# --- core iterative map ---
def step(a, b, t, alpha=0.6, beta=0.8, gamma=0.02, eta=0.02):
# projection (emit)
p = proj(a,b)
rho = cosine_sim(a,b)
# reflection with hashed perturbation
h_b = hash_to_vector(b, t, len(b))
b_new = normalize(add(b, add(scale(p, beta), scale(h_b, eta))))
# projection/actor update
p2 = proj(a, b_new)
h_a = hash_to_vector(a, t, len(a))
a_new = normalize(add(a, add(scale(p2, alpha), scale(h_a, gamma))))
return a_new, b_new, rho
# --- demo ---
if __name__ == '__main__':
dim = 8
# initial vectors (arbitrary example)
a = normalize([1.0, 0.2, 0.1, 0.0, 0.0, 0.3, 0.5, 0.1])
b = normalize([0.0, 0.9, 0.1, 0.1, 0.0, 0.0, 0.3, 0.0])
for n in range(1,201):
t = int(time.time()) + n # deterministic-ish rehash over steps
a, b, rho = step(a,b,t)
if n % 10 == 0 or rho > 0.995:
print(f"n={n:03d} rho={rho:.6f} ||a-b||={math.dist(a,b):.6f}")
if rho > 0.9995:
print("== resonant attractor reached ==")
break