def print_charts(): for n in n_range: ys, zs = runge_kutta_system(y_der, z_der, y0, z0, a, b, n) title = "N = " + str(n) file_name = "imp_" + str(n) xs = create_xs(a, b, n) y = [y_true(x) for x in xs] z = [z_true(x) for x in xs] # print(len(xs), len) # 2, 4, 8, считать погрешности на правом конце отрезка, всё в таблицу. погрешность должна меняться в 2**4 раз res = [ (ys, "y"), (zs, "z"), (y, "y(точный)"), (z, "z(точный)") ] draw(xs, res, title, file_name)
y_der = lambda x, y, z: z / x z_der = lambda x, y, z: z * (y + 2 * z - 1) / (x * (y - 1)) y_true = lambda x: x / (x + 1) z_true = lambda x: x / (x + 1) ** 2 # print_explicit(a, b, y0, z0, y_der, z_der, y_true, z_true) # print() # print_implicit(a, b, y0, z0, y_true, z_true) for n in n_range: if sys.argv[1] == "i": ys, zs, count = implicit_euler(n, a, b, y0, z0, choice(epss)) t = "Неявный метод, N = " + str(n) f = "imp_" + str(n) else: ys, zs = euler(n, a, b, y0, z0, y_der, z_der) t = "Явный метод, N = " + str(n) f = "imp_" + str(n) xs = create_xs(a, b, n) y = [y_true(x) for x in xs] z = [z_true(x) for x in xs] res = [ (ys, "y"), (zs, "z"), (y, "y(точный)"), (z, "z(точный)") ] draw(xs, res, t, f)
# d = model(h,r,t,h_hat,t) # else: # d = model(h,r,t,h,t_hat) d = model(h, r, t, h, t_hat) cnt += d.shape[0] l += d.sum() # break d.sum().backward() # print(time.time()-start) # l.backward() optimizer.step() display_l.append(l.item() / cnt) if (epoch + 1) % 1 == 0: print("{} time: {} : {}".format(epoch + 1, time.time() - start, l.item())) draw(display_l) if (epoch + 1) % 50 == 0 or epoch == 0: valid = [] cnt = 0 for h, r, t in loader.get_dataiter_('valid', 1, True): valid.append(model.evaluate(h, r, t)) if valid[-1] < 10: cnt += 1 print(sum(valid) / len(valid)) print(cnt * 1.0 / len(valid)) model.save_net(model.model_name) test = [] cnt = 0 for h, r, t in loader.get_dataiter_('test', 1, True): test.append(model.evaluate(h, r, t))
def draw(self, plots=None): if plots is None: plots = self.plots draw.draw(plots, self.settings)