diff options
| author | Thibaut Horel <thibaut.horel@gmail.com> | 2015-08-23 03:47:58 -0700 |
|---|---|---|
| committer | Thibaut Horel <thibaut.horel@gmail.com> | 2015-08-23 03:47:58 -0700 |
| commit | 0b0d26b2c0ed7d6f0b69f550f6584dabae184ba1 (patch) | |
| tree | b21a4b25d907d8106ce4189d8a770acd6abe457f /hawkes/cause.py | |
| parent | ef61ece9773e8a865b57f60ca1e1b9faa903af23 (diff) | |
| download | criminal_cascades-0b0d26b2c0ed7d6f0b69f550f6584dabae184ba1.tar.gz | |
Code for hawkes model
Diffstat (limited to 'hawkes/cause.py')
| -rw-r--r-- | hawkes/cause.py | 24 |
1 files changed, 24 insertions, 0 deletions
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)) |
