Download src/boolean_adapter.py from Snapkitty/quantumap: direct link, hf CLI and curl.
- Browser
- Download file 850 Bytes
-
https://huggingface.co/Snapkitty/quantumap/resolve/main/src/boolean_adapter.py
- Command line
-
hf download hf://Snapkitty/quantumap/src/boolean_adapter.py
-
curl -L -o boolean_adapter.py https://huggingface.co/Snapkitty/quantumap/resolve/main/src/boolean_adapter.py
850 Bytes
| """ | |
| BooleanAdapter: Neural weights → {-1, +1} boolean states. | |
| Deterministic threshold: w > 0 → +1, w ≤ 0 → -1 | |
| No entropy-increasing randomness. | |
| """ | |
| import numpy as np | |
| def adapt(weights: np.ndarray) -> np.ndarray: | |
| """Convert raw neural weights to boolean states {-1, +1}.""" | |
| return np.where(weights > 0, 1.0, -1.0) | |
| def adapt_with_threshold(weights: np.ndarray, threshold: float = 0.0) -> np.ndarray: | |
| """Convert with custom threshold.""" | |
| return np.where(weights > threshold, 1.0, -1.0) | |
| def select_active(bool_weights: np.ndarray, n_active: int) -> np.ndarray: | |
| """Select top n_active agents by absolute weight magnitude.""" | |
| indices = np.argsort(np.abs(bool_weights))[::-1][:n_active] | |
| result = np.zeros_like(bool_weights) | |
| result[indices] = bool_weights[indices] | |
| return result | |