summaryrefslogtreecommitdiffstats
path: root/hawkes/cause.py
blob: 0cce9d2691e4a3d7e953a2ab5a072a0fb1d0c355 (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
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))