summaryrefslogtreecommitdiffstats
path: root/experiments/ml.c
diff options
context:
space:
mode:
Diffstat (limited to 'experiments/ml.c')
-rw-r--r--experiments/ml.c772
1 files changed, 425 insertions, 347 deletions
diff --git a/experiments/ml.c b/experiments/ml.c
index 67e5cd1..1ae9098 100644
--- a/experiments/ml.c
+++ b/experiments/ml.c
@@ -773,12 +773,12 @@ struct __pyx_obj_2ml___pyx_scope_struct__ml {
};
-/* "ml.pyx":71
- * successes = [weight_success(dist, dt, alpha, delta, gamma)
- * for (dist, dt) in parents]
+/* "ml.pyx":74
+ * for (dist, dt, w1, w2, w3) in parents]
+ * # find parent that maximizes p/\tilde{p}
* probs[i] = max(s - failures[l] for l, s in enumerate(successes)) # <<<<<<<<<<<<<<
- * probs_fail[i] = all_failures
*
+ * # loop through non-victims
*/
struct __pyx_obj_2ml___pyx_scope_struct_1_genexpr {
PyObject_HEAD
@@ -1284,6 +1284,9 @@ static char __pyx_k_dt[] = "dt";
static char __pyx_k_ll[] = "ll";
static char __pyx_k_ml[] = "ml";
static char __pyx_k_np[] = "np";
+static char __pyx_k_w1[] = "w1";
+static char __pyx_k_w2[] = "w2";
+static char __pyx_k_w3[] = "w3";
static char __pyx_k_age[] = "age";
static char __pyx_k_end[] = "end";
static char __pyx_k_max[] = "max";
@@ -1331,7 +1334,6 @@ static char __pyx_k_itervalues[] = "itervalues";
static char __pyx_k_probs_fail[] = "probs_fail";
static char __pyx_k_non_victims[] = "non_victims";
static char __pyx_k_RuntimeError[] = "RuntimeError";
-static char __pyx_k_all_failures[] = "all_failures";
static char __pyx_k_root_victims[] = "root_victims";
static char __pyx_k_ml_locals_genexpr[] = "ml.<locals>.genexpr";
static char __pyx_k_ndarray_is_not_C_contiguous[] = "ndarray is not C contiguous";
@@ -1350,7 +1352,6 @@ static PyObject *__pyx_n_s_RuntimeError;
static PyObject *__pyx_kp_s_Users_ben_Documents_Cascade_Pro;
static PyObject *__pyx_n_s_ValueError;
static PyObject *__pyx_n_s_age;
-static PyObject *__pyx_n_s_all_failures;
static PyObject *__pyx_n_s_alpha;
static PyObject *__pyx_kp_s_alpha_0_delta_1_Everyone_is_a_ro;
static PyObject *__pyx_n_s_args;
@@ -1405,6 +1406,9 @@ static PyObject *__pyx_n_s_test;
static PyObject *__pyx_n_s_throw;
static PyObject *__pyx_kp_u_unknown_dtype_code_in_numpy_pxd;
static PyObject *__pyx_n_s_victims;
+static PyObject *__pyx_n_s_w1;
+static PyObject *__pyx_n_s_w2;
+static PyObject *__pyx_n_s_w3;
static PyObject *__pyx_n_s_xrange;
static PyObject *__pyx_n_s_zeros;
static PyObject *__pyx_int_neg_1;
@@ -1815,12 +1819,12 @@ static PyObject *__pyx_pw_2ml_1ml(PyObject *__pyx_self, PyObject *__pyx_args, Py
}
static PyObject *__pyx_gb_2ml_2ml_2generator(__pyx_GeneratorObject *__pyx_generator, PyObject *__pyx_sent_value); /* proto */
-/* "ml.pyx":71
- * successes = [weight_success(dist, dt, alpha, delta, gamma)
- * for (dist, dt) in parents]
+/* "ml.pyx":74
+ * for (dist, dt, w1, w2, w3) in parents]
+ * # find parent that maximizes p/\tilde{p}
* probs[i] = max(s - failures[l] for l, s in enumerate(successes)) # <<<<<<<<<<<<<<
- * probs_fail[i] = all_failures
*
+ * # loop through non-victims
*/
static PyObject *__pyx_pf_2ml_2ml_genexpr(PyObject *__pyx_self) {
@@ -1841,7 +1845,7 @@ static PyObject *__pyx_pf_2ml_2ml_genexpr(PyObject *__pyx_self) {
__Pyx_INCREF(((PyObject *)__pyx_cur_scope->__pyx_outer_scope));
__Pyx_GIVEREF(__pyx_cur_scope->__pyx_outer_scope);
{
- __pyx_GeneratorObject *gen = __Pyx_Generator_New((__pyx_generator_body_t) __pyx_gb_2ml_2ml_2generator, (PyObject *) __pyx_cur_scope, __pyx_n_s_genexpr, __pyx_n_s_ml_locals_genexpr); if (unlikely(!gen)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 71; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_GeneratorObject *gen = __Pyx_Generator_New((__pyx_generator_body_t) __pyx_gb_2ml_2ml_2generator, (PyObject *) __pyx_cur_scope, __pyx_n_s_genexpr, __pyx_n_s_ml_locals_genexpr); if (unlikely(!gen)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 74; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_DECREF(__pyx_cur_scope);
__Pyx_RefNannyFinishContext();
return (PyObject *) gen;
@@ -1879,16 +1883,16 @@ static PyObject *__pyx_gb_2ml_2ml_2generator(__pyx_GeneratorObject *__pyx_genera
return NULL;
}
__pyx_L3_first_run:;
- if (unlikely(!__pyx_sent_value)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 71; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ if (unlikely(!__pyx_sent_value)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 74; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__pyx_t_1 = 0;
- if (unlikely(!__pyx_cur_scope->__pyx_outer_scope->__pyx_v_successes)) { __Pyx_RaiseClosureNameError("successes"); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 71; __pyx_clineno = __LINE__; goto __pyx_L1_error;} }
+ if (unlikely(!__pyx_cur_scope->__pyx_outer_scope->__pyx_v_successes)) { __Pyx_RaiseClosureNameError("successes"); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 74; __pyx_clineno = __LINE__; goto __pyx_L1_error;} }
__pyx_t_2 = __pyx_cur_scope->__pyx_outer_scope->__pyx_v_successes; __Pyx_INCREF(__pyx_t_2); __pyx_t_3 = 0;
for (;;) {
if (__pyx_t_3 >= PyList_GET_SIZE(__pyx_t_2)) break;
#if CYTHON_COMPILING_IN_CPYTHON
- __pyx_t_4 = PyList_GET_ITEM(__pyx_t_2, __pyx_t_3); __Pyx_INCREF(__pyx_t_4); __pyx_t_3++; if (unlikely(0 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 71; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_4 = PyList_GET_ITEM(__pyx_t_2, __pyx_t_3); __Pyx_INCREF(__pyx_t_4); __pyx_t_3++; if (unlikely(0 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 74; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
#else
- __pyx_t_4 = PySequence_ITEM(__pyx_t_2, __pyx_t_3); __pyx_t_3++; if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 71; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_4 = PySequence_ITEM(__pyx_t_2, __pyx_t_3); __pyx_t_3++; if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 74; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
#endif
__Pyx_XGOTREF(__pyx_cur_scope->__pyx_v_s);
__Pyx_XDECREF_SET(__pyx_cur_scope->__pyx_v_s, __pyx_t_4);
@@ -1896,14 +1900,14 @@ static PyObject *__pyx_gb_2ml_2ml_2generator(__pyx_GeneratorObject *__pyx_genera
__pyx_t_4 = 0;
__pyx_cur_scope->__pyx_v_l = __pyx_t_1;
__pyx_t_1 = (__pyx_t_1 + 1);
- if (unlikely(!__pyx_cur_scope->__pyx_outer_scope->__pyx_v_failures)) { __Pyx_RaiseClosureNameError("failures"); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 71; __pyx_clineno = __LINE__; goto __pyx_L1_error;} }
+ if (unlikely(!__pyx_cur_scope->__pyx_outer_scope->__pyx_v_failures)) { __Pyx_RaiseClosureNameError("failures"); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 74; __pyx_clineno = __LINE__; goto __pyx_L1_error;} }
if (unlikely(__pyx_cur_scope->__pyx_outer_scope->__pyx_v_failures == Py_None)) {
PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable");
- {__pyx_filename = __pyx_f[0]; __pyx_lineno = 71; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ {__pyx_filename = __pyx_f[0]; __pyx_lineno = 74; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
}
- __pyx_t_4 = __Pyx_GetItemInt_List(__pyx_cur_scope->__pyx_outer_scope->__pyx_v_failures, __pyx_cur_scope->__pyx_v_l, Py_ssize_t, 1, PyInt_FromSsize_t, 1, 1, 0); if (unlikely(__pyx_t_4 == NULL)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 71; __pyx_clineno = __LINE__; goto __pyx_L1_error;};
+ __pyx_t_4 = __Pyx_GetItemInt_List(__pyx_cur_scope->__pyx_outer_scope->__pyx_v_failures, __pyx_cur_scope->__pyx_v_l, Py_ssize_t, 1, PyInt_FromSsize_t, 1, 1, 0); if (unlikely(__pyx_t_4 == NULL)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 74; __pyx_clineno = __LINE__; goto __pyx_L1_error;};
__Pyx_GOTREF(__pyx_t_4);
- __pyx_t_5 = PyNumber_Subtract(__pyx_cur_scope->__pyx_v_s, __pyx_t_4); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 71; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_5 = PyNumber_Subtract(__pyx_cur_scope->__pyx_v_s, __pyx_t_4); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 74; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(__pyx_t_5);
__Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
__pyx_r = __pyx_t_5;
@@ -1923,7 +1927,7 @@ static PyObject *__pyx_gb_2ml_2ml_2generator(__pyx_GeneratorObject *__pyx_genera
__pyx_cur_scope->__pyx_t_1 = 0;
__Pyx_XGOTREF(__pyx_t_2);
__pyx_t_3 = __pyx_cur_scope->__pyx_t_2;
- if (unlikely(!__pyx_sent_value)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 71; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ if (unlikely(!__pyx_sent_value)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 74; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
}
__Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
@@ -1961,13 +1965,15 @@ static PyObject *__pyx_pf_2ml_ml(CYTHON_UNUSED PyObject *__pyx_self, PyObject *_
int __pyx_v_dist;
int __pyx_v_dt;
__pyx_t_2ml_DTYPE_t __pyx_v_beta;
- __pyx_t_2ml_DTYPE_t __pyx_v_all_failures;
__pyx_t_2ml_DTYPE_t __pyx_v_ll;
PyObject *__pyx_v_parents = 0;
PyArrayObject *__pyx_v_probs = 0;
PyArrayObject *__pyx_v_probs_fail = 0;
PyArrayObject *__pyx_v_probs_nv = 0;
PyArrayObject *__pyx_v_cums = 0;
+ CYTHON_UNUSED PyObject *__pyx_v_w1 = NULL;
+ CYTHON_UNUSED PyObject *__pyx_v_w2 = NULL;
+ CYTHON_UNUSED PyObject *__pyx_v_w3 = NULL;
__Pyx_LocalBuf_ND __pyx_pybuffernd_cums;
__Pyx_Buffer __pyx_pybuffer_cums;
__Pyx_LocalBuf_ND __pyx_pybuffernd_probs;
@@ -1994,16 +2000,19 @@ static PyObject *__pyx_pf_2ml_ml(CYTHON_UNUSED PyObject *__pyx_self, PyObject *_
PyObject *__pyx_t_14 = NULL;
PyObject *__pyx_t_15 = NULL;
PyObject *__pyx_t_16 = NULL;
- PyObject *(*__pyx_t_17)(PyObject *);
- int __pyx_t_18;
- __pyx_t_2ml_DTYPE_t __pyx_t_19;
- int __pyx_t_20;
+ PyObject *__pyx_t_17 = NULL;
+ PyObject *__pyx_t_18 = NULL;
+ PyObject *__pyx_t_19 = NULL;
+ PyObject *(*__pyx_t_20)(PyObject *);
int __pyx_t_21;
- PyObject *__pyx_t_22 = NULL;
- PyObject *__pyx_t_23 = NULL;
- PyObject *__pyx_t_24 = NULL;
- PyArrayObject *__pyx_t_25 = NULL;
- int __pyx_t_26;
+ __pyx_t_2ml_DTYPE_t __pyx_t_22;
+ int __pyx_t_23;
+ int __pyx_t_24;
+ PyObject *__pyx_t_25 = NULL;
+ PyObject *__pyx_t_26 = NULL;
+ PyObject *__pyx_t_27 = NULL;
+ PyArrayObject *__pyx_t_28 = NULL;
+ int __pyx_t_29;
int __pyx_lineno = 0;
const char *__pyx_filename = NULL;
int __pyx_clineno = 0;
@@ -2032,10 +2041,10 @@ static PyObject *__pyx_pf_2ml_ml(CYTHON_UNUSED PyObject *__pyx_self, PyObject *_
__pyx_pybuffernd_cums.rcbuffer = &__pyx_pybuffer_cums;
/* "ml.pyx":56
- * DTYPE_t beta, all_failures, ll, beta2
+ * DTYPE_t beta, ll, beta2
* list parents, failures, successes
* n_roots, n_victims = len(root_victims), len(victims) # <<<<<<<<<<<<<<
- * n_nodes = n_victims + len(non_victims) + n_roots
+ * n_nodes = n_roots + n_victims + len(non_victims)
* cdef:
*/
if (unlikely(__pyx_v_root_victims == Py_None)) {
@@ -2054,7 +2063,7 @@ static PyObject *__pyx_pf_2ml_ml(CYTHON_UNUSED PyObject *__pyx_self, PyObject *_
/* "ml.pyx":57
* list parents, failures, successes
* n_roots, n_victims = len(root_victims), len(victims)
- * n_nodes = n_victims + len(non_victims) + n_roots # <<<<<<<<<<<<<<
+ * n_nodes = n_roots + n_victims + len(non_victims) # <<<<<<<<<<<<<<
* cdef:
* np.ndarray[DTYPE_t] probs = np.zeros(n_victims, dtype=DTYPE)
*/
@@ -2063,10 +2072,10 @@ static PyObject *__pyx_pf_2ml_ml(CYTHON_UNUSED PyObject *__pyx_self, PyObject *_
{__pyx_filename = __pyx_f[0]; __pyx_lineno = 57; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
}
__pyx_t_2 = PyDict_Size(__pyx_v_non_victims); if (unlikely(__pyx_t_2 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 57; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __pyx_v_n_nodes = ((__pyx_v_n_victims + __pyx_t_2) + __pyx_v_n_roots);
+ __pyx_v_n_nodes = ((__pyx_v_n_roots + __pyx_v_n_victims) + __pyx_t_2);
/* "ml.pyx":59
- * n_nodes = n_victims + len(non_victims) + n_roots
+ * n_nodes = n_roots + n_victims + len(non_victims)
* cdef:
* np.ndarray[DTYPE_t] probs = np.zeros(n_victims, dtype=DTYPE) # <<<<<<<<<<<<<<
* np.ndarray[DTYPE_t] probs_fail = np.zeros(n_victims, dtype=DTYPE)
@@ -2114,7 +2123,7 @@ static PyObject *__pyx_pf_2ml_ml(CYTHON_UNUSED PyObject *__pyx_self, PyObject *_
* 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)
- * for i, parents in enumerate(victims.itervalues()):
+ *
*/
__pyx_t_6 = __Pyx_GetModuleGlobalName(__pyx_n_s_np); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 60; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(__pyx_t_6);
@@ -2157,8 +2166,8 @@ static PyObject *__pyx_pf_2ml_ml(CYTHON_UNUSED PyObject *__pyx_self, PyObject *_
* 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) # <<<<<<<<<<<<<<
- * for i, parents in enumerate(victims.itervalues()):
- * # for each victim node i, compute the probability that all its parents
+ *
+ * # loop through victims
*/
__pyx_t_4 = __Pyx_GetModuleGlobalName(__pyx_n_s_np); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 61; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(__pyx_t_4);
@@ -2202,9 +2211,9 @@ static PyObject *__pyx_pf_2ml_ml(CYTHON_UNUSED PyObject *__pyx_self, PyObject *_
__pyx_v_probs_nv = ((PyArrayObject *)__pyx_t_3);
__pyx_t_3 = 0;
- /* "ml.pyx":62
- * 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)
+ /* "ml.pyx":64
+ *
+ * # loop through victims
* for i, parents in enumerate(victims.itervalues()): # <<<<<<<<<<<<<<
* # for each victim node i, compute the probability that all its parents
* # fail to infect it, also computes the probability that its most
@@ -2213,9 +2222,9 @@ static PyObject *__pyx_pf_2ml_ml(CYTHON_UNUSED PyObject *__pyx_self, PyObject *_
__pyx_t_2 = 0;
if (unlikely(__pyx_v_victims == Py_None)) {
PyErr_Format(PyExc_AttributeError, "'NoneType' object has no attribute '%s'", "itervalues");
- {__pyx_filename = __pyx_f[0]; __pyx_lineno = 62; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ {__pyx_filename = __pyx_f[0]; __pyx_lineno = 64; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
}
- __pyx_t_4 = __Pyx_dict_iterator(__pyx_v_victims, 1, __pyx_n_s_itervalues, (&__pyx_t_1), (&__pyx_t_11)); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 62; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_4 = __Pyx_dict_iterator(__pyx_v_victims, 1, __pyx_n_s_itervalues, (&__pyx_t_1), (&__pyx_t_11)); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 64; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(__pyx_t_4);
__Pyx_XDECREF(__pyx_t_3);
__pyx_t_3 = __pyx_t_4;
@@ -2223,42 +2232,42 @@ static PyObject *__pyx_pf_2ml_ml(CYTHON_UNUSED PyObject *__pyx_self, PyObject *_
while (1) {
__pyx_t_12 = __Pyx_dict_iter_next(__pyx_t_3, __pyx_t_1, &__pyx_t_2, NULL, &__pyx_t_4, NULL, __pyx_t_11);
if (unlikely(__pyx_t_12 == 0)) break;
- if (unlikely(__pyx_t_12 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 62; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ if (unlikely(__pyx_t_12 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 64; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(__pyx_t_4);
- if (!(likely(PyList_CheckExact(__pyx_t_4))||((__pyx_t_4) == Py_None)||(PyErr_Format(PyExc_TypeError, "Expected %.16s, got %.200s", "list", Py_TYPE(__pyx_t_4)->tp_name), 0))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 62; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ if (!(likely(PyList_CheckExact(__pyx_t_4))||((__pyx_t_4) == Py_None)||(PyErr_Format(PyExc_TypeError, "Expected %.16s, got %.200s", "list", Py_TYPE(__pyx_t_4)->tp_name), 0))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 64; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_XDECREF_SET(__pyx_v_parents, ((PyObject*)__pyx_t_4));
__pyx_t_4 = 0;
__pyx_v_i = __pyx_t_10;
__pyx_t_10 = (__pyx_t_10 + 1);
- /* "ml.pyx":66
+ /* "ml.pyx":68
* # fail to infect it, also computes the probability that its most
* # likely parent infects it
* failures = [weight_failure(dist, dt, alpha, delta, gamma) # <<<<<<<<<<<<<<
- * for (dist, dt) in parents]
- * all_failures = sum(failures)
+ * for (dist, dt, w1, w2, w3) in parents]
+ * probs_fail[i] = sum(failures)
*/
- __pyx_t_4 = PyList_New(0); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 66; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_4 = PyList_New(0); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 68; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(__pyx_t_4);
- /* "ml.pyx":67
+ /* "ml.pyx":69
* # likely parent infects it
* failures = [weight_failure(dist, dt, alpha, delta, gamma)
- * for (dist, dt) in parents] # <<<<<<<<<<<<<<
- * all_failures = sum(failures)
+ * for (dist, dt, w1, w2, w3) in parents] # <<<<<<<<<<<<<<
+ * probs_fail[i] = sum(failures)
* successes = [weight_success(dist, dt, alpha, delta, gamma)
*/
if (unlikely(__pyx_v_parents == Py_None)) {
PyErr_SetString(PyExc_TypeError, "'NoneType' object is not iterable");
- {__pyx_filename = __pyx_f[0]; __pyx_lineno = 67; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ {__pyx_filename = __pyx_f[0]; __pyx_lineno = 69; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
}
__pyx_t_5 = __pyx_v_parents; __Pyx_INCREF(__pyx_t_5); __pyx_t_13 = 0;
for (;;) {
if (__pyx_t_13 >= PyList_GET_SIZE(__pyx_t_5)) break;
#if CYTHON_COMPILING_IN_CPYTHON
- __pyx_t_6 = PyList_GET_ITEM(__pyx_t_5, __pyx_t_13); __Pyx_INCREF(__pyx_t_6); __pyx_t_13++; if (unlikely(0 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 67; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_6 = PyList_GET_ITEM(__pyx_t_5, __pyx_t_13); __Pyx_INCREF(__pyx_t_6); __pyx_t_13++; if (unlikely(0 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 69; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
#else
- __pyx_t_6 = PySequence_ITEM(__pyx_t_5, __pyx_t_13); __pyx_t_13++; if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 67; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_6 = PySequence_ITEM(__pyx_t_5, __pyx_t_13); __pyx_t_13++; if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 69; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
#endif
if ((likely(PyTuple_CheckExact(__pyx_t_6))) || (PyList_CheckExact(__pyx_t_6))) {
PyObject* sequence = __pyx_t_6;
@@ -2267,73 +2276,95 @@ static PyObject *__pyx_pf_2ml_ml(CYTHON_UNUSED PyObject *__pyx_self, PyObject *_
#else
Py_ssize_t size = PySequence_Size(sequence);
#endif
- if (unlikely(size != 2)) {
- if (size > 2) __Pyx_RaiseTooManyValuesError(2);
+ if (unlikely(size != 5)) {
+ if (size > 5) __Pyx_RaiseTooManyValuesError(5);
else if (size >= 0) __Pyx_RaiseNeedMoreValuesError(size);
- {__pyx_filename = __pyx_f[0]; __pyx_lineno = 67; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ {__pyx_filename = __pyx_f[0]; __pyx_lineno = 69; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
}
#if CYTHON_COMPILING_IN_CPYTHON
if (likely(PyTuple_CheckExact(sequence))) {
__pyx_t_14 = PyTuple_GET_ITEM(sequence, 0);
__pyx_t_15 = PyTuple_GET_ITEM(sequence, 1);
+ __pyx_t_16 = PyTuple_GET_ITEM(sequence, 2);
+ __pyx_t_17 = PyTuple_GET_ITEM(sequence, 3);
+ __pyx_t_18 = PyTuple_GET_ITEM(sequence, 4);
} else {
__pyx_t_14 = PyList_GET_ITEM(sequence, 0);
__pyx_t_15 = PyList_GET_ITEM(sequence, 1);
+ __pyx_t_16 = PyList_GET_ITEM(sequence, 2);
+ __pyx_t_17 = PyList_GET_ITEM(sequence, 3);
+ __pyx_t_18 = PyList_GET_ITEM(sequence, 4);
}
__Pyx_INCREF(__pyx_t_14);
__Pyx_INCREF(__pyx_t_15);
+ __Pyx_INCREF(__pyx_t_16);
+ __Pyx_INCREF(__pyx_t_17);
+ __Pyx_INCREF(__pyx_t_18);
#else
- __pyx_t_14 = PySequence_ITEM(sequence, 0); if (unlikely(!__pyx_t_14)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 67; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_GOTREF(__pyx_t_14);
- __pyx_t_15 = PySequence_ITEM(sequence, 1); if (unlikely(!__pyx_t_15)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 67; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_GOTREF(__pyx_t_15);
+ {
+ Py_ssize_t i;
+ PyObject** temps[5] = {&__pyx_t_14,&__pyx_t_15,&__pyx_t_16,&__pyx_t_17,&__pyx_t_18};
+ for (i=0; i < 5; i++) {
+ PyObject* item = PySequence_ITEM(sequence, i); if (unlikely(!item)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 69; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(item);
+ *(temps[i]) = item;
+ }
+ }
#endif
__Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
} else {
Py_ssize_t index = -1;
- __pyx_t_16 = PyObject_GetIter(__pyx_t_6); if (unlikely(!__pyx_t_16)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 67; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_GOTREF(__pyx_t_16);
+ PyObject** temps[5] = {&__pyx_t_14,&__pyx_t_15,&__pyx_t_16,&__pyx_t_17,&__pyx_t_18};
+ __pyx_t_19 = PyObject_GetIter(__pyx_t_6); if (unlikely(!__pyx_t_19)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 69; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(__pyx_t_19);
__Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
- __pyx_t_17 = Py_TYPE(__pyx_t_16)->tp_iternext;
- index = 0; __pyx_t_14 = __pyx_t_17(__pyx_t_16); if (unlikely(!__pyx_t_14)) goto __pyx_L7_unpacking_failed;
- __Pyx_GOTREF(__pyx_t_14);
- index = 1; __pyx_t_15 = __pyx_t_17(__pyx_t_16); if (unlikely(!__pyx_t_15)) goto __pyx_L7_unpacking_failed;
- __Pyx_GOTREF(__pyx_t_15);
- if (__Pyx_IternextUnpackEndCheck(__pyx_t_17(__pyx_t_16), 2) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 67; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __pyx_t_17 = NULL;
- __Pyx_DECREF(__pyx_t_16); __pyx_t_16 = 0;
+ __pyx_t_20 = Py_TYPE(__pyx_t_19)->tp_iternext;
+ for (index=0; index < 5; index++) {
+ PyObject* item = __pyx_t_20(__pyx_t_19); if (unlikely(!item)) goto __pyx_L7_unpacking_failed;
+ __Pyx_GOTREF(item);
+ *(temps[index]) = item;
+ }
+ if (__Pyx_IternextUnpackEndCheck(__pyx_t_20(__pyx_t_19), 5) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 69; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_20 = NULL;
+ __Pyx_DECREF(__pyx_t_19); __pyx_t_19 = 0;
goto __pyx_L8_unpacking_done;
__pyx_L7_unpacking_failed:;
- __Pyx_DECREF(__pyx_t_16); __pyx_t_16 = 0;
- __pyx_t_17 = NULL;
+ __Pyx_DECREF(__pyx_t_19); __pyx_t_19 = 0;
+ __pyx_t_20 = NULL;
if (__Pyx_IterFinish() == 0) __Pyx_RaiseNeedMoreValuesError(index);
- {__pyx_filename = __pyx_f[0]; __pyx_lineno = 67; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ {__pyx_filename = __pyx_f[0]; __pyx_lineno = 69; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__pyx_L8_unpacking_done:;
}
- __pyx_t_12 = __Pyx_PyInt_As_int(__pyx_t_14); if (unlikely((__pyx_t_12 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 67; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_12 = __Pyx_PyInt_As_int(__pyx_t_14); if (unlikely((__pyx_t_12 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 69; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_DECREF(__pyx_t_14); __pyx_t_14 = 0;
- __pyx_t_18 = __Pyx_PyInt_As_int(__pyx_t_15); if (unlikely((__pyx_t_18 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 67; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_21 = __Pyx_PyInt_As_int(__pyx_t_15); if (unlikely((__pyx_t_21 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 69; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_DECREF(__pyx_t_15); __pyx_t_15 = 0;
__pyx_v_dist = __pyx_t_12;
- __pyx_v_dt = __pyx_t_18;
+ __pyx_v_dt = __pyx_t_21;
+ __Pyx_XDECREF_SET(__pyx_v_w1, __pyx_t_16);
+ __pyx_t_16 = 0;
+ __Pyx_XDECREF_SET(__pyx_v_w2, __pyx_t_17);
+ __pyx_t_17 = 0;
+ __Pyx_XDECREF_SET(__pyx_v_w3, __pyx_t_18);
+ __pyx_t_18 = 0;
- /* "ml.pyx":66
+ /* "ml.pyx":68
* # fail to infect it, also computes the probability that its most
* # likely parent infects it
* failures = [weight_failure(dist, dt, alpha, delta, gamma) # <<<<<<<<<<<<<<
- * for (dist, dt) in parents]
- * all_failures = sum(failures)
+ * for (dist, dt, w1, w2, w3) in parents]
+ * probs_fail[i] = sum(failures)
*/
- __pyx_t_6 = PyFloat_FromDouble(__pyx_f_2ml_weight_failure(__pyx_v_dist, __pyx_v_dt, __pyx_v_alpha, __pyx_v_delta, __pyx_v_gamma)); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 66; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_6 = PyFloat_FromDouble(__pyx_f_2ml_weight_failure(__pyx_v_dist, __pyx_v_dt, __pyx_v_alpha, __pyx_v_delta, __pyx_v_gamma)); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 68; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(__pyx_t_6);
- if (unlikely(__Pyx_ListComp_Append(__pyx_t_4, (PyObject*)__pyx_t_6))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 66; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ if (unlikely(__Pyx_ListComp_Append(__pyx_t_4, (PyObject*)__pyx_t_6))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 68; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
- /* "ml.pyx":67
+ /* "ml.pyx":69
* # likely parent infects it
* failures = [weight_failure(dist, dt, alpha, delta, gamma)
- * for (dist, dt) in parents] # <<<<<<<<<<<<<<
- * all_failures = sum(failures)
+ * for (dist, dt, w1, w2, w3) in parents] # <<<<<<<<<<<<<<
+ * probs_fail[i] = sum(failures)
* successes = [weight_success(dist, dt, alpha, delta, gamma)
*/
}
@@ -2343,53 +2374,55 @@ static PyObject *__pyx_pf_2ml_ml(CYTHON_UNUSED PyObject *__pyx_self, PyObject *_
__Pyx_GIVEREF(__pyx_t_4);
__pyx_t_4 = 0;
- /* "ml.pyx":68
+ /* "ml.pyx":70
* failures = [weight_failure(dist, dt, alpha, delta, gamma)
- * for (dist, dt) in parents]
- * all_failures = sum(failures) # <<<<<<<<<<<<<<
+ * for (dist, dt, w1, w2, w3) in parents]
+ * probs_fail[i] = sum(failures) # <<<<<<<<<<<<<<
* successes = [weight_success(dist, dt, alpha, delta, gamma)
- * for (dist, dt) in parents]
+ * for (dist, dt, w1, w2, w3) in parents]
*/
- __pyx_t_4 = PyTuple_New(1); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 68; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_4 = PyTuple_New(1); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 70; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(__pyx_t_4);
__Pyx_INCREF(__pyx_cur_scope->__pyx_v_failures);
PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_cur_scope->__pyx_v_failures);
__Pyx_GIVEREF(__pyx_cur_scope->__pyx_v_failures);
- __pyx_t_5 = __Pyx_PyObject_Call(__pyx_builtin_sum, __pyx_t_4, NULL); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 68; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_5 = __Pyx_PyObject_Call(__pyx_builtin_sum, __pyx_t_4, NULL); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 70; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(__pyx_t_5);
__Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
- __pyx_t_19 = __pyx_PyFloat_AsDouble(__pyx_t_5); if (unlikely((__pyx_t_19 == (npy_double)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 68; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_22 = __pyx_PyFloat_AsDouble(__pyx_t_5); if (unlikely((__pyx_t_22 == (npy_double)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 70; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
- __pyx_v_all_failures = __pyx_t_19;
+ __pyx_t_21 = __pyx_v_i;
+ if (__pyx_t_21 < 0) __pyx_t_21 += __pyx_pybuffernd_probs_fail.diminfo[0].shape;
+ *__Pyx_BufPtrStrided1d(__pyx_t_2ml_DTYPE_t *, __pyx_pybuffernd_probs_fail.rcbuffer->pybuffer.buf, __pyx_t_21, __pyx_pybuffernd_probs_fail.diminfo[0].strides) = __pyx_t_22;
- /* "ml.pyx":69
- * for (dist, dt) in parents]
- * all_failures = sum(failures)
+ /* "ml.pyx":71
+ * for (dist, dt, w1, w2, w3) in parents]
+ * probs_fail[i] = sum(failures)
* successes = [weight_success(dist, dt, alpha, delta, gamma) # <<<<<<<<<<<<<<
- * for (dist, dt) in parents]
- * probs[i] = max(s - failures[l] for l, s in enumerate(successes))
+ * for (dist, dt, w1, w2, w3) in parents]
+ * # find parent that maximizes p/\tilde{p}
*/
- __pyx_t_5 = PyList_New(0); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 69; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_5 = PyList_New(0); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 71; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(__pyx_t_5);
- /* "ml.pyx":70
- * all_failures = sum(failures)
+ /* "ml.pyx":72
+ * probs_fail[i] = sum(failures)
* successes = [weight_success(dist, dt, alpha, delta, gamma)
- * for (dist, dt) in parents] # <<<<<<<<<<<<<<
+ * for (dist, dt, w1, w2, w3) in parents] # <<<<<<<<<<<<<<
+ * # find parent that maximizes p/\tilde{p}
* probs[i] = max(s - failures[l] for l, s in enumerate(successes))
- * probs_fail[i] = all_failures
*/
if (unlikely(__pyx_v_parents == Py_None)) {
PyErr_SetString(PyExc_TypeError, "'NoneType' object is not iterable");
- {__pyx_filename = __pyx_f[0]; __pyx_lineno = 70; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ {__pyx_filename = __pyx_f[0]; __pyx_lineno = 72; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
}
__pyx_t_4 = __pyx_v_parents; __Pyx_INCREF(__pyx_t_4); __pyx_t_13 = 0;
for (;;) {
if (__pyx_t_13 >= PyList_GET_SIZE(__pyx_t_4)) break;
#if CYTHON_COMPILING_IN_CPYTHON
- __pyx_t_6 = PyList_GET_ITEM(__pyx_t_4, __pyx_t_13); __Pyx_INCREF(__pyx_t_6); __pyx_t_13++; if (unlikely(0 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 70; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_6 = PyList_GET_ITEM(__pyx_t_4, __pyx_t_13); __Pyx_INCREF(__pyx_t_6); __pyx_t_13++; if (unlikely(0 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 72; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
#else
- __pyx_t_6 = PySequence_ITEM(__pyx_t_4, __pyx_t_13); __pyx_t_13++; if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 70; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_6 = PySequence_ITEM(__pyx_t_4, __pyx_t_13); __pyx_t_13++; if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 72; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
#endif
if ((likely(PyTuple_CheckExact(__pyx_t_6))) || (PyList_CheckExact(__pyx_t_6))) {
PyObject* sequence = __pyx_t_6;
@@ -2398,74 +2431,96 @@ static PyObject *__pyx_pf_2ml_ml(CYTHON_UNUSED PyObject *__pyx_self, PyObject *_
#else
Py_ssize_t size = PySequence_Size(sequence);
#endif
- if (unlikely(size != 2)) {
- if (size > 2) __Pyx_RaiseTooManyValuesError(2);
+ if (unlikely(size != 5)) {
+ if (size > 5) __Pyx_RaiseTooManyValuesError(5);
else if (size >= 0) __Pyx_RaiseNeedMoreValuesError(size);
- {__pyx_filename = __pyx_f[0]; __pyx_lineno = 70; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ {__pyx_filename = __pyx_f[0]; __pyx_lineno = 72; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
}
#if CYTHON_COMPILING_IN_CPYTHON
if (likely(PyTuple_CheckExact(sequence))) {
- __pyx_t_15 = PyTuple_GET_ITEM(sequence, 0);
- __pyx_t_14 = PyTuple_GET_ITEM(sequence, 1);
+ __pyx_t_18 = PyTuple_GET_ITEM(sequence, 0);
+ __pyx_t_17 = PyTuple_GET_ITEM(sequence, 1);
+ __pyx_t_16 = PyTuple_GET_ITEM(sequence, 2);
+ __pyx_t_15 = PyTuple_GET_ITEM(sequence, 3);
+ __pyx_t_14 = PyTuple_GET_ITEM(sequence, 4);
} else {
- __pyx_t_15 = PyList_GET_ITEM(sequence, 0);
- __pyx_t_14 = PyList_GET_ITEM(sequence, 1);
+ __pyx_t_18 = PyList_GET_ITEM(sequence, 0);
+ __pyx_t_17 = PyList_GET_ITEM(sequence, 1);
+ __pyx_t_16 = PyList_GET_ITEM(sequence, 2);
+ __pyx_t_15 = PyList_GET_ITEM(sequence, 3);
+ __pyx_t_14 = PyList_GET_ITEM(sequence, 4);
}
+ __Pyx_INCREF(__pyx_t_18);
+ __Pyx_INCREF(__pyx_t_17);
+ __Pyx_INCREF(__pyx_t_16);
__Pyx_INCREF(__pyx_t_15);
__Pyx_INCREF(__pyx_t_14);
#else
- __pyx_t_15 = PySequence_ITEM(sequence, 0); if (unlikely(!__pyx_t_15)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 70; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_GOTREF(__pyx_t_15);
- __pyx_t_14 = PySequence_ITEM(sequence, 1); if (unlikely(!__pyx_t_14)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 70; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_GOTREF(__pyx_t_14);
+ {
+ Py_ssize_t i;
+ PyObject** temps[5] = {&__pyx_t_18,&__pyx_t_17,&__pyx_t_16,&__pyx_t_15,&__pyx_t_14};
+ for (i=0; i < 5; i++) {
+ PyObject* item = PySequence_ITEM(sequence, i); if (unlikely(!item)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 72; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(item);
+ *(temps[i]) = item;
+ }
+ }
#endif
__Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
} else {
Py_ssize_t index = -1;
- __pyx_t_16 = PyObject_GetIter(__pyx_t_6); if (unlikely(!__pyx_t_16)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 70; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_GOTREF(__pyx_t_16);
+ PyObject** temps[5] = {&__pyx_t_18,&__pyx_t_17,&__pyx_t_16,&__pyx_t_15,&__pyx_t_14};
+ __pyx_t_19 = PyObject_GetIter(__pyx_t_6); if (unlikely(!__pyx_t_19)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 72; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(__pyx_t_19);
__Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
- __pyx_t_17 = Py_TYPE(__pyx_t_16)->tp_iternext;
- index = 0; __pyx_t_15 = __pyx_t_17(__pyx_t_16); if (unlikely(!__pyx_t_15)) goto __pyx_L11_unpacking_failed;
- __Pyx_GOTREF(__pyx_t_15);
- index = 1; __pyx_t_14 = __pyx_t_17(__pyx_t_16); if (unlikely(!__pyx_t_14)) goto __pyx_L11_unpacking_failed;
- __Pyx_GOTREF(__pyx_t_14);
- if (__Pyx_IternextUnpackEndCheck(__pyx_t_17(__pyx_t_16), 2) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 70; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __pyx_t_17 = NULL;
- __Pyx_DECREF(__pyx_t_16); __pyx_t_16 = 0;
+ __pyx_t_20 = Py_TYPE(__pyx_t_19)->tp_iternext;
+ for (index=0; index < 5; index++) {
+ PyObject* item = __pyx_t_20(__pyx_t_19); if (unlikely(!item)) goto __pyx_L11_unpacking_failed;
+ __Pyx_GOTREF(item);
+ *(temps[index]) = item;
+ }
+ if (__Pyx_IternextUnpackEndCheck(__pyx_t_20(__pyx_t_19), 5) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 72; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_20 = NULL;
+ __Pyx_DECREF(__pyx_t_19); __pyx_t_19 = 0;
goto __pyx_L12_unpacking_done;
__pyx_L11_unpacking_failed:;
- __Pyx_DECREF(__pyx_t_16); __pyx_t_16 = 0;
- __pyx_t_17 = NULL;
+ __Pyx_DECREF(__pyx_t_19); __pyx_t_19 = 0;
+ __pyx_t_20 = NULL;
if (__Pyx_IterFinish() == 0) __Pyx_RaiseNeedMoreValuesError(index);
- {__pyx_filename = __pyx_f[0]; __pyx_lineno = 70; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ {__pyx_filename = __pyx_f[0]; __pyx_lineno = 72; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__pyx_L12_unpacking_done:;
}
- __pyx_t_18 = __Pyx_PyInt_As_int(__pyx_t_15); if (unlikely((__pyx_t_18 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 70; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_DECREF(__pyx_t_15); __pyx_t_15 = 0;
- __pyx_t_12 = __Pyx_PyInt_As_int(__pyx_t_14); if (unlikely((__pyx_t_12 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 70; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_DECREF(__pyx_t_14); __pyx_t_14 = 0;
- __pyx_v_dist = __pyx_t_18;
- __pyx_v_dt = __pyx_t_12;
+ __pyx_t_12 = __Pyx_PyInt_As_int(__pyx_t_18); if (unlikely((__pyx_t_12 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 72; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_DECREF(__pyx_t_18); __pyx_t_18 = 0;
+ __pyx_t_23 = __Pyx_PyInt_As_int(__pyx_t_17); if (unlikely((__pyx_t_23 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 72; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_DECREF(__pyx_t_17); __pyx_t_17 = 0;
+ __pyx_v_dist = __pyx_t_12;
+ __pyx_v_dt = __pyx_t_23;
+ __Pyx_XDECREF_SET(__pyx_v_w1, __pyx_t_16);
+ __pyx_t_16 = 0;
+ __Pyx_XDECREF_SET(__pyx_v_w2, __pyx_t_15);
+ __pyx_t_15 = 0;
+ __Pyx_XDECREF_SET(__pyx_v_w3, __pyx_t_14);
+ __pyx_t_14 = 0;
- /* "ml.pyx":69
- * for (dist, dt) in parents]
- * all_failures = sum(failures)
+ /* "ml.pyx":71
+ * for (dist, dt, w1, w2, w3) in parents]
+ * probs_fail[i] = sum(failures)
* successes = [weight_success(dist, dt, alpha, delta, gamma) # <<<<<<<<<<<<<<
- * for (dist, dt) in parents]
- * probs[i] = max(s - failures[l] for l, s in enumerate(successes))
+ * for (dist, dt, w1, w2, w3) in parents]
+ * # find parent that maximizes p/\tilde{p}
*/
- __pyx_t_6 = PyFloat_FromDouble(__pyx_f_2ml_weight_success(__pyx_v_dist, __pyx_v_dt, __pyx_v_alpha, __pyx_v_delta, __pyx_v_gamma)); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 69; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_6 = PyFloat_FromDouble(__pyx_f_2ml_weight_success(__pyx_v_dist, __pyx_v_dt, __pyx_v_alpha, __pyx_v_delta, __pyx_v_gamma)); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 71; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(__pyx_t_6);
- if (unlikely(__Pyx_ListComp_Append(__pyx_t_5, (PyObject*)__pyx_t_6))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 69; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ if (unlikely(__Pyx_ListComp_Append(__pyx_t_5, (PyObject*)__pyx_t_6))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 71; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
- /* "ml.pyx":70
- * all_failures = sum(failures)
+ /* "ml.pyx":72
+ * probs_fail[i] = sum(failures)
* successes = [weight_success(dist, dt, alpha, delta, gamma)
- * for (dist, dt) in parents] # <<<<<<<<<<<<<<
+ * for (dist, dt, w1, w2, w3) in parents] # <<<<<<<<<<<<<<
+ * # find parent that maximizes p/\tilde{p}
* probs[i] = max(s - failures[l] for l, s in enumerate(successes))
- * probs_fail[i] = all_failures
*/
}
__Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
@@ -2474,45 +2529,34 @@ static PyObject *__pyx_pf_2ml_ml(CYTHON_UNUSED PyObject *__pyx_self, PyObject *_
__Pyx_GIVEREF(__pyx_t_5);
__pyx_t_5 = 0;
- /* "ml.pyx":71
- * successes = [weight_success(dist, dt, alpha, delta, gamma)
- * for (dist, dt) in parents]
+ /* "ml.pyx":74
+ * for (dist, dt, w1, w2, w3) in parents]
+ * # find parent that maximizes p/\tilde{p}
* probs[i] = max(s - failures[l] for l, s in enumerate(successes)) # <<<<<<<<<<<<<<
- * probs_fail[i] = all_failures
*
+ * # loop through non-victims
*/
- __pyx_t_5 = __pyx_pf_2ml_2ml_genexpr(((PyObject*)__pyx_cur_scope)); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 71; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_5 = __pyx_pf_2ml_2ml_genexpr(((PyObject*)__pyx_cur_scope)); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 74; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(__pyx_t_5);
- __pyx_t_4 = PyTuple_New(1); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 71; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_4 = PyTuple_New(1); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 74; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(__pyx_t_4);
PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_t_5);
__Pyx_GIVEREF(__pyx_t_5);
__pyx_t_5 = 0;
- __pyx_t_5 = __Pyx_PyObject_Call(__pyx_builtin_max, __pyx_t_4, NULL); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 71; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_5 = __Pyx_PyObject_Call(__pyx_builtin_max, __pyx_t_4, NULL); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 74; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(__pyx_t_5);
__Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
- __pyx_t_19 = __pyx_PyFloat_AsDouble(__pyx_t_5); if (unlikely((__pyx_t_19 == (npy_double)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 71; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_22 = __pyx_PyFloat_AsDouble(__pyx_t_5); if (unlikely((__pyx_t_22 == (npy_double)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 74; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
- __pyx_t_12 = __pyx_v_i;
- if (__pyx_t_12 < 0) __pyx_t_12 += __pyx_pybuffernd_probs.diminfo[0].shape;
- *__Pyx_BufPtrStrided1d(__pyx_t_2ml_DTYPE_t *, __pyx_pybuffernd_probs.rcbuffer->pybuffer.buf, __pyx_t_12, __pyx_pybuffernd_probs.diminfo[0].strides) = __pyx_t_19;
-
- /* "ml.pyx":72
- * for (dist, dt) in parents]
- * probs[i] = max(s - failures[l] for l, s in enumerate(successes))
- * probs_fail[i] = all_failures # <<<<<<<<<<<<<<
- *
- * for i, parents in enumerate(non_victims.itervalues()):
- */
- __pyx_t_18 = __pyx_v_i;
- if (__pyx_t_18 < 0) __pyx_t_18 += __pyx_pybuffernd_probs_fail.diminfo[0].shape;
- *__Pyx_BufPtrStrided1d(__pyx_t_2ml_DTYPE_t *, __pyx_pybuffernd_probs_fail.rcbuffer->pybuffer.buf, __pyx_t_18, __pyx_pybuffernd_probs_fail.diminfo[0].strides) = __pyx_v_all_failures;
+ __pyx_t_23 = __pyx_v_i;
+ if (__pyx_t_23 < 0) __pyx_t_23 += __pyx_pybuffernd_probs.diminfo[0].shape;
+ *__Pyx_BufPtrStrided1d(__pyx_t_2ml_DTYPE_t *, __pyx_pybuffernd_probs.rcbuffer->pybuffer.buf, __pyx_t_23, __pyx_pybuffernd_probs.diminfo[0].strides) = __pyx_t_22;
}
__Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
- /* "ml.pyx":74
- * probs_fail[i] = all_failures
+ /* "ml.pyx":77
*
+ * # 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
@@ -2521,52 +2565,52 @@ static PyObject *__pyx_pf_2ml_ml(CYTHON_UNUSED PyObject *__pyx_self, PyObject *_
__pyx_t_1 = 0;
if (unlikely(__pyx_v_non_victims == Py_None)) {
PyErr_Format(PyExc_AttributeError, "'NoneType' object has no attribute '%s'", "itervalues");
- {__pyx_filename = __pyx_f[0]; __pyx_lineno = 74; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ {__pyx_filename = __pyx_f[0]; __pyx_lineno = 77; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
}
- __pyx_t_5 = __Pyx_dict_iterator(__pyx_v_non_victims, 1, __pyx_n_s_itervalues, (&__pyx_t_2), (&__pyx_t_11)); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 74; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_5 = __Pyx_dict_iterator(__pyx_v_non_victims, 1, __pyx_n_s_itervalues, (&__pyx_t_2), (&__pyx_t_11)); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 77; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(__pyx_t_5);
__Pyx_XDECREF(__pyx_t_3);
__pyx_t_3 = __pyx_t_5;
__pyx_t_5 = 0;
while (1) {
- __pyx_t_20 = __Pyx_dict_iter_next(__pyx_t_3, __pyx_t_2, &__pyx_t_1, NULL, &__pyx_t_5, NULL, __pyx_t_11);
- if (unlikely(__pyx_t_20 == 0)) break;
- if (unlikely(__pyx_t_20 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 74; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_12 = __Pyx_dict_iter_next(__pyx_t_3, __pyx_t_2, &__pyx_t_1, NULL, &__pyx_t_5, NULL, __pyx_t_11);
+ if (unlikely(__pyx_t_12 == 0)) break;
+ if (unlikely(__pyx_t_12 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 77; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(__pyx_t_5);
- if (!(likely(PyList_CheckExact(__pyx_t_5))||((__pyx_t_5) == Py_None)||(PyErr_Format(PyExc_TypeError, "Expected %.16s, got %.200s", "list", Py_TYPE(__pyx_t_5)->tp_name), 0))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 74; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ if (!(likely(PyList_CheckExact(__pyx_t_5))||((__pyx_t_5) == Py_None)||(PyErr_Format(PyExc_TypeError, "Expected %.16s, got %.200s", "list", Py_TYPE(__pyx_t_5)->tp_name), 0))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 77; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_XDECREF_SET(__pyx_v_parents, ((PyObject*)__pyx_t_5));
__pyx_t_5 = 0;
__pyx_v_i = __pyx_t_10;
__pyx_t_10 = (__pyx_t_10 + 1);
- /* "ml.pyx":77
+ /* "ml.pyx":80
* # for each non victim node, compute the probability that all its
* # parents fail to infect it
* failures = [weight_failure(dist, dt, alpha, delta, gamma) # <<<<<<<<<<<<<<
- * for (dist, dt) in parents]
+ * for (dist, dt, w1, w2, w3) in parents]
* probs_nv[i] = sum(failures)
*/
- __pyx_t_5 = PyList_New(0); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 77; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_5 = PyList_New(0); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 80; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(__pyx_t_5);
- /* "ml.pyx":78
+ /* "ml.pyx":81
* # parents fail to infect it
* failures = [weight_failure(dist, dt, alpha, delta, gamma)
- * for (dist, dt) in parents] # <<<<<<<<<<<<<<
+ * for (dist, dt, w1, w2, w3) in parents] # <<<<<<<<<<<<<<
* probs_nv[i] = sum(failures)
- * probs.sort()
+ *
*/
if (unlikely(__pyx_v_parents == Py_None)) {
PyErr_SetString(PyExc_TypeError, "'NoneType' object is not iterable");
- {__pyx_filename = __pyx_f[0]; __pyx_lineno = 78; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ {__pyx_filename = __pyx_f[0]; __pyx_lineno = 81; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
}
__pyx_t_4 = __pyx_v_parents; __Pyx_INCREF(__pyx_t_4); __pyx_t_13 = 0;
for (;;) {
if (__pyx_t_13 >= PyList_GET_SIZE(__pyx_t_4)) break;
#if CYTHON_COMPILING_IN_CPYTHON
- __pyx_t_6 = PyList_GET_ITEM(__pyx_t_4, __pyx_t_13); __Pyx_INCREF(__pyx_t_6); __pyx_t_13++; if (unlikely(0 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 78; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_6 = PyList_GET_ITEM(__pyx_t_4, __pyx_t_13); __Pyx_INCREF(__pyx_t_6); __pyx_t_13++; if (unlikely(0 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 81; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
#else
- __pyx_t_6 = PySequence_ITEM(__pyx_t_4, __pyx_t_13); __pyx_t_13++; if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 78; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_6 = PySequence_ITEM(__pyx_t_4, __pyx_t_13); __pyx_t_13++; if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 81; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
#endif
if ((likely(PyTuple_CheckExact(__pyx_t_6))) || (PyList_CheckExact(__pyx_t_6))) {
PyObject* sequence = __pyx_t_6;
@@ -2575,74 +2619,96 @@ static PyObject *__pyx_pf_2ml_ml(CYTHON_UNUSED PyObject *__pyx_self, PyObject *_
#else
Py_ssize_t size = PySequence_Size(sequence);
#endif
- if (unlikely(size != 2)) {
- if (size > 2) __Pyx_RaiseTooManyValuesError(2);
+ if (unlikely(size != 5)) {
+ if (size > 5) __Pyx_RaiseTooManyValuesError(5);
else if (size >= 0) __Pyx_RaiseNeedMoreValuesError(size);
- {__pyx_filename = __pyx_f[0]; __pyx_lineno = 78; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ {__pyx_filename = __pyx_f[0]; __pyx_lineno = 81; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
}
#if CYTHON_COMPILING_IN_CPYTHON
if (likely(PyTuple_CheckExact(sequence))) {
__pyx_t_14 = PyTuple_GET_ITEM(sequence, 0);
__pyx_t_15 = PyTuple_GET_ITEM(sequence, 1);
+ __pyx_t_16 = PyTuple_GET_ITEM(sequence, 2);
+ __pyx_t_17 = PyTuple_GET_ITEM(sequence, 3);
+ __pyx_t_18 = PyTuple_GET_ITEM(sequence, 4);
} else {
__pyx_t_14 = PyList_GET_ITEM(sequence, 0);
__pyx_t_15 = PyList_GET_ITEM(sequence, 1);
+ __pyx_t_16 = PyList_GET_ITEM(sequence, 2);
+ __pyx_t_17 = PyList_GET_ITEM(sequence, 3);
+ __pyx_t_18 = PyList_GET_ITEM(sequence, 4);
}
__Pyx_INCREF(__pyx_t_14);
__Pyx_INCREF(__pyx_t_15);
+ __Pyx_INCREF(__pyx_t_16);
+ __Pyx_INCREF(__pyx_t_17);
+ __Pyx_INCREF(__pyx_t_18);
#else
- __pyx_t_14 = PySequence_ITEM(sequence, 0); if (unlikely(!__pyx_t_14)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 78; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_GOTREF(__pyx_t_14);
- __pyx_t_15 = PySequence_ITEM(sequence, 1); if (unlikely(!__pyx_t_15)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 78; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_GOTREF(__pyx_t_15);
+ {
+ Py_ssize_t i;
+ PyObject** temps[5] = {&__pyx_t_14,&__pyx_t_15,&__pyx_t_16,&__pyx_t_17,&__pyx_t_18};
+ for (i=0; i < 5; i++) {
+ PyObject* item = PySequence_ITEM(sequence, i); if (unlikely(!item)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 81; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(item);
+ *(temps[i]) = item;
+ }
+ }
#endif
__Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
} else {
Py_ssize_t index = -1;
- __pyx_t_16 = PyObject_GetIter(__pyx_t_6); if (unlikely(!__pyx_t_16)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 78; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_GOTREF(__pyx_t_16);
+ PyObject** temps[5] = {&__pyx_t_14,&__pyx_t_15,&__pyx_t_16,&__pyx_t_17,&__pyx_t_18};
+ __pyx_t_19 = PyObject_GetIter(__pyx_t_6); if (unlikely(!__pyx_t_19)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 81; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(__pyx_t_19);
__Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
- __pyx_t_17 = Py_TYPE(__pyx_t_16)->tp_iternext;
- index = 0; __pyx_t_14 = __pyx_t_17(__pyx_t_16); if (unlikely(!__pyx_t_14)) goto __pyx_L17_unpacking_failed;
- __Pyx_GOTREF(__pyx_t_14);
- index = 1; __pyx_t_15 = __pyx_t_17(__pyx_t_16); if (unlikely(!__pyx_t_15)) goto __pyx_L17_unpacking_failed;
- __Pyx_GOTREF(__pyx_t_15);
- if (__Pyx_IternextUnpackEndCheck(__pyx_t_17(__pyx_t_16), 2) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 78; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __pyx_t_17 = NULL;
- __Pyx_DECREF(__pyx_t_16); __pyx_t_16 = 0;
+ __pyx_t_20 = Py_TYPE(__pyx_t_19)->tp_iternext;
+ for (index=0; index < 5; index++) {
+ PyObject* item = __pyx_t_20(__pyx_t_19); if (unlikely(!item)) goto __pyx_L17_unpacking_failed;
+ __Pyx_GOTREF(item);
+ *(temps[index]) = item;
+ }
+ if (__Pyx_IternextUnpackEndCheck(__pyx_t_20(__pyx_t_19), 5) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 81; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_20 = NULL;
+ __Pyx_DECREF(__pyx_t_19); __pyx_t_19 = 0;
goto __pyx_L18_unpacking_done;
__pyx_L17_unpacking_failed:;
- __Pyx_DECREF(__pyx_t_16); __pyx_t_16 = 0;
- __pyx_t_17 = NULL;
+ __Pyx_DECREF(__pyx_t_19); __pyx_t_19 = 0;
+ __pyx_t_20 = NULL;
if (__Pyx_IterFinish() == 0) __Pyx_RaiseNeedMoreValuesError(index);
- {__pyx_filename = __pyx_f[0]; __pyx_lineno = 78; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ {__pyx_filename = __pyx_f[0]; __pyx_lineno = 81; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__pyx_L18_unpacking_done:;
}
- __pyx_t_20 = __Pyx_PyInt_As_int(__pyx_t_14); if (unlikely((__pyx_t_20 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 78; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_12 = __Pyx_PyInt_As_int(__pyx_t_14); if (unlikely((__pyx_t_12 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 81; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_DECREF(__pyx_t_14); __pyx_t_14 = 0;
- __pyx_t_21 = __Pyx_PyInt_As_int(__pyx_t_15); if (unlikely((__pyx_t_21 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 78; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_24 = __Pyx_PyInt_As_int(__pyx_t_15); if (unlikely((__pyx_t_24 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 81; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_DECREF(__pyx_t_15); __pyx_t_15 = 0;
- __pyx_v_dist = __pyx_t_20;
- __pyx_v_dt = __pyx_t_21;
+ __pyx_v_dist = __pyx_t_12;
+ __pyx_v_dt = __pyx_t_24;
+ __Pyx_XDECREF_SET(__pyx_v_w1, __pyx_t_16);
+ __pyx_t_16 = 0;
+ __Pyx_XDECREF_SET(__pyx_v_w2, __pyx_t_17);
+ __pyx_t_17 = 0;
+ __Pyx_XDECREF_SET(__pyx_v_w3, __pyx_t_18);
+ __pyx_t_18 = 0;
- /* "ml.pyx":77
+ /* "ml.pyx":80
* # for each non victim node, compute the probability that all its
* # parents fail to infect it
* failures = [weight_failure(dist, dt, alpha, delta, gamma) # <<<<<<<<<<<<<<
- * for (dist, dt) in parents]
+ * for (dist, dt, w1, w2, w3) in parents]
* probs_nv[i] = sum(failures)
*/
- __pyx_t_6 = PyFloat_FromDouble(__pyx_f_2ml_weight_failure(__pyx_v_dist, __pyx_v_dt, __pyx_v_alpha, __pyx_v_delta, __pyx_v_gamma)); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 77; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_6 = PyFloat_FromDouble(__pyx_f_2ml_weight_failure(__pyx_v_dist, __pyx_v_dt, __pyx_v_alpha, __pyx_v_delta, __pyx_v_gamma)); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 80; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(__pyx_t_6);
- if (unlikely(__Pyx_ListComp_Append(__pyx_t_5, (PyObject*)__pyx_t_6))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 77; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ if (unlikely(__Pyx_ListComp_Append(__pyx_t_5, (PyObject*)__pyx_t_6))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 80; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
- /* "ml.pyx":78
+ /* "ml.pyx":81
* # parents fail to infect it
* failures = [weight_failure(dist, dt, alpha, delta, gamma)
- * for (dist, dt) in parents] # <<<<<<<<<<<<<<
+ * for (dist, dt, w1, w2, w3) in parents] # <<<<<<<<<<<<<<
* probs_nv[i] = sum(failures)
- * probs.sort()
+ *
*/
}
__Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
@@ -2651,37 +2717,37 @@ static PyObject *__pyx_pf_2ml_ml(CYTHON_UNUSED PyObject *__pyx_self, PyObject *_
__Pyx_GIVEREF(__pyx_t_5);
__pyx_t_5 = 0;
- /* "ml.pyx":79
+ /* "ml.pyx":82
* failures = [weight_failure(dist, dt, alpha, delta, gamma)
- * for (dist, dt) in parents]
+ * for (dist, dt, w1, w2, w3) in parents]
* probs_nv[i] = sum(failures) # <<<<<<<<<<<<<<
- * probs.sort()
- * probs = probs[::-1]
+ *
+ * # calculate log likelihood
*/
- __pyx_t_5 = PyTuple_New(1); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 79; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_5 = PyTuple_New(1); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 82; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(__pyx_t_5);
__Pyx_INCREF(__pyx_cur_scope->__pyx_v_failures);
PyTuple_SET_ITEM(__pyx_t_5, 0, __pyx_cur_scope->__pyx_v_failures);
__Pyx_GIVEREF(__pyx_cur_scope->__pyx_v_failures);
- __pyx_t_4 = __Pyx_PyObject_Call(__pyx_builtin_sum, __pyx_t_5, NULL); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 79; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_4 = __Pyx_PyObject_Call(__pyx_builtin_sum, __pyx_t_5, NULL); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 82; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(__pyx_t_4);
__Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
- __pyx_t_19 = __pyx_PyFloat_AsDouble(__pyx_t_4); if (unlikely((__pyx_t_19 == (npy_double)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 79; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_22 = __pyx_PyFloat_AsDouble(__pyx_t_4); if (unlikely((__pyx_t_22 == (npy_double)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 82; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
- __pyx_t_21 = __pyx_v_i;
- if (__pyx_t_21 < 0) __pyx_t_21 += __pyx_pybuffernd_probs_nv.diminfo[0].shape;
- *__Pyx_BufPtrStrided1d(__pyx_t_2ml_DTYPE_t *, __pyx_pybuffernd_probs_nv.rcbuffer->pybuffer.buf, __pyx_t_21, __pyx_pybuffernd_probs_nv.diminfo[0].strides) = __pyx_t_19;
+ __pyx_t_24 = __pyx_v_i;
+ if (__pyx_t_24 < 0) __pyx_t_24 += __pyx_pybuffernd_probs_nv.diminfo[0].shape;
+ *__Pyx_BufPtrStrided1d(__pyx_t_2ml_DTYPE_t *, __pyx_pybuffernd_probs_nv.rcbuffer->pybuffer.buf, __pyx_t_24, __pyx_pybuffernd_probs_nv.diminfo[0].strides) = __pyx_t_22;
}
__Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
- /* "ml.pyx":80
- * for (dist, dt) in parents]
- * probs_nv[i] = sum(failures)
- * probs.sort() # <<<<<<<<<<<<<<
- * probs = probs[::-1]
+ /* "ml.pyx":85
+ *
+ * # calculate log likelihood
+ * probs.sort(); probs = probs[::-1] # sort probs in descending order # <<<<<<<<<<<<<<
* cdef:
+ * np.ndarray[DTYPE_t] cums = probs.cumsum()
*/
- __pyx_t_4 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_probs), __pyx_n_s_sort); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 80; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_4 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_probs), __pyx_n_s_sort); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 85; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(__pyx_t_4);
__pyx_t_5 = NULL;
if (CYTHON_COMPILING_IN_CPYTHON && likely(PyMethod_Check(__pyx_t_4))) {
@@ -2694,54 +2760,46 @@ static PyObject *__pyx_pf_2ml_ml(CYTHON_UNUSED PyObject *__pyx_self, PyObject *_
}
}
if (__pyx_t_5) {
- __pyx_t_3 = __Pyx_PyObject_CallOneArg(__pyx_t_4, __pyx_t_5); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 80; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_3 = __Pyx_PyObject_CallOneArg(__pyx_t_4, __pyx_t_5); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 85; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
} else {
- __pyx_t_3 = __Pyx_PyObject_CallNoArg(__pyx_t_4); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 80; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_3 = __Pyx_PyObject_CallNoArg(__pyx_t_4); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 85; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
}
__Pyx_GOTREF(__pyx_t_3);
__Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
__Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
-
- /* "ml.pyx":81
- * probs_nv[i] = sum(failures)
- * probs.sort()
- * probs = probs[::-1] # <<<<<<<<<<<<<<
- * cdef:
- * np.ndarray[DTYPE_t] cums = probs.cumsum()
- */
- __pyx_t_3 = PyObject_GetItem(((PyObject *)__pyx_v_probs), __pyx_slice_); if (unlikely(__pyx_t_3 == NULL)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 81; __pyx_clineno = __LINE__; goto __pyx_L1_error;};
+ __pyx_t_3 = PyObject_GetItem(((PyObject *)__pyx_v_probs), __pyx_slice_); if (unlikely(__pyx_t_3 == NULL)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 85; __pyx_clineno = __LINE__; goto __pyx_L1_error;};
__Pyx_GOTREF(__pyx_t_3);
- if (!(likely(((__pyx_t_3) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_3, __pyx_ptype_5numpy_ndarray))))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 81; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ if (!(likely(((__pyx_t_3) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_3, __pyx_ptype_5numpy_ndarray))))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 85; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__pyx_t_7 = ((PyArrayObject *)__pyx_t_3);
{
__Pyx_BufFmt_StackElem __pyx_stack[1];
__Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_probs.rcbuffer->pybuffer);
__pyx_t_10 = __Pyx_GetBufferAndValidate(&__pyx_pybuffernd_probs.rcbuffer->pybuffer, (PyObject*)__pyx_t_7, &__Pyx_TypeInfo_nn___pyx_t_2ml_DTYPE_t, PyBUF_FORMAT| PyBUF_STRIDES| PyBUF_WRITABLE, 1, 0, __pyx_stack);
if (unlikely(__pyx_t_10 < 0)) {
- PyErr_Fetch(&__pyx_t_22, &__pyx_t_23, &__pyx_t_24);
+ PyErr_Fetch(&__pyx_t_25, &__pyx_t_26, &__pyx_t_27);
if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_probs.rcbuffer->pybuffer, (PyObject*)__pyx_v_probs, &__Pyx_TypeInfo_nn___pyx_t_2ml_DTYPE_t, PyBUF_FORMAT| PyBUF_STRIDES| PyBUF_WRITABLE, 1, 0, __pyx_stack) == -1)) {
- Py_XDECREF(__pyx_t_22); Py_XDECREF(__pyx_t_23); Py_XDECREF(__pyx_t_24);
+ Py_XDECREF(__pyx_t_25); Py_XDECREF(__pyx_t_26); Py_XDECREF(__pyx_t_27);
__Pyx_RaiseBufferFallbackError();
} else {
- PyErr_Restore(__pyx_t_22, __pyx_t_23, __pyx_t_24);
+ PyErr_Restore(__pyx_t_25, __pyx_t_26, __pyx_t_27);
}
}
__pyx_pybuffernd_probs.diminfo[0].strides = __pyx_pybuffernd_probs.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_probs.diminfo[0].shape = __pyx_pybuffernd_probs.rcbuffer->pybuffer.shape[0];
- if (unlikely(__pyx_t_10 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 81; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ if (unlikely(__pyx_t_10 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 85; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
}
__pyx_t_7 = 0;
__Pyx_DECREF_SET(__pyx_v_probs, ((PyArrayObject *)__pyx_t_3));
__pyx_t_3 = 0;
- /* "ml.pyx":83
- * probs = probs[::-1]
+ /* "ml.pyx":87
+ * probs.sort(); probs = probs[::-1] # sort probs in descending order
* cdef:
* np.ndarray[DTYPE_t] cums = probs.cumsum() # <<<<<<<<<<<<<<
* ll = probs_fail.sum()
* ll += probs_nv.sum()
*/
- __pyx_t_4 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_probs), __pyx_n_s_cumsum); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 83; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_4 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_probs), __pyx_n_s_cumsum); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 87; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(__pyx_t_4);
__pyx_t_5 = NULL;
if (CYTHON_COMPILING_IN_CPYTHON && likely(PyMethod_Check(__pyx_t_4))) {
@@ -2754,35 +2812,35 @@ static PyObject *__pyx_pf_2ml_ml(CYTHON_UNUSED PyObject *__pyx_self, PyObject *_
}
}
if (__pyx_t_5) {
- __pyx_t_3 = __Pyx_PyObject_CallOneArg(__pyx_t_4, __pyx_t_5); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 83; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_3 = __Pyx_PyObject_CallOneArg(__pyx_t_4, __pyx_t_5); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 87; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
} else {
- __pyx_t_3 = __Pyx_PyObject_CallNoArg(__pyx_t_4); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 83; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_3 = __Pyx_PyObject_CallNoArg(__pyx_t_4); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 87; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
}
__Pyx_GOTREF(__pyx_t_3);
__Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
- if (!(likely(((__pyx_t_3) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_3, __pyx_ptype_5numpy_ndarray))))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 83; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __pyx_t_25 = ((PyArrayObject *)__pyx_t_3);
+ if (!(likely(((__pyx_t_3) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_3, __pyx_ptype_5numpy_ndarray))))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 87; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_28 = ((PyArrayObject *)__pyx_t_3);
{
__Pyx_BufFmt_StackElem __pyx_stack[1];
- if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_cums.rcbuffer->pybuffer, (PyObject*)__pyx_t_25, &__Pyx_TypeInfo_nn___pyx_t_2ml_DTYPE_t, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack) == -1)) {
+ if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_cums.rcbuffer->pybuffer, (PyObject*)__pyx_t_28, &__Pyx_TypeInfo_nn___pyx_t_2ml_DTYPE_t, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack) == -1)) {
__pyx_v_cums = ((PyArrayObject *)Py_None); __Pyx_INCREF(Py_None); __pyx_pybuffernd_cums.rcbuffer->pybuffer.buf = NULL;
- {__pyx_filename = __pyx_f[0]; __pyx_lineno = 83; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ {__pyx_filename = __pyx_f[0]; __pyx_lineno = 87; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
} else {__pyx_pybuffernd_cums.diminfo[0].strides = __pyx_pybuffernd_cums.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_cums.diminfo[0].shape = __pyx_pybuffernd_cums.rcbuffer->pybuffer.shape[0];
}
}
- __pyx_t_25 = 0;
+ __pyx_t_28 = 0;
__pyx_v_cums = ((PyArrayObject *)__pyx_t_3);
__pyx_t_3 = 0;
- /* "ml.pyx":84
+ /* "ml.pyx":88
* cdef:
* np.ndarray[DTYPE_t] cums = probs.cumsum()
* ll = probs_fail.sum() # <<<<<<<<<<<<<<
* ll += probs_nv.sum()
*
*/
- __pyx_t_4 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_probs_fail), __pyx_n_s_sum); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 84; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_4 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_probs_fail), __pyx_n_s_sum); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 88; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(__pyx_t_4);
__pyx_t_5 = NULL;
if (CYTHON_COMPILING_IN_CPYTHON && likely(PyMethod_Check(__pyx_t_4))) {
@@ -2795,27 +2853,27 @@ static PyObject *__pyx_pf_2ml_ml(CYTHON_UNUSED PyObject *__pyx_self, PyObject *_
}
}
if (__pyx_t_5) {
- __pyx_t_3 = __Pyx_PyObject_CallOneArg(__pyx_t_4, __pyx_t_5); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 84; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_3 = __Pyx_PyObject_CallOneArg(__pyx_t_4, __pyx_t_5); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 88; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
} else {
- __pyx_t_3 = __Pyx_PyObject_CallNoArg(__pyx_t_4); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 84; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_3 = __Pyx_PyObject_CallNoArg(__pyx_t_4); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 88; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
}
__Pyx_GOTREF(__pyx_t_3);
__Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
- __pyx_t_19 = __pyx_PyFloat_AsDouble(__pyx_t_3); if (unlikely((__pyx_t_19 == (npy_double)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 84; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_22 = __pyx_PyFloat_AsDouble(__pyx_t_3); if (unlikely((__pyx_t_22 == (npy_double)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 88; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
- __pyx_v_ll = __pyx_t_19;
+ __pyx_v_ll = __pyx_t_22;
- /* "ml.pyx":85
+ /* "ml.pyx":89
* np.ndarray[DTYPE_t] cums = probs.cumsum()
* ll = probs_fail.sum()
* ll += probs_nv.sum() # <<<<<<<<<<<<<<
*
* for i in xrange(n_victims - 1, 0, -1):
*/
- __pyx_t_3 = PyFloat_FromDouble(__pyx_v_ll); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 85; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_3 = PyFloat_FromDouble(__pyx_v_ll); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 89; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(__pyx_t_3);
- __pyx_t_5 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_probs_nv), __pyx_n_s_sum); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 85; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_5 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_probs_nv), __pyx_n_s_sum); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 89; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(__pyx_t_5);
__pyx_t_6 = NULL;
if (CYTHON_COMPILING_IN_CPYTHON && likely(PyMethod_Check(__pyx_t_5))) {
@@ -2828,22 +2886,22 @@ static PyObject *__pyx_pf_2ml_ml(CYTHON_UNUSED PyObject *__pyx_self, PyObject *_
}
}
if (__pyx_t_6) {
- __pyx_t_4 = __Pyx_PyObject_CallOneArg(__pyx_t_5, __pyx_t_6); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 85; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_4 = __Pyx_PyObject_CallOneArg(__pyx_t_5, __pyx_t_6); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 89; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
} else {
- __pyx_t_4 = __Pyx_PyObject_CallNoArg(__pyx_t_5); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 85; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_4 = __Pyx_PyObject_CallNoArg(__pyx_t_5); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 89; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
}
__Pyx_GOTREF(__pyx_t_4);
__Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
- __pyx_t_5 = PyNumber_InPlaceAdd(__pyx_t_3, __pyx_t_4); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 85; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_5 = PyNumber_InPlaceAdd(__pyx_t_3, __pyx_t_4); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 89; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(__pyx_t_5);
__Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
__Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
- __pyx_t_19 = __pyx_PyFloat_AsDouble(__pyx_t_5); if (unlikely((__pyx_t_19 == (npy_double)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 85; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_22 = __pyx_PyFloat_AsDouble(__pyx_t_5); if (unlikely((__pyx_t_22 == (npy_double)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 89; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
- __pyx_v_ll = __pyx_t_19;
+ __pyx_v_ll = __pyx_t_22;
- /* "ml.pyx":87
+ /* "ml.pyx":91
* ll += probs_nv.sum()
*
* for i in xrange(n_victims - 1, 0, -1): # <<<<<<<<<<<<<<
@@ -2853,38 +2911,50 @@ static PyObject *__pyx_pf_2ml_ml(CYTHON_UNUSED PyObject *__pyx_self, PyObject *_
for (__pyx_t_10 = (__pyx_v_n_victims - 1); __pyx_t_10 > 0; __pyx_t_10-=1) {
__pyx_v_i = __pyx_t_10;
- /* "ml.pyx":89
+ /* "ml.pyx":93
* for i in xrange(n_victims - 1, 0, -1):
* # iterate over all victim nodes to find the optimal threshold
* roots = n_roots + n_victims - 1 - i # <<<<<<<<<<<<<<
- * beta = 1. / (1. + exp(-probs[i]))
- * if beta > float(roots) / age:
+ * beta = exp(probs[i])#1. / (1. + exp(-probs[i]))
+ * print beta
*/
__pyx_v_roots = (((__pyx_v_n_roots + __pyx_v_n_victims) - 1) - __pyx_v_i);
- /* "ml.pyx":90
+ /* "ml.pyx":94
* # iterate over all victim nodes to find the optimal threshold
* roots = n_roots + n_victims - 1 - i
- * beta = 1. / (1. + exp(-probs[i])) # <<<<<<<<<<<<<<
+ * beta = exp(probs[i])#1. / (1. + exp(-probs[i])) # <<<<<<<<<<<<<<
+ * print beta
* if beta > float(roots) / age:
- * break
*/
__pyx_t_11 = __pyx_v_i;
if (__pyx_t_11 < 0) __pyx_t_11 += __pyx_pybuffernd_probs.diminfo[0].shape;
- __pyx_v_beta = (1. / (1. + exp((-(*__Pyx_BufPtrStrided1d(__pyx_t_2ml_DTYPE_t *, __pyx_pybuffernd_probs.rcbuffer->pybuffer.buf, __pyx_t_11, __pyx_pybuffernd_probs.diminfo[0].strides))))));
+ __pyx_v_beta = exp((*__Pyx_BufPtrStrided1d(__pyx_t_2ml_DTYPE_t *, __pyx_pybuffernd_probs.rcbuffer->pybuffer.buf, __pyx_t_11, __pyx_pybuffernd_probs.diminfo[0].strides)));
- /* "ml.pyx":91
+ /* "ml.pyx":95
* roots = n_roots + n_victims - 1 - i
- * beta = 1. / (1. + exp(-probs[i]))
+ * beta = exp(probs[i])#1. / (1. + exp(-probs[i]))
+ * print beta # <<<<<<<<<<<<<<
+ * if beta > float(roots) / age:
+ * break
+ */
+ __pyx_t_5 = PyFloat_FromDouble(__pyx_v_beta); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 95; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(__pyx_t_5);
+ if (__Pyx_PrintOne(0, __pyx_t_5) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 95; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
+
+ /* "ml.pyx":96
+ * beta = exp(probs[i])#1. / (1. + exp(-probs[i]))
+ * print beta
* if beta > float(roots) / age: # <<<<<<<<<<<<<<
* break
* else:
*/
- __pyx_t_26 = ((__pyx_v_beta > (((double)__pyx_v_roots) / __pyx_v_age)) != 0);
- if (__pyx_t_26) {
+ __pyx_t_29 = ((__pyx_v_beta > (((double)__pyx_v_roots) / __pyx_v_age)) != 0);
+ if (__pyx_t_29) {
- /* "ml.pyx":92
- * beta = 1. / (1. + exp(-probs[i]))
+ /* "ml.pyx":97
+ * print beta
* if beta > float(roots) / age:
* break # <<<<<<<<<<<<<<
* else:
@@ -2895,50 +2965,50 @@ static PyObject *__pyx_pf_2ml_ml(CYTHON_UNUSED PyObject *__pyx_self, PyObject *_
}
/*else*/ {
- /* "ml.pyx":94
+ /* "ml.pyx":99
* break
* else:
* print "alpha: {0}, delta: {1}. Everyone is a root".format(alpha, delta) # <<<<<<<<<<<<<<
* roots = n_victims + n_roots
* i = -1
*/
- __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_kp_s_alpha_0_delta_1_Everyone_is_a_ro, __pyx_n_s_format); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 94; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_kp_s_alpha_0_delta_1_Everyone_is_a_ro, __pyx_n_s_format); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 99; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(__pyx_t_4);
- __pyx_t_3 = PyFloat_FromDouble(__pyx_v_alpha); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 94; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_3 = PyFloat_FromDouble(__pyx_v_alpha); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 99; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(__pyx_t_3);
- __pyx_t_6 = PyFloat_FromDouble(__pyx_v_delta); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 94; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_6 = PyFloat_FromDouble(__pyx_v_delta); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 99; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(__pyx_t_6);
- __pyx_t_15 = NULL;
+ __pyx_t_18 = NULL;
__pyx_t_2 = 0;
if (CYTHON_COMPILING_IN_CPYTHON && likely(PyMethod_Check(__pyx_t_4))) {
- __pyx_t_15 = PyMethod_GET_SELF(__pyx_t_4);
- if (likely(__pyx_t_15)) {
+ __pyx_t_18 = PyMethod_GET_SELF(__pyx_t_4);
+ if (likely(__pyx_t_18)) {
PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_4);
- __Pyx_INCREF(__pyx_t_15);
+ __Pyx_INCREF(__pyx_t_18);
__Pyx_INCREF(function);
__Pyx_DECREF_SET(__pyx_t_4, function);
__pyx_t_2 = 1;
}
}
- __pyx_t_14 = PyTuple_New(2+__pyx_t_2); if (unlikely(!__pyx_t_14)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 94; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_GOTREF(__pyx_t_14);
- if (__pyx_t_15) {
- PyTuple_SET_ITEM(__pyx_t_14, 0, __pyx_t_15); __Pyx_GIVEREF(__pyx_t_15); __pyx_t_15 = NULL;
+ __pyx_t_17 = PyTuple_New(2+__pyx_t_2); if (unlikely(!__pyx_t_17)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 99; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(__pyx_t_17);
+ if (__pyx_t_18) {
+ PyTuple_SET_ITEM(__pyx_t_17, 0, __pyx_t_18); __Pyx_GIVEREF(__pyx_t_18); __pyx_t_18 = NULL;
}
- PyTuple_SET_ITEM(__pyx_t_14, 0+__pyx_t_2, __pyx_t_3);
+ PyTuple_SET_ITEM(__pyx_t_17, 0+__pyx_t_2, __pyx_t_3);
__Pyx_GIVEREF(__pyx_t_3);
- PyTuple_SET_ITEM(__pyx_t_14, 1+__pyx_t_2, __pyx_t_6);
+ PyTuple_SET_ITEM(__pyx_t_17, 1+__pyx_t_2, __pyx_t_6);
__Pyx_GIVEREF(__pyx_t_6);
__pyx_t_3 = 0;
__pyx_t_6 = 0;
- __pyx_t_5 = __Pyx_PyObject_Call(__pyx_t_4, __pyx_t_14, NULL); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 94; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_5 = __Pyx_PyObject_Call(__pyx_t_4, __pyx_t_17, NULL); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 99; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(__pyx_t_5);
- __Pyx_DECREF(__pyx_t_14); __pyx_t_14 = 0;
+ __Pyx_DECREF(__pyx_t_17); __pyx_t_17 = 0;
__Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
- if (__Pyx_PrintOne(0, __pyx_t_5) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 94; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ if (__Pyx_PrintOne(0, __pyx_t_5) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 99; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
- /* "ml.pyx":95
+ /* "ml.pyx":100
* else:
* print "alpha: {0}, delta: {1}. Everyone is a root".format(alpha, delta)
* roots = n_victims + n_roots # <<<<<<<<<<<<<<
@@ -2947,7 +3017,7 @@ static PyObject *__pyx_pf_2ml_ml(CYTHON_UNUSED PyObject *__pyx_self, PyObject *_
*/
__pyx_v_roots = (__pyx_v_n_victims + __pyx_v_n_roots);
- /* "ml.pyx":96
+ /* "ml.pyx":101
* print "alpha: {0}, delta: {1}. Everyone is a root".format(alpha, delta)
* roots = n_victims + n_roots
* i = -1 # <<<<<<<<<<<<<<
@@ -2958,7 +3028,7 @@ static PyObject *__pyx_pf_2ml_ml(CYTHON_UNUSED PyObject *__pyx_self, PyObject *_
}
__pyx_L20_break:;
- /* "ml.pyx":97
+ /* "ml.pyx":102
* roots = n_victims + n_roots
* i = -1
* beta = float(roots) / age # <<<<<<<<<<<<<<
@@ -2967,7 +3037,7 @@ static PyObject *__pyx_pf_2ml_ml(CYTHON_UNUSED PyObject *__pyx_self, PyObject *_
*/
__pyx_v_beta = (((double)__pyx_v_roots) / __pyx_v_age);
- /* "ml.pyx":98
+ /* "ml.pyx":103
* i = -1
* beta = float(roots) / age
* for i in xrange(n_victims - 1, 0, -1): # <<<<<<<<<<<<<<
@@ -2977,19 +3047,19 @@ static PyObject *__pyx_pf_2ml_ml(CYTHON_UNUSED PyObject *__pyx_self, PyObject *_
for (__pyx_t_10 = (__pyx_v_n_victims - 1); __pyx_t_10 > 0; __pyx_t_10-=1) {
__pyx_v_i = __pyx_t_10;
- /* "ml.pyx":99
+ /* "ml.pyx":104
* beta = float(roots) / age
* for i in xrange(n_victims - 1, 0, -1):
* if probs[i] >= log(beta/(1.- beta)): # <<<<<<<<<<<<<<
* break
* ll += age * log(1 - beta)
*/
- __pyx_t_20 = __pyx_v_i;
- if (__pyx_t_20 < 0) __pyx_t_20 += __pyx_pybuffernd_probs.diminfo[0].shape;
- __pyx_t_26 = (((*__Pyx_BufPtrStrided1d(__pyx_t_2ml_DTYPE_t *, __pyx_pybuffernd_probs.rcbuffer->pybuffer.buf, __pyx_t_20, __pyx_pybuffernd_probs.diminfo[0].strides)) >= log((__pyx_v_beta / (1. - __pyx_v_beta)))) != 0);
- if (__pyx_t_26) {
+ __pyx_t_12 = __pyx_v_i;
+ if (__pyx_t_12 < 0) __pyx_t_12 += __pyx_pybuffernd_probs.diminfo[0].shape;
+ __pyx_t_29 = (((*__Pyx_BufPtrStrided1d(__pyx_t_2ml_DTYPE_t *, __pyx_pybuffernd_probs.rcbuffer->pybuffer.buf, __pyx_t_12, __pyx_pybuffernd_probs.diminfo[0].strides)) >= log((__pyx_v_beta / (1. - __pyx_v_beta)))) != 0);
+ if (__pyx_t_29) {
- /* "ml.pyx":100
+ /* "ml.pyx":105
* for i in xrange(n_victims - 1, 0, -1):
* if probs[i] >= log(beta/(1.- beta)):
* break # <<<<<<<<<<<<<<
@@ -3001,7 +3071,7 @@ static PyObject *__pyx_pf_2ml_ml(CYTHON_UNUSED PyObject *__pyx_self, PyObject *_
}
__pyx_L23_break:;
- /* "ml.pyx":101
+ /* "ml.pyx":106
* if probs[i] >= log(beta/(1.- beta)):
* break
* ll += age * log(1 - beta) # <<<<<<<<<<<<<<
@@ -3010,17 +3080,17 @@ static PyObject *__pyx_pf_2ml_ml(CYTHON_UNUSED PyObject *__pyx_self, PyObject *_
*/
__pyx_v_ll = (__pyx_v_ll + (__pyx_v_age * log((1.0 - __pyx_v_beta))));
- /* "ml.pyx":102
+ /* "ml.pyx":107
* break
* ll += age * log(1 - beta)
* if i >= 0: # <<<<<<<<<<<<<<
* ll += cums[i]
* if roots > 0:
*/
- __pyx_t_26 = ((__pyx_v_i >= 0) != 0);
- if (__pyx_t_26) {
+ __pyx_t_29 = ((__pyx_v_i >= 0) != 0);
+ if (__pyx_t_29) {
- /* "ml.pyx":103
+ /* "ml.pyx":108
* ll += age * log(1 - beta)
* if i >= 0:
* ll += cums[i] # <<<<<<<<<<<<<<
@@ -3034,17 +3104,17 @@ static PyObject *__pyx_pf_2ml_ml(CYTHON_UNUSED PyObject *__pyx_self, PyObject *_
}
__pyx_L25:;
- /* "ml.pyx":104
+ /* "ml.pyx":109
* if i >= 0:
* ll += cums[i]
* if roots > 0: # <<<<<<<<<<<<<<
* ll += roots * log(beta) - roots * log(1 - beta)
* return (beta, roots, ll)
*/
- __pyx_t_26 = ((__pyx_v_roots > 0) != 0);
- if (__pyx_t_26) {
+ __pyx_t_29 = ((__pyx_v_roots > 0) != 0);
+ if (__pyx_t_29) {
- /* "ml.pyx":105
+ /* "ml.pyx":110
* ll += cums[i]
* if roots > 0:
* ll += roots * log(beta) - roots * log(1 - beta) # <<<<<<<<<<<<<<
@@ -3055,29 +3125,29 @@ static PyObject *__pyx_pf_2ml_ml(CYTHON_UNUSED PyObject *__pyx_self, PyObject *_
}
__pyx_L26:;
- /* "ml.pyx":106
+ /* "ml.pyx":111
* if roots > 0:
* ll += roots * log(beta) - roots * log(1 - beta)
* return (beta, roots, ll) # <<<<<<<<<<<<<<
*/
__Pyx_XDECREF(__pyx_r);
- __pyx_t_5 = PyFloat_FromDouble(__pyx_v_beta); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 106; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_5 = PyFloat_FromDouble(__pyx_v_beta); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 111; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(__pyx_t_5);
- __pyx_t_4 = __Pyx_PyInt_From_int(__pyx_v_roots); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 106; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_4 = __Pyx_PyInt_From_int(__pyx_v_roots); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 111; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(__pyx_t_4);
- __pyx_t_14 = PyFloat_FromDouble(__pyx_v_ll); if (unlikely(!__pyx_t_14)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 106; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_GOTREF(__pyx_t_14);
- __pyx_t_6 = PyTuple_New(3); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 106; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_17 = PyFloat_FromDouble(__pyx_v_ll); if (unlikely(!__pyx_t_17)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 111; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(__pyx_t_17);
+ __pyx_t_6 = PyTuple_New(3); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 111; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(__pyx_t_6);
PyTuple_SET_ITEM(__pyx_t_6, 0, __pyx_t_5);
__Pyx_GIVEREF(__pyx_t_5);
PyTuple_SET_ITEM(__pyx_t_6, 1, __pyx_t_4);
__Pyx_GIVEREF(__pyx_t_4);
- PyTuple_SET_ITEM(__pyx_t_6, 2, __pyx_t_14);
- __Pyx_GIVEREF(__pyx_t_14);
+ PyTuple_SET_ITEM(__pyx_t_6, 2, __pyx_t_17);
+ __Pyx_GIVEREF(__pyx_t_17);
__pyx_t_5 = 0;
__pyx_t_4 = 0;
- __pyx_t_14 = 0;
+ __pyx_t_17 = 0;
__pyx_r = __pyx_t_6;
__pyx_t_6 = 0;
goto __pyx_L0;
@@ -3099,6 +3169,9 @@ static PyObject *__pyx_pf_2ml_ml(CYTHON_UNUSED PyObject *__pyx_self, PyObject *_
__Pyx_XDECREF(__pyx_t_14);
__Pyx_XDECREF(__pyx_t_15);
__Pyx_XDECREF(__pyx_t_16);
+ __Pyx_XDECREF(__pyx_t_17);
+ __Pyx_XDECREF(__pyx_t_18);
+ __Pyx_XDECREF(__pyx_t_19);
{ PyObject *__pyx_type, *__pyx_value, *__pyx_tb;
__Pyx_ErrFetch(&__pyx_type, &__pyx_value, &__pyx_tb);
__Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_cums.rcbuffer->pybuffer);
@@ -3120,6 +3193,9 @@ static PyObject *__pyx_pf_2ml_ml(CYTHON_UNUSED PyObject *__pyx_self, PyObject *_
__Pyx_XDECREF((PyObject *)__pyx_v_probs_fail);
__Pyx_XDECREF((PyObject *)__pyx_v_probs_nv);
__Pyx_XDECREF((PyObject *)__pyx_v_cums);
+ __Pyx_XDECREF(__pyx_v_w1);
+ __Pyx_XDECREF(__pyx_v_w2);
+ __Pyx_XDECREF(__pyx_v_w3);
__Pyx_DECREF(((PyObject *)__pyx_cur_scope));
__Pyx_XGIVEREF(__pyx_r);
__Pyx_RefNannyFinishContext();
@@ -5386,7 +5462,6 @@ static __Pyx_StringTabEntry __pyx_string_tab[] = {
{&__pyx_kp_s_Users_ben_Documents_Cascade_Pro, __pyx_k_Users_ben_Documents_Cascade_Pro, sizeof(__pyx_k_Users_ben_Documents_Cascade_Pro), 0, 0, 1, 0},
{&__pyx_n_s_ValueError, __pyx_k_ValueError, sizeof(__pyx_k_ValueError), 0, 0, 1, 1},
{&__pyx_n_s_age, __pyx_k_age, sizeof(__pyx_k_age), 0, 0, 1, 1},
- {&__pyx_n_s_all_failures, __pyx_k_all_failures, sizeof(__pyx_k_all_failures), 0, 0, 1, 1},
{&__pyx_n_s_alpha, __pyx_k_alpha, sizeof(__pyx_k_alpha), 0, 0, 1, 1},
{&__pyx_kp_s_alpha_0_delta_1_Everyone_is_a_ro, __pyx_k_alpha_0_delta_1_Everyone_is_a_ro, sizeof(__pyx_k_alpha_0_delta_1_Everyone_is_a_ro), 0, 0, 1, 0},
{&__pyx_n_s_args, __pyx_k_args, sizeof(__pyx_k_args), 0, 0, 1, 1},
@@ -5441,18 +5516,21 @@ static __Pyx_StringTabEntry __pyx_string_tab[] = {
{&__pyx_n_s_throw, __pyx_k_throw, sizeof(__pyx_k_throw), 0, 0, 1, 1},
{&__pyx_kp_u_unknown_dtype_code_in_numpy_pxd, __pyx_k_unknown_dtype_code_in_numpy_pxd, sizeof(__pyx_k_unknown_dtype_code_in_numpy_pxd), 0, 1, 0, 0},
{&__pyx_n_s_victims, __pyx_k_victims, sizeof(__pyx_k_victims), 0, 0, 1, 1},
+ {&__pyx_n_s_w1, __pyx_k_w1, sizeof(__pyx_k_w1), 0, 0, 1, 1},
+ {&__pyx_n_s_w2, __pyx_k_w2, sizeof(__pyx_k_w2), 0, 0, 1, 1},
+ {&__pyx_n_s_w3, __pyx_k_w3, sizeof(__pyx_k_w3), 0, 0, 1, 1},
{&__pyx_n_s_xrange, __pyx_k_xrange, sizeof(__pyx_k_xrange), 0, 0, 1, 1},
{&__pyx_n_s_zeros, __pyx_k_zeros, sizeof(__pyx_k_zeros), 0, 0, 1, 1},
{0, 0, 0, 0, 0, 0, 0}
};
static int __Pyx_InitCachedBuiltins(void) {
- __pyx_builtin_enumerate = __Pyx_GetBuiltinName(__pyx_n_s_enumerate); if (!__pyx_builtin_enumerate) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 62; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __pyx_builtin_sum = __Pyx_GetBuiltinName(__pyx_n_s_sum); if (!__pyx_builtin_sum) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 68; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __pyx_builtin_max = __Pyx_GetBuiltinName(__pyx_n_s_max); if (!__pyx_builtin_max) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 71; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_builtin_enumerate = __Pyx_GetBuiltinName(__pyx_n_s_enumerate); if (!__pyx_builtin_enumerate) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 64; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_builtin_sum = __Pyx_GetBuiltinName(__pyx_n_s_sum); if (!__pyx_builtin_sum) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 70; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_builtin_max = __Pyx_GetBuiltinName(__pyx_n_s_max); if (!__pyx_builtin_max) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 74; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
#if PY_MAJOR_VERSION >= 3
- __pyx_builtin_xrange = __Pyx_GetBuiltinName(__pyx_n_s_range); if (!__pyx_builtin_xrange) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 87; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_builtin_xrange = __Pyx_GetBuiltinName(__pyx_n_s_range); if (!__pyx_builtin_xrange) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 91; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
#else
- __pyx_builtin_xrange = __Pyx_GetBuiltinName(__pyx_n_s_xrange); if (!__pyx_builtin_xrange) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 87; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_builtin_xrange = __Pyx_GetBuiltinName(__pyx_n_s_xrange); if (!__pyx_builtin_xrange) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 91; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
#endif
__pyx_builtin_ValueError = __Pyx_GetBuiltinName(__pyx_n_s_ValueError); if (!__pyx_builtin_ValueError) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 218; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__pyx_builtin_range = __Pyx_GetBuiltinName(__pyx_n_s_range); if (!__pyx_builtin_range) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 231; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
@@ -5466,14 +5544,14 @@ static int __Pyx_InitCachedConstants(void) {
__Pyx_RefNannyDeclarations
__Pyx_RefNannySetupContext("__Pyx_InitCachedConstants", 0);
- /* "ml.pyx":81
- * probs_nv[i] = sum(failures)
- * probs.sort()
- * probs = probs[::-1] # <<<<<<<<<<<<<<
+ /* "ml.pyx":85
+ *
+ * # calculate log likelihood
+ * probs.sort(); probs = probs[::-1] # sort probs in descending order # <<<<<<<<<<<<<<
* cdef:
* np.ndarray[DTYPE_t] cums = probs.cumsum()
*/
- __pyx_slice_ = PySlice_New(Py_None, Py_None, __pyx_int_neg_1); if (unlikely(!__pyx_slice_)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 81; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_slice_ = PySlice_New(Py_None, Py_None, __pyx_int_neg_1); if (unlikely(!__pyx_slice_)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 85; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(__pyx_slice_);
__Pyx_GIVEREF(__pyx_slice_);
@@ -5550,10 +5628,10 @@ static int __Pyx_InitCachedConstants(void) {
* DTYPE_t alpha, DTYPE_t delta, DTYPE_t gamma=10):
* cdef:
*/
- __pyx_tuple__8 = PyTuple_Pack(29, __pyx_n_s_root_victims, __pyx_n_s_victims, __pyx_n_s_non_victims, __pyx_n_s_age, __pyx_n_s_alpha, __pyx_n_s_delta, __pyx_n_s_gamma, __pyx_n_s_n_roots, __pyx_n_s_n_victims, __pyx_n_s_n_nodes, __pyx_n_s_roots, __pyx_n_s_i, __pyx_n_s_dist, __pyx_n_s_dt, __pyx_n_s_t, __pyx_n_s_l, __pyx_n_s_beta, __pyx_n_s_all_failures, __pyx_n_s_ll, __pyx_n_s_beta2, __pyx_n_s_parents, __pyx_n_s_failures, __pyx_n_s_successes, __pyx_n_s_probs, __pyx_n_s_probs_fail, __pyx_n_s_probs_nv, __pyx_n_s_cums, __pyx_n_s_genexpr, __pyx_n_s_genexpr); if (unlikely(!__pyx_tuple__8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 50; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_tuple__8 = PyTuple_Pack(31, __pyx_n_s_root_victims, __pyx_n_s_victims, __pyx_n_s_non_victims, __pyx_n_s_age, __pyx_n_s_alpha, __pyx_n_s_delta, __pyx_n_s_gamma, __pyx_n_s_n_roots, __pyx_n_s_n_victims, __pyx_n_s_n_nodes, __pyx_n_s_roots, __pyx_n_s_i, __pyx_n_s_dist, __pyx_n_s_dt, __pyx_n_s_t, __pyx_n_s_l, __pyx_n_s_beta, __pyx_n_s_ll, __pyx_n_s_beta2, __pyx_n_s_parents, __pyx_n_s_failures, __pyx_n_s_successes, __pyx_n_s_probs, __pyx_n_s_probs_fail, __pyx_n_s_probs_nv, __pyx_n_s_cums, __pyx_n_s_w1, __pyx_n_s_w2, __pyx_n_s_w3, __pyx_n_s_genexpr, __pyx_n_s_genexpr); if (unlikely(!__pyx_tuple__8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 50; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(__pyx_tuple__8);
__Pyx_GIVEREF(__pyx_tuple__8);
- __pyx_codeobj__9 = (PyObject*)__Pyx_PyCode_New(7, 0, 29, 0, 0, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__8, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_Users_ben_Documents_Cascade_Pro, __pyx_n_s_ml, 50, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__9)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 50; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_codeobj__9 = (PyObject*)__Pyx_PyCode_New(7, 0, 31, 0, 0, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__8, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_Users_ben_Documents_Cascade_Pro, __pyx_n_s_ml, 50, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__9)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 50; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_RefNannyFinishContext();
return 0;
__pyx_L1_error:;
@@ -5653,7 +5731,7 @@ PyMODINIT_FUNC PyInit_ml(void)
if (PyType_Ready(&__pyx_type_2ml___pyx_scope_struct__ml) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 50; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__pyx_type_2ml___pyx_scope_struct__ml.tp_print = 0;
__pyx_ptype_2ml___pyx_scope_struct__ml = &__pyx_type_2ml___pyx_scope_struct__ml;
- if (PyType_Ready(&__pyx_type_2ml___pyx_scope_struct_1_genexpr) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 71; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ if (PyType_Ready(&__pyx_type_2ml___pyx_scope_struct_1_genexpr) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 74; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__pyx_type_2ml___pyx_scope_struct_1_genexpr.tp_print = 0;
__pyx_ptype_2ml___pyx_scope_struct_1_genexpr = &__pyx_type_2ml___pyx_scope_struct_1_genexpr;
/*--- Type import code ---*/