def evaluate_esn_1d(dataset, params, runs_per_iteration=1, test_snrs=None): if len(params.keys()) != 1: class InvalidParameterDictException(Exception): pass raise InvalidParameterDictException( '1d grid search requires exactly 1 parameter lists') output = [] param_grid = ParameterGrid(params) p1 = sorted(params.keys())[0] # We need the SNR of u/v. u_train, _, u_test, _ = dataset for params in param_grid: print(params) nrmses = [] test_snrs_t = [] for i in range(runs_per_iteration): esn = ESN(**params) nrmses.append(evaluate_esn(dataset, esn)) if test_snrs is not None: test_snrs_t.append(snr(u_test.var(), esn.v.var())) v = esn.v output.append(np.mean(nrmses)) if test_snrs is not None: test_snrs.append(np.mean(test_snrs_t)) return output
def plot_input_noise_trained(dataset): # Logspace from 0.001 to 0.14, as 0.14 is an SNR of ~0.0 with NARMA10. test_noise_std = np.logspace(-2.8239, -0.841, 30) train_noise_std = np.logspace(-2.8239, -0.841, 30) params = { 'awgn_test_std': test_noise_std, 'awgn_train_std': train_noise_std, } u_train, y_train, u_test, y_test = dataset print(snr(u_train.var(), min(train_noise_std)**2)) nrmses, stds = evaluate_esn_2d(dataset, params, runs_per_iteration=10) nrmses = np.array(nrmses).T sns.heatmap(list(reversed(nrmses)), vmin=0.0, vmax=1.0, square=True) ax = plt.axes() # Fix half cells at the top and bottom. This is a current bug in Matplotlib. ax.set_ylim(ax.get_ylim()[0] + 0.5, 0.0) x_width = ax.get_xlim()[1] y_width = ax.get_ylim()[0] plt.xticks([0.0, 0.5 * x_width, x_width], [40, 20, 0]) plt.yticks([0.0, 0.5 * y_width, y_width], [0, 20, 40]) ax.xaxis.set_ticks_position('none') ax.yaxis.set_ticks_position('none') plt.xlabel('Test signal to noise ratio') plt.ylabel('Train signal to noise ratio') ax.collections[0].colorbar.set_label('NRMSE')
def update(self): """ """ # update the RBs used by each ue self._update_ue_rb() # --- total_rb_demand = sum(self._rb_map.values()) # IDEAL CASE: we have more RBs than the UEs demand # == all UEs are satified with their demand if total_rb_demand < Antenna.BW_RB_MAP[self._cur_ch_bw]: self._grid.logger.log("op:antenna_good_cap, antenna:" + str(self) + ", rb_demand:" + str(total_rb_demand) + ", avail_rb:" + str(Antenna.BW_RB_MAP[self._cur_ch_bw]) + ", per_used:" + str(total_rb_demand/Antenna.BW_RB_MAP[self._cur_ch_bw]) + ", nconnected_ues:" + str(len(self.connected_ues)) ) # -- for ue in self.connected_ues: ue.tx_rate = ue.demand # NOT IDEAL CASE: we have less RBs than the UEs demand # == available RBs split evenly among UEs else: # quantity of RBs available avail_rb = Antenna.BW_RB_MAP[self._cur_ch_bw] # bivide equaly among all UEs rb_per_ue = math.floor(avail_rb/len(self.connected_ues)) # set UE tx_rate based for ue in self.connected_ues: ue.tx_rate = rb_per_ue * util.snr_to_bit(util.snr(ue, self) ) self._grid.logger.log("op:antenna_bad_cap, antenna:" + str(self) + ", rb_demand:" + str(total_rb_demand) + ", avail_rb:" + str(Antenna.BW_RB_MAP[self._cur_ch_bw]) + ", per_used:" + str(1.0) + ", nconnected_ues:" + str(len(self.connected_ues)) ) if len(self.connected_ues) != self.prev_n_ues: if self.prev_n_ues == 0: self._grid.logger.log("op:antenna_wake_up") elif len(self.connected_ues) == 0: self._grid.logger.log("op:antenna_idle") self.prev_n_ues = len(self.connected_ues) # Notify BBU that this antenna requires more bandwidth self._ch_bw_required = self.rb_demand_to_ch_bw(total_rb_demand) if self._ch_bw_required != self._cur_ch_bw: self._bbu.event(controller.ANTENNA_BW_UPDATE, self)
def _update_ue_rb(self): """ Check the total RBs required to satisfy UEs demands """ self._rb_map = {} for ue in self.connected_ues: # calculate the total RBs for each UE # mult per 84 because: 84 ofdm symbons in a RB self._rb_map[ue] = ue.demand / (util.snr_to_bit(util.snr(ue, self, 0)) * 84.0)
def _update_ue_rb(self): """ Check the total RBs required to satisfy UEs demands """ self._rb_map = {} for ue in self._ues: # calculate the total RBs for each UE # mult per 84 because: 84 ofdm symbons in a RB self._rb_map[ue] = ue.demand / (util.snr_to_bit(util.snr(ue, self, 0)) * 84.0)
def can_fit_ue(self, ue): # BS always can fit an UE if self.type == Antenna.BS_ID: return True total_rb_demand = sum(self._rb_map.values()) ue_rb_demand = ue.demand / (util.snr_to_bit(util.snr(ue, self, 0)) * 84.0) if total_rb_demand + ue_rb_demand < Antenna.BW_RB_MAP[self._cur_ch_bw]: return True else: return False
def update(self): """ """ # update the RBs used by each ue self._update_ue_rb() # --- total_rb_demand = sum(self._rb_map.values()) # IDEAL CASE: we have more RBs than the UEs demand # == all UEs are satified with their demand if total_rb_demand < Antenna.BW_RB_MAP[self._cur_ch_bw]: self._grid.logger.log("op:antenna_good_cap, antenna:" + str(self) + ", rb_demand:" + str(total_rb_demand) + ", avail_rb:" + str(Antenna.BW_RB_MAP[self._cur_ch_bw]) + ", per_used:" + str(total_rb_demand/Antenna.BW_RB_MAP[self._cur_ch_bw]) + ", n_ues:" + str(len(self._ues)) ) # -- for ue in self._ues: ue.tx_rate = ue.demand # NOT IDEAL CASE: we have less RBs than the UEs demand # == available RBs split evenly among UEs else: # quantity of RBs available avail_rb = Antenna.BW_RB_MAP[self._cur_ch_bw] # bivide equaly among all UEs rb_per_ue = math.floor(avail_rb/len(self._ues)) # set UE tx_rate based for ue in self._ues: ue.tx_rate = rb_per_ue * util.snr_to_bit(util.snr(ue, self) ) self._grid.logger.log("op:antenna_bad_cap, antenna:" + str(self) + ", rb_demand:" + str(total_rb_demand) + ", avail_rb:" + str(Antenna.BW_RB_MAP[self._cur_ch_bw]) + ", per_used:" + str(1.0) + ", n_ues:" + str(len(self._ues)) ) # Notify BBU that this antenna requires more bandwidth self._ch_bw_required = self.rb_demand_to_ch_bw(total_rb_demand) if self._ch_bw_required != self._cur_ch_bw: self._bbu.event(controller.ANTENNA_BW_UPDATE, self)
def evaluate_esn_2d(dataset, params, runs_per_iteration=1, test_snrs=None): if len(params.keys()) != 2: class InvalidParameterDictException(Exception): pass raise InvalidParameterDictException( '2d grid search requires exactly 2 parameter lists') # We need the SNR of u/v. u_train, _, u_test, _ = dataset sorted_params = sorted(params.keys()) p1 = sorted_params[0] p2 = sorted_params[1] n_p1, n_p2 = len(params[p1]), len(params[p2]) nrmse_output = [[] for _ in range(n_p1)] std_output = [[] for _ in range(n_p1)] for i in range(n_p1): if test_snrs is not None: test_snrs.append([]) param_grid = ParameterGrid(params) for i, params in enumerate(param_grid): print(params) p1_i = i // n_p2 nrmses = [] test_snrs_t = [] for i in range(runs_per_iteration): # (TODO): Change this to return everything instead of passing lists # to this grid function. nrmse, esn = eval_esn_with_params(dataset, params) nrmses.append(nrmse) if test_snrs is not None: test_snrs_t.append(snr(u_test.var(), esn.v.var())) v = esn.v nrmse_output[p1_i].append(np.mean(nrmses)) std_output[p1_i].append(np.std(nrmses)) if test_snrs is not None: test_snrs[p1_i].append(np.mean(test_snrs_t)) # (TODO): Return a dict of different metrics that includes SNR. return nrmse_output, std_output