From 0b0d26b2c0ed7d6f0b69f550f6584dabae184ba1 Mon Sep 17 00:00:00 2001 From: Thibaut Horel Date: Sun, 23 Aug 2015 03:47:58 -0700 Subject: Code for hawkes model --- hawkes/cause.py | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 hawkes/cause.py (limited to 'hawkes/cause.py') diff --git a/hawkes/cause.py b/hawkes/cause.py new file mode 100644 index 0000000..0cce9d2 --- /dev/null +++ b/hawkes/cause.py @@ -0,0 +1,24 @@ +from cPickle import load +from math import exp + + +def main(a): + lamb, alpha, mu = a + dr = 0 + r = 0 + for ((n1, t1), s) in event_edges.iteritems(): + if not s: + dr += 1 + if lamb > sum(alpha * w * mu * exp(-mu * (t1 - t2)) + for (n2, t2, w) in s): + r += 1 + return lamb, alpha, mu, dr, r + + +if __name__ == "__main__": + nodes, edges, events, event_edges = load(open("data.pickle", "rb")) + for i, line in enumerate(open("values-sorted.txt")): + if i > 100: + break + lamb, alpha, mu, v = map(float, line.strip().split()) + print main((lamb, alpha, mu)) -- cgit v1.2.3-70-g09d2