diff options
Diffstat (limited to 'experiments/ml3.pyx')
| -rw-r--r-- | experiments/ml3.pyx | 21 |
1 files changed, 7 insertions, 14 deletions
diff --git a/experiments/ml3.pyx b/experiments/ml3.pyx index 5cbe3ba..49b24cf 100644 --- a/experiments/ml3.pyx +++ b/experiments/ml3.pyx @@ -11,13 +11,8 @@ cdef DTYPE_t weight_success(int dist, int dt, DTYPE_t alpha, DTYPE_t delta, """weight for successful infection, exponential time model""" cdef DTYPE_t structural, temporal, result structural = delta ** dist - # structural = plogis(w1,delta) * plogis(w2,delta) * plogis(w3,delta) temporal = log(exp(alpha)-1.) - alpha*dt - # 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 - # print 'st', structural, temporal return result cdef DTYPE_t weight_failure(int dist, int dt, DTYPE_t alpha, DTYPE_t delta, @@ -25,11 +20,8 @@ cdef DTYPE_t weight_failure(int dist, int dt, DTYPE_t alpha, DTYPE_t delta, """weight for failed infection, exponential time model""" cdef DTYPE_t structural, temporal, result structural = delta ** dist - # 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) - # print 'stnv', structural, temporal + result = log(1. - structural + structural * temporal) return result def ml3(dict root_victims, dict victims, dict non_victims, DTYPE_t age, @@ -74,16 +66,17 @@ def ml3(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.2, 1., 1.): + for beta in np.arange(0.2, 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]) + seeds = probs<thresh + non_seeds = probs>=thresh + roots = n_roots + sum(seeds) beta_add = 0. # add probability for realized edges and subtract probability these edges fail - beta_add += (probs[probs>=thresh]).sum() + beta_add += (probs[non_seeds]).sum() # add probability for the seeds and non-seeds - beta_add += roots * log(beta/3012.) + len(probs[probs>=thresh]) * log(1. - beta) + beta_add += roots * log(beta/3012.) + sum(non_seeds) * log(1. - beta) if beta_add > max_beta_add: max_beta = beta |
