summaryrefslogtreecommitdiffstats
path: root/experiments/process.py
blob: 1ec917e79b4ab0af5e0f85a6f92bda9cb4c3cb79 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
from csv import DictReader
import sys
from ml import ml
import numpy as np
from cPickle import dump, load
from itertools import product


def build_network(filename):
    victims = {}
    non_victims = {}
    with open(filename) as fh:
        reader = DictReader(fh)
        for row in reader:
            from_, to = int(float(row["from"])), int(float(row["to"]))
            if row["t2"] != "NA":
                dt = int(row["t2"]) - int(row["t1"])
                parent = (int(row["dist"]), dt)
                if to not in victims:
                    victims[to] = []
                victims[to].append(parent)
                if from_ not in victims:
                    victims[from_] = []
            else:
                from_, to = int(float(row["from"])), int(float(row["to"]))
                parent = (int(row["dist"]), int(row["t1"]))
                if to not in victims:
                    non_victims[to] = []
                non_victims[to].append(parent)
                if from_ not in victims:
                    victims[from_] = []
    root_victims = {}
    for victim in victims.keys():
        if not victims[victim]:
            del victims[victim]
        root_victims[victim] = []
    return root_victims, victims, non_victims


if __name__ == "__main__":
    #root_victims, victims, non_victims = build_network(sys.argv[1])
    #dump((root_victims, victims, non_victims), open("network.pickle", "w"))
    root_victims, victims, non_victims = load(open("network.pickle"))

    alpha = np.arange(1000006., 1000007., 1.)
    delta = np.arange(0.1, 1., 0.01)
    with open("out.log", "a") as fh:
        for a, d in product(alpha, delta):
            beta, roots, ll = ml(root_victims, victims, non_victims, a, d)
            fh.write("\t".join(map(str, [a, d, beta, roots, ll])) + "\n")