batch_size = 500 nepoch = 50 #-------------------------------------------# # Here should be the data_preparing function # It is expected to return: # train_inp, train_out, val_inp, and val_out #-------------------------------------------# h_real = np.load('D://Github Repositories/mmWave Beam Management/H_Matrices FineGrid/MISO_Static_FineGrid_Hmatrices_real.npy')[:,antenna_sel] h_imag = np.load('D://Github Repositories/mmWave Beam Management/H_Matrices FineGrid/MISO_Static_FineGrid_Hmatrices_imag.npy')[:,antenna_sel] loc = np.load('D://Github Repositories/mmWave Beam Management/H_Matrices FineGrid/MISO_Static_FineGrid_UE_location.npy') # h_real = np.load('/Users/yh9277/Dropbox/ML Beam Alignment/Data/H_Matrices FineGrid/MISO_Static_FineGrid_Hmatrices_real.npy') # h_imag = np.load('/Users/yh9277/Dropbox/ML Beam Alignment/Data/H_Matrices FineGrid/MISO_Static_FineGrid_Hmatrices_imag.npy') BS_loc = [641,435,10] num_samples = h_real.shape[0] gc = GaussianCenters(n_clusters=8, arrival_rate = 1000, cluster_variance = 5, seed=r_seed) sel_samples = gc.sample() # gc.plot_sample(sel_samples) # sel_samples = np.arange(10000) h_real = h_real[sel_samples,:] h_imag = h_imag[sel_samples,:] loc = loc[sel_samples,:] plt.figure(figsize=(8,6)) plt.scatter(loc[:,0], loc[:,1], s=1, label='UE') plt.scatter(BS_loc[0], BS_loc[1], s=10, marker='s', label='BS') plt.legend(loc='lower left') plt.xlabel('x (meter)') plt.ylabel('y (meter)') plt.title('UE Distribution') plt.show()
val_h,val_y = val_batch val_y = torch.from_numpy(val_y).float() # val_x = torch.from_numpy(estimate_h(val_h, model, num_antenna)).float() val_x, val_z = estimate_h(val_h, model, num_antenna, h_est_force_z) if h_est_force_z: val_z = torch.from_numpy(val_z).float() loss = loss_fn(model(val_x,val_z),val_y) return loss.item() dataset = GaussianCenters(possible_loc=loc[:,:2], n_clusters=n_clusters, arrival_rate = arrival_rate, cluster_variance = cluster_variance) test_gains_maml = np.zeros((len(num_of_beams),ntest,dataset.n_clusters*dataset.arrival_rate)) test_gains_scratch = np.zeros((len(num_of_beams),ntest,dataset.n_clusters*dataset.arrival_rate)) test_gains_dft = np.zeros((len(num_of_beams),ntest,dataset.n_clusters*dataset.arrival_rate)) for i,N in enumerate(num_of_beams): print(str(N) + '-beams Codebook') # Model: # ------ model = AnalogBeamformer(n_antenna = num_antenna, n_beam = N) maml = MAML(model, lr=fast_lr, first_order=True) # Training: # --------- optimizer = optim.Adam(model.parameters(),lr=meta_lr, betas=(0.9,0.999), amsgrad=False)
nepoch = 20 h_est_force_z = False # #-------------------------------------------# # Here should be the data_preparing function # It is expected to return: # train_inp, train_out, val_inp, and val_out #-------------------------------------------# h_real = np.load('D://Github Repositories/mmWave Beam Management/H_Matrices FineGrid/MISO_Static_FineGrid_Hmatrices_real.npy')[:,antenna_sel] h_imag = np.load('D://Github Repositories/mmWave Beam Management/H_Matrices FineGrid/MISO_Static_FineGrid_Hmatrices_imag.npy')[:,antenna_sel] loc = np.load('D://Github Repositories/mmWave Beam Management/H_Matrices FineGrid/MISO_Static_FineGrid_UE_location.npy') # h_real = np.load('/Users/yh9277/Dropbox/ML Beam Alignment/Data/H_Matrices FineGrid/MISO_Static_FineGrid_Hmatrices_real.npy') # h_imag = np.load('/Users/yh9277/Dropbox/ML Beam Alignment/Data/H_Matrices FineGrid/MISO_Static_FineGrid_Hmatrices_imag.npy') BS_loc = [641,435,10] num_samples = h_real.shape[0] gc = GaussianCenters(n_clusters=10, arrival_rate = 1000, cluster_variance = 10) sel_samples = gc.sample() # gc.plot_sample(sel_samples) # sel_samples = np.arange(10000) h_real = h_real[sel_samples,:] h_imag = h_imag[sel_samples,:] loc = loc[sel_samples,:] plt.figure(figsize=(8,6)) plt.scatter(loc[:,0], loc[:,1], s=1, label='UE') plt.scatter(BS_loc[0], BS_loc[1], s=10, marker='s', label='BS') plt.legend(loc='lower left') plt.xlabel('x (meter)') plt.ylabel('y (meter)') plt.title('UE Distribution') plt.show()