P2SAMAPA commited on
Commit
f0300e9
Β·
unverified Β·
1 Parent(s): f34e5b6

Update models.py

Browse files
Files changed (1) hide show
  1. models.py +14 -0
models.py CHANGED
@@ -10,6 +10,8 @@ Key components:
10
  - Sparse categorical cross-entropy loss
11
  """
12
 
 
 
13
  import numpy as np
14
  import tensorflow as tf
15
  from tensorflow.keras.models import Model
@@ -19,6 +21,13 @@ from tensorflow.keras.layers import (
19
  Multiply, Add, Activation, Conv1D
20
  )
21
  from tensorflow.keras.callbacks import EarlyStopping, ReduceLROnPlateau
 
 
 
 
 
 
 
22
  from tensorflow.keras.regularizers import l2
23
 
24
 
@@ -120,6 +129,11 @@ def train_tft(X_train, y_train, X_val, y_val, epochs=200):
120
  Train the TFT classifier.
121
  y_train/y_val: integer class labels (argmax of 5-day fwd returns).
122
  """
 
 
 
 
 
123
  seq_len = X_train.shape[1]
124
  num_features = X_train.shape[2]
125
  num_classes = len(np.unique(y_train))
 
10
  - Sparse categorical cross-entropy loss
11
  """
12
 
13
+ import random
14
+ import os
15
  import numpy as np
16
  import tensorflow as tf
17
  from tensorflow.keras.models import Model
 
21
  Multiply, Add, Activation, Conv1D
22
  )
23
  from tensorflow.keras.callbacks import EarlyStopping, ReduceLROnPlateau
24
+
25
+ # ── Fixed random seed β€” ensures reproducible results across runs ─────────────
26
+ SEED = 42
27
+ random.seed(SEED)
28
+ np.random.seed(SEED)
29
+ tf.random.set_seed(SEED)
30
+ os.environ["PYTHONHASHSEED"] = str(SEED)
31
  from tensorflow.keras.regularizers import l2
32
 
33
 
 
129
  Train the TFT classifier.
130
  y_train/y_val: integer class labels (argmax of 5-day fwd returns).
131
  """
132
+ # Re-apply seed immediately before model build for full reproducibility
133
+ random.seed(SEED)
134
+ np.random.seed(SEED)
135
+ tf.random.set_seed(SEED)
136
+
137
  seq_len = X_train.shape[1]
138
  num_features = X_train.shape[2]
139
  num_classes = len(np.unique(y_train))