-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_shuffled_target_decoding.py
More file actions
67 lines (57 loc) · 1.87 KB
/
test_shuffled_target_decoding.py
File metadata and controls
67 lines (57 loc) · 1.87 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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
import numpy as np
import pandas as pd
# Load data from the shuffled .npy files
X_path = "datasets/hdc_pairs_200_shot/X_pairs_shuffled.npy"
Y_path = "datasets/hdc_pairs_200_shot/Y_pairs_shuffled.npy"
O_path = "datasets/hdc_pairs_200_shot/O_pairs_shuffled.npy"
X = np.load(X_path, mmap_mode="r")
Y = np.load(Y_path, mmap_mode="r")
O = np.load(O_path, mmap_mode="r")
# Choose a random index
idx = np.random.randint(0, len(Y))
print(f"\n🔀 Random sample index selected: {idx}")
# Get the sample
y_sample = Y[idx][:10]
o_sample = O[idx]
# Decode using same logic as inference
VOLUME_K = 0.2
OCLOSE = 0
OVOLUME = 1
OQUOTE = 2
ONTRADES = 3
OTBBAV = 4
OTBQAV = 5
prev_close = float(o_sample[OCLOSE])
prev_vals = {
"volume": float(o_sample[OVOLUME]),
"quote_asset_volume": float(o_sample[OQUOTE]),
"number_of_trades": float(o_sample[ONTRADES]),
"taker_buy_base_asset_volume": float(o_sample[OTBBAV]),
"taker_buy_quote_asset_volume": float(o_sample[OTBQAV]),
}
decoded_rows = []
for row in y_sample:
# OHLC decoding
dec = {
"open": prev_close * np.exp(row[0]),
"high": prev_close * np.exp(row[1]),
"low": prev_close * np.exp(row[2]),
"close": prev_close * np.exp(row[3]),
}
# Volume decoding
vol_keys = [
"volume", "quote_asset_volume", "number_of_trades",
"taker_buy_base_asset_volume", "taker_buy_quote_asset_volume"
]
for i, key in enumerate(vol_keys, start=4):
log_ret = np.arctanh(np.clip(row[i], -0.999999, 0.999999)) / VOLUME_K
dec[key] = prev_vals[key] * np.exp(log_ret)
# Update previous values for next step
prev_close = dec["close"]
for key in prev_vals:
prev_vals[key] = dec[key]
decoded_rows.append(dec)
# Display in terminal
decoded_df = pd.DataFrame(decoded_rows)
print("\n📋 Decoded first 10 target rows:")
print(decoded_df.to_string(index=False))