summaryrefslogtreecommitdiffstats
path: root/experiments/process.py
diff options
context:
space:
mode:
authorThibaut Horel <thibaut.horel@gmail.com>2015-06-07 22:23:39 -0700
committerThibaut Horel <thibaut.horel@gmail.com>2015-06-07 22:23:39 -0700
commite5dada202c34521618bf82a086093c342841e5e8 (patch)
treedd7c640ed2bd77ce5e6b0ae050e6662c21cc3b43 /experiments/process.py
parenta29d738721db46b0ca3b7b5b3ffd282ad3f25909 (diff)
downloadcriminal_cascades-e5dada202c34521618bf82a086093c342841e5e8.tar.gz
Project cleanup before handing it to Ben
Diffstat (limited to 'experiments/process.py')
-rw-r--r--experiments/process.py48
1 files changed, 11 insertions, 37 deletions
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} <file>".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()