@@ -40,8 +40,22 @@ def __init__(self, input_dim, number_tokens, norm=1.0, beta=1.0):
4040 self .D = input_dim
4141 self .L = number_tokens
4242 self .S = nn .Linear (input_dim , input_dim , bias = False )
43- # Initialisation random
44- self .S .weight .data .uniform_ (0.0 , norm )
43+ self .S .weight .data .uniform_ (0.0 , norm ) # Initialisation random
44+
45+ def init_teacher (self , R ):
46+ """
47+ Initialize S as a PSD matrix: S = W W^T / sqrt(r * D)
48+ where W is a random Gaussian matrix.
49+ """
50+ # Create a random weight matrix W ~ N(0, 1)
51+ self .R = R
52+ W = torch .randn (self .D , self .R , device = self .S .weight .device )
53+
54+ # Compute PSD matrix
55+ S_psd = (W @ W .T ) / np .sqrt (self .R * self .D )
56+
57+ # Copy into model weights
58+ self .S .weight .data = S_psd .clone ()
4559
4660
4761 def forward (self , x , delta_in ):
@@ -96,6 +110,8 @@ def run_experiment(alpha_idx=0, D=100, L=2, rho=1.00, rho_star=0.5, beta=1.0,
96110
97111 all_results = []
98112
113+ R_star = int (rho_star * D )
114+
99115 if run_index is not None and alpha_list is not None :
100116 alpha_list = [alpha_list [run_index ]]
101117
@@ -109,13 +125,14 @@ def run_experiment(alpha_idx=0, D=100, L=2, rho=1.00, rho_star=0.5, beta=1.0,
109125 N = int (alpha * D ** 2 )
110126 with torch .no_grad ():
111127 teacher = Net (D , L , norm = 1.0 , beta = beta_star )
128+ teacher .init_teacher (R_star )
112129 S_teacher = teacher .S .weight .detach ().cpu ().numpy ()
113130
114131 MSE_runs , label_err_runs , label_err_runs_noise = [], [], []
115132 train_data_runs , train_reg_runs , total_loss_runs = [], [], []
116133 S_runs = []
117134
118- for i in range (samples ):
135+ for _ in range (samples ):
119136 x_train = torch .normal (0 , 1 , (N , L , D ))
120137 with torch .no_grad ():
121138 y_train = teacher (x_train , delta_in = Delta_in )
@@ -157,9 +174,9 @@ def run_experiment(alpha_idx=0, D=100, L=2, rho=1.00, rho_star=0.5, beta=1.0,
157174 "MSE_mean" : float (np .mean (MSE_runs )),
158175 "MSE_std" : float (np .std (MSE_runs , ddof = 1 )) if len (MSE_runs ) > 1 else 0.0 ,
159176 "label_err_mean" : float (np .mean (label_err_runs )/ D ** 2 ),
160- "label_err_std" : float (np .std (label_err_runs , ddof = 1 )/ D ** 4 ) if len (label_err_runs ) > 1 else 0.0 ,
177+ "label_err_std" : float (np .std (label_err_runs , ddof = 1 )/ D ** 2 ) if len (label_err_runs ) > 1 else 0.0 ,
161178 "label_err_mean_noise" : float (np .mean (label_err_runs_noise )/ D ** 2 ),
162- "label_err_std_noise" : float (np .std (label_err_runs_noise , ddof = 1 )/ D ** 4 ) if len (label_err_runs_noise ) > 1 else 0.0 ,
179+ "label_err_std_noise" : float (np .std (label_err_runs_noise , ddof = 1 )/ D ** 2 ) if len (label_err_runs_noise ) > 1 else 0.0 ,
163180 "train_data_mean" : float (np .mean (train_data_runs )/ D ** 2 ),
164181 "train_reg_mean" : float (np .mean (train_reg_runs )/ D ** 2 ),
165182 "train_total_mean" : float (np .mean (total_loss_runs )/ D ** 2 ),
@@ -231,9 +248,9 @@ def get_run_dir(base_path="/home/peucelle/tpiv-simulations/results"):
231248 # Charger la configuration
232249 config = {
233250 "verbose" : False ,
234- "alpha_start" : 0.005 ,
235- "alpha_end" : 1.0 ,
236- "alpha_steps" : 10 ,
251+ "alpha_start" : 0.0005 ,
252+ "alpha_end" : 0.05 ,
253+ "alpha_steps" : 15 ,
237254 "d" : 100 ,
238255 "L" : 2 ,
239256 "beta" : 1.0 ,
@@ -247,7 +264,7 @@ def get_run_dir(base_path="/home/peucelle/tpiv-simulations/results"):
247264 "tol" : 1e-6 ,
248265 "n_test" : 2000 ,
249266 "rho" : 1.0 ,
250- "rho_star" : 0.5
267+ "rho_star" : 0.5
251268 }
252269
253270 # Initialiser les graines
0 commit comments