"edge_index": dp.edge_index.to(device), "pos": dp.pos.to(device) } F.update_params(params_dict) y0 = dp.x.to(device) t = dp.t[0:ts].to(device) y_pd = adj_integr.integrate(F, y0, t, method=args.method, rtol=args.rtol, atol=args.atol) print("Plotting...") print(y_pd.cpu().detach().numpy().shape) print(dp.y.numpy().shape) print(dataset[0].t.shape) print(dataset[0].pos.shape) plt.figure(0) utils.plot_fields( t=dataset[0].t, coords=dataset[0].pos, fields={ "y_pd": y_pd.cpu().detach().numpy(), "y_gt": dp.y.numpy(), }, save_path="./tmp_figs_dec12_n3000/", delay=0.0001, ) plt.show()
print("epoch {:>5d} | train loss: {:>7.12f}".format(epoch, losses.mean())) torch.save(F.state_dict(), args.model_path) if losses.mean() <= 0.0001: break dp = dataset[0] params_dict = {"edge_index": dp.edge_index.to(device), "pos": dp.pos.to(device)} F.update_params(params_dict) y0 = dp.x.to(device) t = dp.t[0:ts].to(device) y_pd = adj_integr.integrate( F, y0, t, method=args.method, rtol=args.rtol, atol=args.atol) print("Plotting...") print(y_pd.cpu().detach().numpy().shape) print(dp.y.numpy().shape) print(dataset[0].t.shape) print(dataset[0].pos.shape) plt.figure(0) utils.plot_fields( t=dataset[0].t, coords=dataset[0].pos, fields={ "y_pd": y_pd.cpu().detach().numpy(), "y_gt": dp.y.numpy(), }, save_path="./tmp_covid_state_daily_norm_10k/", delay=0.0001, ) plt.show()
np.linalg.norm(u[i].reshape(-1) - u_pd[i].reshape(-1)) / (np.linalg.norm(u[i].reshape(-1)) + eps) for i in range(len(u)) ] diffs_over_time.append(diffs) print("test case {:>5d} | test loss: {:>7.12f}".format(i, losses[i])) if i in inds_of_sims_to_show: print("Plotting...") # utils.plot_grid(dataset[i].pos.cpu().detach().numpy()) plt.figure(0) utils.plot_fields( t=dataset[i].t, coords=dataset[i].pos, fields={ "y_pd": u_pd, "y_gt": u, }, save_path="./tmp_figs/", delay=0.0001, ) plt.show() # if i == 2: # break print("Plotting diffs...") plt.figure(0) t = dataset[0].t.numpy() for diff in diffs_over_time: plt.plot(t, diff, alpha=0.5)
eps = 1.0e-6 diffs = [np.linalg.norm(u[i].reshape(-1) - u_pd[i].reshape(-1)) / (np.linalg.norm(u[i].reshape(-1)) + eps) for i in range(len(u))] diffs_over_time.append(diffs) print("test case {:>5d} | test loss: {:>7.12f}".format(i, losses[i])) if i in inds_of_sims_to_show: print("Plotting...") utils.plot_grid(dataset[i].pos.cpu().detach().numpy()) plt.figure(0) utils.plot_fields( t=dataset[i].t.cpu().detach().numpy(), coords=dataset[i].pos.cpu().detach().numpy(), fields={ "y_pd": u_pd, "y_gt": u, }, save_path="./tmp_figs/", delay=0.0001, ) plt.show() # if i == 2: # 3 for grids, 2 for time points # break print("Plotting diffs...") plt.figure(0) t = dataset[0].t.numpy() for diff in diffs_over_time: plt.plot(t, diff, alpha=0.5)