Learning Parameters¶
Code¶
To learn the model parameters, you can run learn_parameters.py
directly on the command line:
python learn_parameters.py 'path/to/dataset_directory'
or from your own Python code:
1 from learn_parameters import get_dataset, learn_parameters
2
3 dataset_dir, dataset_info, g = get_dataset(dataset_dir='path/to/dataset_directory')
4 learn_parameters(dataset_dir, dataset_info, g)
Input files¶
You’ll need to create the following files inside your dataset directory.
Graph¶
Create igraph file for dataset as follows:
1 import igraph
2
3 # Create igraph
4 g = igraph.Graph(n=len(nodes), # nodes is a a list with the nodes
5 directed=False,
6 edges=edge_list, # list of edges (not unique), with indices in node list (u,v)
7 edge_attrs={'timestep': edge_timesteps} # list of timesteps, one for each edge in edge_list
8 )
9
10 # Annotate with time when nodes become active
11 for v in g.vs:
12 v['nid'] = f'nid-{v.index}' # Annotate with original index
13 neighbors = list(set([u for u in g.neighbors(v)]))
14 if len(neighbors) > 0:
15 v_edges = g.es.select(_between=([v.index], neighbors))
16 v['active'] = min(v_edges['timestep'])
17
18 # Save to file
19 graph_filename = 'dataset_name.pklz' # name you want to use for your dataset
20 g.write_picklez(os.path.join(dataset_dir, graph_filename))
Dataset info¶
Create dataset info file as follows:
1 import pickle
2
3 dataset_info = {'gname': graph_filename,
4 'L': 1,
5 'N': g.vcount(),
6 'T': len(timesteps),
7 'timesteps': timesteps
8 }
9
10 dataset_info_file = os.path.join(dataset_dir, 'dataset_info.pkl')
11 output = open(dataset_info_file, 'wb')
12 pickle.dump(dataset_info, output)
Note: timesteps
is a list of possible timesteps in case they are not sequential (i.e., 1…T)
Output files¶
Parameters will be saved to path/to/dataset_directory/learned_parameters/model_params.msg