| import argparse |
| import numpy as np |
|
|
| def get_dictionary(dim, dictionary_size, seed): |
| """Procedurally generate a normalized dictionary matrix using deterministic PRNG seed.""" |
| rng = np.random.RandomState(seed) |
| dict_mat = rng.standard_normal((dim, dictionary_size)).astype(np.float32) |
| norms = np.linalg.norm(dict_mat, axis=0, keepdims=True) + 1e-9 |
| return dict_mat / norms |
|
|
| def sparse_matching_pursuit(W, u_dict, v_dict, rank): |
| """Compresses W by projecting onto u_dict and v_dict up to a given rank.""" |
| W_residual = W.copy() |
| projections = [] |
| |
| for r in range(rank): |
| |
| |
| |
| corr_matrix = np.dot(u_dict.T, np.dot(W_residual, v_dict)) |
| |
| |
| idx_u, idx_v = np.unravel_index(np.argmax(np.abs(corr_matrix)), corr_matrix.shape) |
| coeff = corr_matrix[idx_u, idx_v] |
| |
| |
| projections.append((idx_u, idx_v, coeff)) |
| |
| |
| outer_prod = np.outer(u_dict[:, idx_u], v_dict[:, idx_v]) |
| W_residual -= coeff * outer_prod |
| |
| return projections |
|
|
| def reconstruct_matrix(projections, u_dict, v_dict, m, n): |
| """Reconstructs the weight matrix from sparse projections and dictionaries.""" |
| W_rec = np.zeros((m, n), dtype=np.float32) |
| for idx_u, idx_v, coeff in projections: |
| W_rec += coeff * np.outer(u_dict[:, idx_u], v_dict[:, idx_v]) |
| return W_rec |
|
|
| def run_proof(): |
| print("======================================================================") |
| print("ZYMATICA | Genesis Protocol: Procedural Seed Reconstruction Proof") |
| print("======================================================================\n") |
|
|
| M, N = 64, 64 |
| DICT_SIZE = 128 |
| RANK = 4 |
| MASTER_SEED = 42 |
|
|
| print(f"[1] Generating Mock Layer Weight Matrix W ({M}x{N} floats)...") |
| |
| rng = np.random.RandomState(MASTER_SEED) |
| W_true = rng.standard_normal((M, N)).astype(np.float32) |
| |
| U_true = rng.standard_normal((M, 4)) |
| V_true = rng.standard_normal((N, 4)) |
| W_true = np.dot(U_true, V_true.T) + 0.1 * rng.standard_normal((M, N)) |
| |
| raw_size_bytes = W_true.nbytes |
| print(f" -> Size of raw weights matrix W: {raw_size_bytes} bytes ({raw_size_bytes / 1024:.2f} KB)") |
|
|
| print(f"\n[2] Instantiating Procedural Dictionaries (Seed={MASTER_SEED}, DictSize={DICT_SIZE})...") |
| u_dict = get_dictionary(M, DICT_SIZE, MASTER_SEED) |
| v_dict = get_dictionary(N, DICT_SIZE, MASTER_SEED + 500) |
| print(f" -> Generated U_dict shape: {u_dict.shape}") |
| print(f" -> Generated V_dict shape: {v_dict.shape}") |
|
|
| print(f"\n[3] Compiling Weight Matrix into Sparse Trajectories (Rank={RANK})...") |
| projections = sparse_matching_pursuit(W_true, u_dict, v_dict, RANK) |
| |
| |
| |
| compressed_bytes = RANK * 4 |
| compression_ratio = raw_size_bytes / compressed_bytes |
| print(f" Sparse Projections:") |
| for r, (iu, iv, val) in enumerate(projections): |
| print(f" Rank {r+1}: U_idx={iu:3d}, V_idx={iv:3d}, Coefficient={val:.4f}") |
| print(f" -> Compressed Payload Size: {compressed_bytes} bytes") |
| print(f" -> Compression Ratio: {compression_ratio:.2f}x") |
|
|
| print("\n[4] Executing Edge Reconstructor (Procedural Inflation)...") |
| W_rec = reconstruct_matrix(projections, u_dict, v_dict, M, N) |
| |
| mse = np.mean((W_true - W_rec) ** 2) |
| cosine_sim = np.dot(W_true.flatten(), W_rec.flatten()) / (np.linalg.norm(W_true) * np.linalg.norm(W_rec) + 1e-9) |
| |
| print(f" - Reconstruction Mean Squared Error (MSE): {mse:.6f}") |
| print(f" - Cosine Similarity (Fidelity Index): {cosine_sim * 100:.2f}%") |
| |
| print("\n[VERIFICATION] Deterministic procedural morphogenesis completed successfully.") |
|
|
| if __name__ == "__main__": |
| parser = argparse.ArgumentParser(description="Zymatica Genesis Protocol Proof") |
| parser.add_argument("--test", action="store_true", help="Run test mode") |
| args = parser.parse_args() |
| run_proof() |
|
|