summaryrefslogtreecommitdiffstats
path: root/experiments/ml.pyx
diff options
context:
space:
mode:
Diffstat (limited to 'experiments/ml.pyx')
-rw-r--r--experiments/ml.pyx18
1 files changed, 10 insertions, 8 deletions
diff --git a/experiments/ml.pyx b/experiments/ml.pyx
index cc79609..853c934 100644
--- a/experiments/ml.pyx
+++ b/experiments/ml.pyx
@@ -19,7 +19,7 @@ cdef DTYPE_t weight_success(int dist, int dt, DTYPE_t alpha, DTYPE_t delta,
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
+ print 'st', structural, temporal
return result
cdef DTYPE_t weight_failure(int dist, int dt, DTYPE_t alpha, DTYPE_t delta,
@@ -31,7 +31,7 @@ cdef DTYPE_t weight_failure(int dist, int dt, DTYPE_t alpha, DTYPE_t delta,
temporal = exp(-alpha * dt)
# temporal = 1. - 1. / (1. + dt/alpha)**0.01
result = log(1. - structural + structural * temporal)
- # print 'stnv', structural, temporal
+ print 'stnv', structural, temporal
return result
def ml(dict root_victims, dict victims, dict non_victims, DTYPE_t age,
@@ -41,7 +41,7 @@ def ml(dict root_victims, dict victims, dict non_victims, DTYPE_t age,
DTYPE_t beta, ll, beta2
list parents, failures, successes
n_roots, n_victims = len(root_victims), len(victims)
- n_nodes = 148152
+ n_nodes = 4#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)
@@ -80,21 +80,23 @@ def ml(dict root_victims, dict victims, dict non_victims, DTYPE_t age,
max_beta_add = float('-inf')
# iterate over all victim nodes to find the optimal threshold
for i in xrange(0, n_victims+1, 1):
+ print
roots = n_roots + n_victims - i
- beta = float(roots)/float(n_nodes)
+ beta = 1. / (1. + exp(-probs[i]))
+ # beta = float(roots)/float(n_nodes)
thresh = log(beta/(1.-beta))
- # print 'thresh:', thresh
+ 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]):', len(probs[probs>thresh])
+ beta_add = (probs[probs>=thresh]).sum()
+ 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
+ print 'i:', max_i, 'add:', max_beta_add, 'roots:', roots
else:
print i