From e5dada202c34521618bf82a086093c342841e5e8 Mon Sep 17 00:00:00 2001 From: Thibaut Horel Date: Sun, 7 Jun 2015 22:23:39 -0700 Subject: Project cleanup before handing it to Ben --- experiments/process.py | 48 +++++++++++------------------------------------- 1 file changed, 11 insertions(+), 37 deletions(-) (limited to 'experiments/process.py') diff --git a/experiments/process.py b/experiments/process.py index b5b70ca..5fc55ba 100644 --- a/experiments/process.py +++ b/experiments/process.py @@ -1,51 +1,25 @@ -from csv import DictReader import sys from ml import ml import numpy as np -from cPickle import dump, load +from cPickle import load from itertools import product +from math import exp -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"]), 3012 - 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 +def print_ll(alpha, delta): + beta, roots, ll = ml(root_victims, victims, non_victims, alpha, delta) + print "\t".join(map(str, [alpha, delta, beta, roots, ll, exp(ll)])) + "\n" 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")) + if len(sys.argv) < 2: + sys.exit("usage: {0} ".format(sys.argv[0])) - alpha = np.arange(0.0000005, 0.00000051, 0.000001) - delta = np.arange(1., 1.000001, 0.001) + root_victims, victims, non_victims, age = load(open(sys.argv[1])) + alpha = 1. / np.arange(1., 1000., 10.) # parameter of the time component + delta = np.arange(0.01, 0.9, 0.03) # parameter of the structural component 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) + beta, roots, ll = ml(root_victims, victims, non_victims, age, a, d) fh.write("\t".join(map(str, [a, d, beta, roots, ll])) + "\n") fh.flush() -- cgit v1.2.3-70-g09d2