-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhdc_data_shuffle_v2.py
More file actions
44 lines (35 loc) · 1.28 KB
/
hdc_data_shuffle_v2.py
File metadata and controls
44 lines (35 loc) · 1.28 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
import numpy as np
from numpy.lib.format import open_memmap
# === Input paths ===
X_in = "datasets/hdc_pairs_200_shot/X_pairs_combined.npy"
Y_in = "datasets/hdc_pairs_200_shot/Y_pairs_combined.npy"
O_in = "datasets/hdc_pairs_200_shot/O_pairs_combined.npy"
# === Output paths ===
X_out = "datasets/hdc_pairs_200_shot/X_pairs_shuffled.npy"
Y_out = "datasets/hdc_pairs_200_shot/Y_pairs_shuffled.npy"
O_out = "datasets/hdc_pairs_200_shot/O_pairs_shuffled.npy"
# === Load input data ===
X = np.load(X_in, mmap_mode="r")
Y = np.load(Y_in, mmap_mode="r")
O = np.load(O_in, mmap_mode="r")
N, W, F = X.shape
_, _, T = Y.shape
_, O_dim = O.shape
# === Create empty output arrays ===
X_shuf = open_memmap(X_out, mode="w+", dtype=np.float32, shape=(N, W, F))
Y_shuf = open_memmap(Y_out, mode="w+", dtype=np.float32, shape=(N, W, T))
O_shuf = open_memmap(O_out, mode="w+", dtype=np.float32, shape=(N, O_dim))
# === Generate and apply permutation ===
perm = np.random.default_rng().permutation(N)
for new_idx, old_idx in enumerate(perm):
X_shuf[new_idx] = X[old_idx]
Y_shuf[new_idx] = Y[old_idx]
O_shuf[new_idx] = O[old_idx]
# === Flush to disk ===
X_shuf.flush()
Y_shuf.flush()
O_shuf.flush()
print(f"✅ Shuffled and saved:")
print(f" → {X_out}")
print(f" → {Y_out}")
print(f" → {O_out}")