summaryrefslogtreecommitdiffstats
path: root/experiments/ml3.pyx
diff options
context:
space:
mode:
authorBen Green <ben@SEASITs-MacBook-Pro.local>2015-06-23 11:55:17 -0400
committerBen Green <ben@SEASITs-MacBook-Pro.local>2015-06-23 11:55:17 -0400
commitaa081ff0ddadfcfdcfc4b61af9845760a463e4cc (patch)
treef1005aaa3e62d2b01d5c042b9342576b952e5f81 /experiments/ml3.pyx
parentd99879dc3d6839b00f4b325320fe2b992391b915 (diff)
downloadcriminal_cascades-aa081ff0ddadfcfdcfc4b61af9845760a463e4cc.tar.gz
updated calculation of structural component with edge weights, and to
penalize less for longer distances
Diffstat (limited to 'experiments/ml3.pyx')
-rw-r--r--experiments/ml3.pyx22
1 files changed, 3 insertions, 19 deletions
diff --git a/experiments/ml3.pyx b/experiments/ml3.pyx
index d7f7ff1..1f46ef5 100644
--- a/experiments/ml3.pyx
+++ b/experiments/ml3.pyx
@@ -6,9 +6,6 @@ from libc.math cimport log, exp
DTYPE = np.float64
ctypedef np.float_t DTYPE_t
-cdef DTYPE_t plogis(DTYPE_t weight, DTYPE_t delta):
- return 1./(1. + exp(-weight/delta))
-
cdef DTYPE_t weight_success(int dist, int dt, DTYPE_t alpha, DTYPE_t delta,
DTYPE_t w1, DTYPE_t w2, DTYPE_t w3):
"""weight for successful infection, exponential time model"""
@@ -32,22 +29,20 @@ cdef DTYPE_t weight_failure(int dist, int dt, DTYPE_t alpha, DTYPE_t delta,
# structural = plogis(w1,delta) * plogis(w2,delta) * plogis(w3,delta)
temporal = exp(-alpha * dt)
# temporal = 1. - 1. / (1. + dt/alpha)**0.01
- result = log(1. - structural + structural * temporal)
+ result = log(1. - structural)
# print 'stnv', structural, temporal
return result
def ml3(dict root_victims, dict victims, dict non_victims, DTYPE_t age,
DTYPE_t alpha, DTYPE_t delta):
cdef:
- int n_roots, n_victims, n_nodes, roots, i, dist, dt, t, l
+ int n_roots, n_victims, roots, i, dist, dt, t, l
DTYPE_t beta, ll, beta_add, max_beta, max_beta_add
list parents, failures, successes
n_roots, n_victims = len(root_victims), len(victims)
- n_nodes = 148152
cdef:
np.ndarray[DTYPE_t] probs = np.zeros(n_victims, dtype=DTYPE)
np.ndarray[DTYPE_t] probs_fail = np.zeros(n_victims, dtype=DTYPE)
- np.ndarray[DTYPE_t] probs_nv = np.zeros(len(non_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)
@@ -74,29 +69,18 @@ def ml3(dict root_victims, dict victims, dict non_victims, DTYPE_t age,
parent_dts[i] = dts[l]
probs_fail[i] = failures[l]
- # 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)
-
# print successes
# print failures
# print probs
# calculate log likelihood
- # probs.sort(); probs = probs[::-1] # sort probs in descending order
- # cdef:
- # np.ndarray[DTYPE_t] cums = probs.cumsum()
ll = probs_fail.sum() # add probability that all edges to victims fail
# ll += probs_nv.sum() # add probability that all edges to non_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.09, 1., .05):
+ for beta in np.arange(0.1, 1., .1):
thresh = log(beta/(3012.*(1.-beta)))
# print 'beta:', beta, 'thresh:', thresh, 'infected:', len(probs[probs>=thresh])
roots = n_roots + len(probs[probs<thresh])