def calculate(self, model_func): self.w_store.append(self.w) algo = algo_GD.SGD(w_init=self.w, t_max=self.t, a=self.a) for i in algo: f = model_func(noise_value=self.noise_data[algo.t - 1]) algo.update(f) self.w_store.append(algo.w) tmp = 0 total_w = 0 for k in range(algo.t): tmp += (1 - self.eta)**k total_w += ((1 - self.eta)**k) * algo.wstore[k] self.w = total_w / tmp self.w_store.append(self.w) return self.w
import helper import noise if __name__ == "__main__": args = sys.argv t = int(args[1]) w_init = np.array([3, 3]) _t_max = 3000 f = model_opt.RosenBrock() w_star = f.w_star last_w_store = [] iqr_store = [] for i in tqdm(range(t)): a = 5 noise_data = noise.Pareto(dim=2, n=_t_max, a=a).generate() * 300 iqr = helper.iqr(noise_data) algo = algo_GD.SGD(w_init=w_init, t_max=_t_max, a=0.00078) for i in algo: noise_value = noise_data[algo.t - 1] f = model_opt.RosenBrock(noise_value=noise_value) algo.update(model=f) last_w_store.append(algo.w) iqr_store.append(iqr) dt_now = datetime.datetime.now() last_w_store = np.array(last_w_store) data = np.array([iqr_store, last_w_store[:, 0], last_w_store[:, 1]]).T df = pd.DataFrame(data=data, columns=['iqr', 'w_0', 'w_1']) df.to_csv('pareto_noise/pareto_noise{}_last_w{}.csv'.format(t, dt_now), header=True)