mda-memory 0.1.1__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
mda/__init__.py ADDED
@@ -0,0 +1,3 @@
1
+ from mda.mda import MDA
2
+
3
+ __all__ = ["MDA"]
mda/core/__init__.py ADDED
File without changes
mda/core/bind.py ADDED
@@ -0,0 +1,39 @@
1
+ import numpy as np
2
+
3
+ DIM = 256
4
+
5
+
6
+ def normalize(v: np.ndarray) -> np.ndarray:
7
+ n = np.linalg.norm(v)
8
+ return v / (n + 1e-8)
9
+
10
+
11
+ def random_vector(dim: int = DIM, seed: int = None) -> np.ndarray:
12
+ rng = np.random.default_rng(seed)
13
+ return normalize(rng.normal(0, 1, dim))
14
+
15
+
16
+ def zero_vector(dim: int = DIM) -> np.ndarray:
17
+ return np.zeros(dim)
18
+
19
+
20
+ def bind(a: np.ndarray, b: np.ndarray) -> np.ndarray:
21
+ return np.real(np.fft.ifft(np.fft.fft(a) * np.fft.fft(b)))
22
+
23
+
24
+ def unbind(compound: np.ndarray, b: np.ndarray) -> np.ndarray:
25
+ F_b = np.fft.fft(b)
26
+ F_b_inv = np.conj(F_b) / (np.abs(F_b) ** 2 + 1e-6)
27
+ b_inv = np.real(np.fft.ifft(F_b_inv))
28
+ return np.real(np.fft.ifft(np.fft.fft(compound) * np.fft.fft(b_inv)))
29
+
30
+
31
+ def bind_many(*vectors: np.ndarray) -> np.ndarray:
32
+ result = vectors[0].copy()
33
+ for v in vectors[1:]:
34
+ result = bind(result, v)
35
+ return result
36
+
37
+
38
+ def cosine(a: np.ndarray, b: np.ndarray) -> float:
39
+ return float(np.dot(a, b) / (np.linalg.norm(a) * np.linalg.norm(b) + 1e-8))