diff options
Diffstat (limited to 'experiments/ml.pyx')
| -rw-r--r-- | experiments/ml.pyx | 20 |
1 files changed, 14 insertions, 6 deletions
diff --git a/experiments/ml.pyx b/experiments/ml.pyx index 8dfea70..cc79609 100644 --- a/experiments/ml.pyx +++ b/experiments/ml.pyx @@ -13,11 +13,13 @@ 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""" cdef DTYPE_t structural, temporal, result - structural = dist * log(delta) + structural = delta ** dist # structural = plogis(w1,delta) * plogis(w2,delta) * plogis(w3,delta) - temporal = log(alpha) - alpha * dt + temporal = exp(-alpha*dt) * (exp(alpha)-1) + if exp(-alpha*dt)==0.: print 'UNDERFLOW ERROR' # temporal = 1. / (1. + (dt - 1.)/alpha)**0.01 - 1. / (1. + dt/alpha)**0.01 - result = structural + temporal + result = log(structural * temporal) + # print 'st', structural, temporal return result cdef DTYPE_t weight_failure(int dist, int dt, DTYPE_t alpha, DTYPE_t delta, @@ -26,9 +28,10 @@ cdef DTYPE_t weight_failure(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 = 1. - exp(-alpha * dt) + temporal = exp(-alpha * dt) # temporal = 1. - 1. / (1. + dt/alpha)**0.01 - result = log(1. - structural * temporal) + result = log(1. - structural + structural * temporal) + # print 'stnv', structural, temporal return result def ml(dict root_victims, dict victims, dict non_victims, DTYPE_t age, @@ -72,6 +75,7 @@ def ml(dict root_victims, dict victims, dict non_victims, DTYPE_t age, 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_i = -1 max_beta_add = float('-inf') # iterate over all victim nodes to find the optimal threshold @@ -79,16 +83,20 @@ def ml(dict root_victims, dict victims, dict non_victims, DTYPE_t age, roots = n_roots + n_victims - i beta = float(roots)/float(n_nodes) thresh = log(beta/(1.-beta)) + # print 'thresh:', thresh # add probability for realized edges and subtract probability these edges fail beta_add = (probs[probs>thresh]).sum() - print len(probs[probs>thresh]) + # print 'len(probs[probs>thresh]):', len(probs[probs>thresh]) # add probability for the seeds and non-seeds beta_add += roots * log(beta) + (n_nodes-roots) * log(1 - beta) if beta_add > max_beta_add: max_i = i max_beta_add = beta_add + print max_i, max_beta_add + else: + print i ll += max_beta_add roots = n_roots + n_victims - max_i |
