@@ -47,6 +47,9 @@ class FiniteDiffRegressor(BaseModel, RegressorMixin):
47
47
q : float, optional
48
48
Quantile for quantile loss (default=0.5).
49
49
50
+ seed : int
51
+ Random seed.
52
+
50
53
**kwargs
51
54
Additional parameters to pass to the scikit-learn model.
52
55
@@ -72,6 +75,7 @@ def __init__(self, base_model,
72
75
self .l1_ratio = l1_ratio
73
76
self .type_loss = type_loss
74
77
self .q = q
78
+ self .seed = seed
75
79
76
80
# Training state
77
81
self .loss_history_ = []
@@ -85,6 +89,7 @@ def _initialize_weights(self, X, y):
85
89
input_dim = X .shape [1 ]
86
90
# He initialization (good for ReLU-like activations)
87
91
scale = np .sqrt (2.0 / input_dim )
92
+ np .random .seed (self .seed )
88
93
self .model .W_ = np .random .normal (0 , scale , size = self .model .W_ .shape )
89
94
self ._is_initialized = True
90
95
@@ -108,7 +113,7 @@ def _loss(self, X, y, **kwargs):
108
113
def _compute_grad (self , X , y ):
109
114
"""Compute gradient using finite differences"""
110
115
if not self ._is_initialized :
111
- self ._initialize_weights (X )
116
+ self ._initialize_weights (X , y )
112
117
113
118
W = self .model .W_ .copy () # Use current weights
114
119
shape = W .shape
@@ -152,7 +157,7 @@ def fit(self, X, y, epochs=10, verbose=True, show_progress=True, sample_weight=N
152
157
"""Fit model using finite difference optimization"""
153
158
# Initialize weights if not already done
154
159
if not self ._is_initialized :
155
- self ._initialize_weights (X )
160
+ self ._initialize_weights (X , y )
156
161
157
162
# Training loop
158
163
iterator = tqdm (range (epochs )) if show_progress else range (epochs )
0 commit comments