summaryrefslogtreecommitdiffstats
path: root/experiments/ml3.pyx
diff options
context:
space:
mode:
authorBen Green <ben@SEASITs-MacBook-Pro.local>2015-06-25 15:33:21 -0400
committerBen Green <ben@SEASITs-MacBook-Pro.local>2015-06-25 15:33:21 -0400
commitc8fc620dda6096932707566dc8f20a3e65cb26b0 (patch)
tree89062eaceca70f16eed0e9067648f5b71666ef45 /experiments/ml3.pyx
parent708a88f3b301851c9904d8bbf0656688d9bdb95f (diff)
downloadcriminal_cascades-c8fc620dda6096932707566dc8f20a3e65cb26b0.tar.gz
Tried ml3 that allows for multiple parents to infect.
Diffstat (limited to 'experiments/ml3.pyx')
-rw-r--r--experiments/ml3.pyx16
1 files changed, 9 insertions, 7 deletions
diff --git a/experiments/ml3.pyx b/experiments/ml3.pyx
index 49b24cf..faeda92 100644
--- a/experiments/ml3.pyx
+++ b/experiments/ml3.pyx
@@ -36,6 +36,7 @@ def ml3(dict root_victims, dict victims, dict non_victims, DTYPE_t age,
np.ndarray[DTYPE_t] probs_fail = np.zeros(n_victims, dtype=DTYPE)
np.ndarray[DTYPE_t] parent_dists = np.zeros(n_victims, dtype=DTYPE)
np.ndarray[DTYPE_t] parent_dts = np.zeros(n_victims, dtype=DTYPE)
+ np.ndarray[DTYPE_t] isSeed = np.ones(n_victims, dtype=DTYPE)
# loop through victims
for i, parents in enumerate(victims.itervalues()):
@@ -51,25 +52,26 @@ def ml3(dict root_victims, dict victims, dict non_victims, DTYPE_t age,
dts = [dt for (dist, dt, w1, w2, w3) in parents]
# find parent that maximizes log(p) - log(\tilde{p})
# probs[i] = max(s - failures[l] for l, s in enumerate(successes))
- probs[i] = float("-inf")
+ # probs[i] = 0.
for l, s in enumerate(successes):
prob = s - failures[l]
- if prob > probs[i]:
- probs[i] = prob
+ if prob > -19.523275053840013:
+ isSeed[i] = 0
+ probs[i] += prob
parent_dists[i] = dists[l]
parent_dts[i] = dts[l]
# probs_fail[i] = failures[l]
# calculate log likelihood
- ll = probs_fail.sum() # add probability that all edges to all victims fail
+ ll = probs_fail.sum() # add probability that all edges to all victims fail
# print 'probs', probs
max_beta_add = float('-inf')
# iterate over all victim nodes to find the optimal threshold
- for beta in np.arange(0.2, 1., .1):
+ for beta in np.arange(0.00001, 1., 1.):
thresh = log(beta/(3012.*(1.-beta)))
- seeds = probs<thresh
- non_seeds = probs>=thresh
+ seeds = isSeed==1
+ non_seeds = isSeed==0
roots = n_roots + sum(seeds)
beta_add = 0.