| | |
| | |
| | |
| | |
| |
|
| | import numpy as np |
| | import pickle |
| | from sklearn.ensemble import RandomForestClassifier |
| | from sklearn.model_selection import train_test_split |
| | from sklearn.metrics import accuracy_score |
| |
|
| | |
| | |
| | |
| | def particle_step(state: np.ndarray, input_vec: np.ndarray) -> np.ndarray: |
| | |
| | |
| | W = np.sin(np.arange(state.size) + 1.0) |
| | new = np.tanh(state * 0.9 + input_vec.dot(W) * 0.1) |
| | return new |
| | |
| |
|
| | class ParticleManipulator: |
| | def __init__(self, dim=64): |
| | self.dim = dim |
| | |
| | self.state = np.random.randn(dim) * 0.01 |
| |
|
| | def step(self, input_vec): |
| | |
| | inp = np.asarray(input_vec).ravel() |
| | if inp.size == 0: |
| | inp = np.zeros(self.dim) |
| | |
| | if inp.size < self.dim: |
| | x = np.pad(inp, (0, self.dim - inp.size)) |
| | else: |
| | x = inp[:self.dim] |
| | self.state = particle_step(self.state, x) |
| | return self.state |
| |
|
| | |
| | def simulate_signals(n_samples=500, dim=16, n_classes=4, noise=0.05, seed=0): |
| | rng = np.random.RandomState(seed) |
| | X = [] |
| | y = [] |
| | for cls in range(n_classes): |
| | base = rng.randn(dim) * (0.5 + cls*0.2) + cls*0.7 |
| | for i in range(n_samples // n_classes): |
| | sample = base + rng.randn(dim) * noise |
| | X.append(sample) |
| | y.append(cls) |
| | return np.array(X), np.array(y) |
| |
|
| | |
| | def build_dataset(manip, raw_X): |
| | features = [] |
| | for raw in raw_X: |
| | st = manip.step(raw) |
| | feat = st.copy()[:manip.dim] |
| | features.append(feat) |
| | return np.array(features) |
| |
|
| | |
| | if __name__ == "__main__": |
| | |
| | raw_X, y = simulate_signals(n_samples=800, dim=32, n_classes=4) |
| | manip = ParticleManipulator(dim=32) |
| |
|
| | X = build_dataset(manip, raw_X) |
| | X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=42) |
| |
|
| | clf = RandomForestClassifier(n_estimators=100, random_state=42) |
| | clf.fit(X_train, y_train) |
| | preds = clf.predict(X_test) |
| | print("Accuracy:", accuracy_score(y_test, preds)) |
| |
|
| | |
| | artifact = { |
| | "model": clf, |
| | "particle_state": manip.state, |
| | "meta": {"owner": "Ananthu Sajeev", "artifact_type": "venomous_mind_snapshot_v1"} |
| | } |
| | with open("venomous_mind_snapshot.pkl", "wb") as f: |
| | pickle.dump(artifact, f) |
| |
|
| | print("Saved venomous_mind_snapshot.pkl — this file is your digital pattern snapshot.") |