def perturb_all_nodes(variant): runner, ckpt_path = init(variant, device=device) experiments = { # "dropout": { # "dropout": True, # }, "pulse1": { "strength": 1.0 }, "pulse10": { "strength": 10.0 }, # "pulse100": { # "strength": 100.0 # }, # "pulse1000": { # "strength": 1000.0 # }, } for experiment_name in experiments: experiment_args = experiments[experiment_name] reset_random_state(runner.config) # 10 nodes, 10 timesteps, 5 random draws node_range = torch.arange(runner.config.TASK.NUM_NODES) # node_range = torch.randint(0, runner.config.TASK.NUM_NODES, (settings,)) step_range = [5, runner.config.TASK.NUM_STEPS // 2, runner.config.TASK.NUM_STEPS - 5] # Early, mid, late perturb_exp = [] print() print(f"{runner.config.VARIANT} - {experiment_name}") print() for step in step_range: for node in node_range: _, primary_res = pulse( runner, ckpt_path, trials=5, step=step, node=[node], **experiment_args ) perturb_exp.append({ "step": step, "node": node, "score": torch.tensor(primary_res).mean() }) torch.save(perturb_exp, f"./eval/perturb_all_{runner.config.VARIANT}-{experiment_name}.pth")
device = torch.device("cuda", 0) else: device = torch.device("cpu") import torch.nn.functional as f from torch.utils import data from analyze_utils import init from analyze_utils import init, pulse, reset_random_state #, rq_1_1 variant = "seq_mnist_drop0" variant = "seq_mnist" runner, ckpt_path = init(variant, device=device) #%% import networkx as nx G = nx.read_edgelist(runner.config.MODEL.GRAPH_FILE) nx.draw(G, with_labels=True) # plt.savefig("network.pdf") print(nx.diameter(G)) #%% metrics, info = runner.eval(ckpt_path) inputs = info["inputs"] outputs = info["outputs"] targets = info["targets"] masks = info["masks"] #%%
import seaborn as sns import numpy as np # ! SET YOUR DEVICE HERE ALLOCATED_DEVICE_ID = 4 os.environ["CUDA_VISIBLE_DEVICES"] = str(ALLOCATED_DEVICE_ID) import torch if torch.cuda.device_count() >= 0: device = torch.device("cuda", 0) else: device = torch.device("cpu") from analyze_utils import init, pulse, reset_random_state # , rq_1_1 variant = "dc" runner, ckpt_path = init(variant) #%% import networkx as nx G = nx.read_edgelist(runner.config.MODEL.GRAPH_FILE) nx.draw(G, with_labels=True) # plt.savefig("network.pdf") print(nx.diameter(G)) #%% metrics, info = runner.eval(ckpt_path) inputs, outputs, targets, masks = info inputs = info["inputs"] outputs = info["outputs"]