diff options
| author | Ben Green <ben@SEASITs-MacBook-Pro.local> | 2015-06-20 10:13:23 -0400 |
|---|---|---|
| committer | Ben Green <ben@SEASITs-MacBook-Pro.local> | 2015-06-20 10:13:23 -0400 |
| commit | f2891c93b96388442d44512e6c43b092153f8c25 (patch) | |
| tree | f85236ec90e1524a63731aec2ddbe017ab233fe5 /experiments/ml.pyx | |
| parent | 958c31ca10c4eed08da818b9e16d84ebfeb44c27 (diff) | |
| download | criminal_cascades-f2891c93b96388442d44512e6c43b092153f8c25.tar.gz | |
tried generating cascades and recovering parameters, still got the same
result where optimization minimizes alpha, delta as much as possible
Diffstat (limited to 'experiments/ml.pyx')
| -rw-r--r-- | experiments/ml.pyx | 26 |
1 files changed, 15 insertions, 11 deletions
diff --git a/experiments/ml.pyx b/experiments/ml.pyx index 67b561c..e1ce4cf 100644 --- a/experiments/ml.pyx +++ b/experiments/ml.pyx @@ -15,8 +15,8 @@ cdef DTYPE_t weight_success(int dist, int dt, DTYPE_t alpha, DTYPE_t delta, cdef DTYPE_t structural, temporal, result structural = delta ** dist # structural = plogis(w1,delta) * plogis(w2,delta) * plogis(w3,delta) - # temporal = exp(-alpha*dt) * (exp(alpha)-1) - temporal = 1 - exp(-alpha*dt) + temporal = exp(-alpha*dt) * (exp(alpha)-1.) + # temporal = 1 - exp(-alpha*dt) if exp(-alpha*dt)==0.: print 'UNDERFLOW ERROR' # temporal = 1. / (1. + (dt - 1.)/alpha)**0.01 - 1. / (1. + dt/alpha)**0.01 result = log(structural * temporal) @@ -42,7 +42,7 @@ def ml(dict root_victims, dict victims, dict non_victims, DTYPE_t age, DTYPE_t beta, ll list parents, failures, successes n_roots, n_victims = len(root_victims), len(victims) - n_nodes = 11270 + n_nodes = 100 cdef: np.ndarray[DTYPE_t] probs = np.zeros(n_victims, dtype=DTYPE) np.ndarray[DTYPE_t] probs_fail = np.zeros(n_victims, dtype=DTYPE) @@ -62,12 +62,16 @@ def ml(dict root_victims, dict victims, dict non_victims, DTYPE_t age, probs[i] = max(s - failures[l] for l, s in enumerate(successes)) # loop through non-victims - # for i, parents in enumerate(non_victims.itervalues()): - # # for each non victim node, compute the probability that all its - # # parents fail to infect it - # failures = [weight_failure(dist, dt, alpha, delta, w1, w2, w3) - # for (dist, dt, w1, w2, w3) in parents] - # probs_nv[i] = sum(failures) + for i, parents in enumerate(non_victims.itervalues()): + # for each non victim node, compute the probability that all its + # parents fail to infect it + failures = [weight_failure(dist, dt, alpha, delta, w1, w2, w3) + for (dist, dt, w1, w2, w3) in parents] + probs_nv[i] = sum(failures) + + # print successes + # print failures + # print probs # calculate log likelihood # probs.sort(); probs = probs[::-1] # sort probs in descending order @@ -79,7 +83,7 @@ def ml(dict root_victims, dict victims, dict non_victims, DTYPE_t age, # print 'probs', probs max_beta_add = float('-inf') # iterate over all victim nodes to find the optimal threshold - for beta in np.arange(0.001, .1, .001): + for beta in [0.13]:#np.arange(0.001, .2, .002): thresh = log(beta/(1.-beta)) # print 'beta:', beta, 'thresh:', thresh, 'infected:', len(probs[probs>=thresh]) roots = n_roots + len(probs[probs<thresh]) @@ -87,7 +91,7 @@ def ml(dict root_victims, dict victims, dict non_victims, DTYPE_t age, # add probability for realized edges and subtract probability these edges fail beta_add = (probs[probs>=thresh]).sum() # add probability for the seeds and non-seeds - beta_add += roots * log(beta) + (n_nodes-roots) * log(1 - beta) + beta_add += roots * log(beta) + (n_nodes-roots) * log(1. - beta) if beta_add > max_beta_add: max_beta = beta |
