From 99083ceede0a7e172da99e378973b4b58ba2a64a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ricardo=20Monta=C3=B1ana?= Date: Thu, 13 Jul 2023 16:59:37 +0200 Subject: [PATCH] Fix KDB algorithm argsort --- bayesclass/BaseClassifier.cc | 93 ++++++ bayesclass/BaseClassifier.h | 40 +++ bayesclass/BayesNetwork.cpp | 569 +++++++++++++++++++---------------- bayesclass/BayesNetwork.pyx | 3 + bayesclass/KDB.cc | 110 +++++++ bayesclass/KDB.h | 18 ++ bayesclass/Metrics.cc | 9 +- bayesclass/Metrics.hpp | 3 +- bayesclass/Network.cc | 11 + bayesclass/Network.h | 2 +- bayesclass/clfs.py | 2 +- 11 files changed, 603 insertions(+), 257 deletions(-) create mode 100644 bayesclass/BaseClassifier.cc create mode 100644 bayesclass/BaseClassifier.h create mode 100644 bayesclass/KDB.cc create mode 100644 bayesclass/KDB.h diff --git a/bayesclass/BaseClassifier.cc b/bayesclass/BaseClassifier.cc new file mode 100644 index 0000000..e560db6 --- /dev/null +++ b/bayesclass/BaseClassifier.cc @@ -0,0 +1,93 @@ +#include "BaseClassifier.h" + +namespace bayesnet { + using namespace std; + using namespace torch; + + BaseClassifier::BaseClassifier(Network model) : model(model), m(0), n(0) {} + BaseClassifier& BaseClassifier::build(vector& features, string className, map>& states) + { + + dataset = torch::cat({ X, y.view({150, 1}) }, 1); + this->features = features; + this->className = className; + this->states = states; + checkFitParameters(); + train(); + return *this; + } + BaseClassifier& BaseClassifier::fit(Tensor& X, Tensor& y, vector& features, string className, map>& states) + { + this->X = X; + this->y = y; + return build(features, className, states); + } + BaseClassifier& BaseClassifier::fit(vector>& X, vector& y, vector& features, string className, map>& states) + { + this->X = torch::zeros({ static_cast(X[0].size()), static_cast(X.size()) }, kInt64); + for (int i = 0; i < X.size(); ++i) { + this->X.index_put_({ "...", i }, torch::tensor(X[i], kInt64)); + } + this->y = torch::tensor(y, kInt64); + return build(features, className, states); + } + void BaseClassifier::checkFitParameters() + { + auto sizes = X.sizes(); + m = sizes[0]; + n = sizes[1]; + if (m != y.size(0)) { + throw invalid_argument("X and y must have the same number of samples"); + } + if (n != features.size()) { + throw invalid_argument("X and features must have the same number of features"); + } + if (states.find(className) == states.end()) { + throw invalid_argument("className not found in states"); + } + for (auto feature : features) { + if (states.find(feature) == states.end()) { + throw invalid_argument("feature [" + feature + "] not found in states"); + } + } + } + vector> tensorToVector(const torch::Tensor& tensor) + { + // convert mxn tensor to nxm vector + vector> result; + auto tensor_accessor = tensor.accessor(); + + // Iterate over columns and rows of the tensor + for (int j = 0; j < tensor.size(1); ++j) { + vector column; + for (int i = 0; i < tensor.size(0); ++i) { + column.push_back(tensor_accessor[i][j]); + } + result.push_back(column); + } + + return result; + } + Tensor BaseClassifier::predict(Tensor& X) + { + auto m_ = X.size(0); + auto n_ = X.size(1); + vector> Xd(n_, vector(m_, 0)); + for (auto i = 0; i < n_; i++) { + auto temp = X.index({ "...", i }); + Xd[i] = vector(temp.data_ptr(), temp.data_ptr() + m_); + } + auto yp = model.predict(Xd); + auto ypred = torch::tensor(yp, torch::kInt64); + return ypred; + } + float BaseClassifier::score(Tensor& X, Tensor& y) + { + Tensor y_pred = predict(X); + return (y_pred == y).sum().item() / y.size(0); + } + void BaseClassifier::show() + { + model.show(); + } +} \ No newline at end of file diff --git a/bayesclass/BaseClassifier.h b/bayesclass/BaseClassifier.h new file mode 100644 index 0000000..e2e5080 --- /dev/null +++ b/bayesclass/BaseClassifier.h @@ -0,0 +1,40 @@ +#ifndef CLASSIFIERS_H +#include +#include "Network.h" +using namespace std; +using namespace torch; + +namespace bayesnet { + class BaseClassifier { + private: + BaseClassifier& build(vector& features, string className, map>& states); + protected: + Network model; + int m, n; // m: number of samples, n: number of features + Tensor X; + Tensor y; + Tensor dataset; + vector features; + string className; + map> states; + void checkFitParameters(); + virtual void train() = 0; + public: + BaseClassifier(Network model); + Tensor& getX(); + vector& getFeatures(); + string& getClassName(); + BaseClassifier& fit(Tensor& X, Tensor& y, vector& features, string className, map>& states); + BaseClassifier& fit(vector>& X, vector& y, vector& features, string className, map>& states); + Tensor predict(Tensor& X); + float score(Tensor& X, Tensor& y); + void show(); + }; + +} +#endif + + + + + diff --git a/bayesclass/BayesNetwork.cpp b/bayesclass/BayesNetwork.cpp index d1b711e..0ed0491 100644 --- a/bayesclass/BayesNetwork.cpp +++ b/bayesclass/BayesNetwork.cpp @@ -987,8 +987,8 @@ static const char *__pyx_f[] = { struct __pyx_obj_10bayesclass_8BayesNet_BayesNetwork; struct __pyx_obj_10bayesclass_8BayesNet_CMetrics; -/* "bayesclass/BayesNetwork.pyx":22 - * string version() +/* "bayesclass/BayesNetwork.pyx":23 + * void show() * * cdef class BayesNetwork: # <<<<<<<<<<<<<< * cdef Network *thisptr @@ -1000,7 +1000,7 @@ struct __pyx_obj_10bayesclass_8BayesNet_BayesNetwork { }; -/* "bayesclass/BayesNetwork.pyx":63 +/* "bayesclass/BayesNetwork.pyx":66 * vector[float] conditionalEdgeWeights() * * cdef class CMetrics: # <<<<<<<<<<<<<< @@ -1536,7 +1536,8 @@ static PyObject *__pyx_pf_10bayesclass_8BayesNet_12BayesNetwork_16getFeatures(st static PyObject *__pyx_pf_10bayesclass_8BayesNet_12BayesNetwork_18getStates(struct __pyx_obj_10bayesclass_8BayesNet_BayesNetwork *__pyx_v_self); /* proto */ static PyObject *__pyx_pf_10bayesclass_8BayesNet_12BayesNetwork_20getClassName(struct __pyx_obj_10bayesclass_8BayesNet_BayesNetwork *__pyx_v_self); /* proto */ static PyObject *__pyx_pf_10bayesclass_8BayesNet_12BayesNetwork_22getClassNumStates(struct __pyx_obj_10bayesclass_8BayesNet_BayesNetwork *__pyx_v_self); /* proto */ -static PyObject *__pyx_pf_10bayesclass_8BayesNet_12BayesNetwork_24__reduce__(CYTHON_UNUSED struct __pyx_obj_10bayesclass_8BayesNet_BayesNetwork *__pyx_v_self); /* proto */ +static PyObject *__pyx_pf_10bayesclass_8BayesNet_12BayesNetwork_24show(struct __pyx_obj_10bayesclass_8BayesNet_BayesNetwork *__pyx_v_self); /* proto */ +static PyObject *__pyx_pf_10bayesclass_8BayesNet_12BayesNetwork_26__reduce__(CYTHON_UNUSED struct __pyx_obj_10bayesclass_8BayesNet_BayesNetwork *__pyx_v_self); /* proto */ static int __pyx_pf_10bayesclass_8BayesNet_8CMetrics___cinit__(struct __pyx_obj_10bayesclass_8BayesNet_CMetrics *__pyx_v_self, PyObject *__pyx_v_X, PyObject *__pyx_v_y, PyObject *__pyx_v_features, PyObject *__pyx_v_className, PyObject *__pyx_v_classStates); /* proto */ static void __pyx_pf_10bayesclass_8BayesNet_8CMetrics_2__dealloc__(struct __pyx_obj_10bayesclass_8BayesNet_CMetrics *__pyx_v_self); /* proto */ static PyObject *__pyx_pf_10bayesclass_8BayesNet_8CMetrics_4conditionalEdgeWeights(struct __pyx_obj_10bayesclass_8BayesNet_CMetrics *__pyx_v_self, PyObject *__pyx_v_n_vars); /* proto */ @@ -1548,7 +1549,7 @@ static PyObject *__pyx_float_1_0; static PyObject *__pyx_slice_; /* Late includes */ -/* "bayesclass/BayesNetwork.pyx":24 +/* "bayesclass/BayesNetwork.pyx":25 * cdef class BayesNetwork: * cdef Network *thisptr * def __cinit__(self, maxThreads=0.8, laplaceSmooth=1.0): # <<<<<<<<<<<<<< @@ -1598,7 +1599,7 @@ static int __pyx_pw_10bayesclass_8BayesNet_12BayesNetwork_1__cinit__(PyObject *_ } } if (unlikely(kw_args > 0)) { - if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "__cinit__") < 0)) __PYX_ERR(0, 24, __pyx_L3_error) + if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "__cinit__") < 0)) __PYX_ERR(0, 25, __pyx_L3_error) } } else { switch (PyTuple_GET_SIZE(__pyx_args)) { @@ -1615,7 +1616,7 @@ static int __pyx_pw_10bayesclass_8BayesNet_12BayesNetwork_1__cinit__(PyObject *_ } goto __pyx_L4_argument_unpacking_done; __pyx_L5_argtuple_error:; - __Pyx_RaiseArgtupleInvalid("__cinit__", 0, 0, 2, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 24, __pyx_L3_error) + __Pyx_RaiseArgtupleInvalid("__cinit__", 0, 0, 2, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 25, __pyx_L3_error) __pyx_L3_error:; __Pyx_AddTraceback("bayesclass.BayesNet.BayesNetwork.__cinit__", __pyx_clineno, __pyx_lineno, __pyx_filename); __Pyx_RefNannyFinishContext(); @@ -1639,24 +1640,24 @@ static int __pyx_pf_10bayesclass_8BayesNet_12BayesNetwork___cinit__(struct __pyx int __pyx_clineno = 0; __Pyx_RefNannySetupContext("__cinit__", 0); - /* "bayesclass/BayesNetwork.pyx":25 + /* "bayesclass/BayesNetwork.pyx":26 * cdef Network *thisptr * def __cinit__(self, maxThreads=0.8, laplaceSmooth=1.0): * self.thisptr = new Network(maxThreads, laplaceSmooth) # <<<<<<<<<<<<<< * def __dealloc__(self): * del self.thisptr */ - __pyx_t_1 = __pyx_PyFloat_AsFloat(__pyx_v_maxThreads); if (unlikely((__pyx_t_1 == (float)-1) && PyErr_Occurred())) __PYX_ERR(0, 25, __pyx_L1_error) - __pyx_t_2 = __pyx_PyFloat_AsFloat(__pyx_v_laplaceSmooth); if (unlikely((__pyx_t_2 == (float)-1) && PyErr_Occurred())) __PYX_ERR(0, 25, __pyx_L1_error) + __pyx_t_1 = __pyx_PyFloat_AsFloat(__pyx_v_maxThreads); if (unlikely((__pyx_t_1 == (float)-1) && PyErr_Occurred())) __PYX_ERR(0, 26, __pyx_L1_error) + __pyx_t_2 = __pyx_PyFloat_AsFloat(__pyx_v_laplaceSmooth); if (unlikely((__pyx_t_2 == (float)-1) && PyErr_Occurred())) __PYX_ERR(0, 26, __pyx_L1_error) try { __pyx_t_3 = new bayesnet::Network(__pyx_t_1, __pyx_t_2); } catch(...) { __Pyx_CppExn2PyErr(); - __PYX_ERR(0, 25, __pyx_L1_error) + __PYX_ERR(0, 26, __pyx_L1_error) } __pyx_v_self->thisptr = __pyx_t_3; - /* "bayesclass/BayesNetwork.pyx":24 + /* "bayesclass/BayesNetwork.pyx":25 * cdef class BayesNetwork: * cdef Network *thisptr * def __cinit__(self, maxThreads=0.8, laplaceSmooth=1.0): # <<<<<<<<<<<<<< @@ -1675,7 +1676,7 @@ static int __pyx_pf_10bayesclass_8BayesNet_12BayesNetwork___cinit__(struct __pyx return __pyx_r; } -/* "bayesclass/BayesNetwork.pyx":26 +/* "bayesclass/BayesNetwork.pyx":27 * def __cinit__(self, maxThreads=0.8, laplaceSmooth=1.0): * self.thisptr = new Network(maxThreads, laplaceSmooth) * def __dealloc__(self): # <<<<<<<<<<<<<< @@ -1698,7 +1699,7 @@ static void __pyx_pf_10bayesclass_8BayesNet_12BayesNetwork_2__dealloc__(struct _ __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("__dealloc__", 0); - /* "bayesclass/BayesNetwork.pyx":27 + /* "bayesclass/BayesNetwork.pyx":28 * self.thisptr = new Network(maxThreads, laplaceSmooth) * def __dealloc__(self): * del self.thisptr # <<<<<<<<<<<<<< @@ -1707,7 +1708,7 @@ static void __pyx_pf_10bayesclass_8BayesNet_12BayesNetwork_2__dealloc__(struct _ */ delete __pyx_v_self->thisptr; - /* "bayesclass/BayesNetwork.pyx":26 + /* "bayesclass/BayesNetwork.pyx":27 * def __cinit__(self, maxThreads=0.8, laplaceSmooth=1.0): * self.thisptr = new Network(maxThreads, laplaceSmooth) * def __dealloc__(self): # <<<<<<<<<<<<<< @@ -1719,7 +1720,7 @@ static void __pyx_pf_10bayesclass_8BayesNet_12BayesNetwork_2__dealloc__(struct _ __Pyx_RefNannyFinishContext(); } -/* "bayesclass/BayesNetwork.pyx":28 +/* "bayesclass/BayesNetwork.pyx":29 * def __dealloc__(self): * del self.thisptr * def fit(self, X, y, features, className): # <<<<<<<<<<<<<< @@ -1767,23 +1768,23 @@ static PyObject *__pyx_pw_10bayesclass_8BayesNet_12BayesNetwork_5fit(PyObject *_ case 1: if (likely((values[1] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_y)) != 0)) kw_args--; else { - __Pyx_RaiseArgtupleInvalid("fit", 1, 4, 4, 1); __PYX_ERR(0, 28, __pyx_L3_error) + __Pyx_RaiseArgtupleInvalid("fit", 1, 4, 4, 1); __PYX_ERR(0, 29, __pyx_L3_error) } CYTHON_FALLTHROUGH; case 2: if (likely((values[2] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_features)) != 0)) kw_args--; else { - __Pyx_RaiseArgtupleInvalid("fit", 1, 4, 4, 2); __PYX_ERR(0, 28, __pyx_L3_error) + __Pyx_RaiseArgtupleInvalid("fit", 1, 4, 4, 2); __PYX_ERR(0, 29, __pyx_L3_error) } CYTHON_FALLTHROUGH; case 3: if (likely((values[3] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_className)) != 0)) kw_args--; else { - __Pyx_RaiseArgtupleInvalid("fit", 1, 4, 4, 3); __PYX_ERR(0, 28, __pyx_L3_error) + __Pyx_RaiseArgtupleInvalid("fit", 1, 4, 4, 3); __PYX_ERR(0, 29, __pyx_L3_error) } } if (unlikely(kw_args > 0)) { - if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "fit") < 0)) __PYX_ERR(0, 28, __pyx_L3_error) + if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "fit") < 0)) __PYX_ERR(0, 29, __pyx_L3_error) } } else if (PyTuple_GET_SIZE(__pyx_args) != 4) { goto __pyx_L5_argtuple_error; @@ -1800,7 +1801,7 @@ static PyObject *__pyx_pw_10bayesclass_8BayesNet_12BayesNetwork_5fit(PyObject *_ } goto __pyx_L4_argument_unpacking_done; __pyx_L5_argtuple_error:; - __Pyx_RaiseArgtupleInvalid("fit", 1, 4, 4, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 28, __pyx_L3_error) + __Pyx_RaiseArgtupleInvalid("fit", 1, 4, 4, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 29, __pyx_L3_error) __pyx_L3_error:; __Pyx_AddTraceback("bayesclass.BayesNet.BayesNetwork.fit", __pyx_clineno, __pyx_lineno, __pyx_filename); __Pyx_RefNannyFinishContext(); @@ -1836,7 +1837,7 @@ static PyObject *__pyx_pf_10bayesclass_8BayesNet_12BayesNetwork_4fit(struct __py int __pyx_clineno = 0; __Pyx_RefNannySetupContext("fit", 0); - /* "bayesclass/BayesNetwork.pyx":29 + /* "bayesclass/BayesNetwork.pyx":30 * del self.thisptr * def fit(self, X, y, features, className): * X_ = [X[:, i] for i in range(X.shape[1])] # <<<<<<<<<<<<<< @@ -1844,23 +1845,23 @@ static PyObject *__pyx_pf_10bayesclass_8BayesNet_12BayesNetwork_4fit(struct __py * self.thisptr.fit(X_, y, features_bytes, className.encode()) */ { /* enter inner scope */ - __pyx_t_1 = PyList_New(0); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 29, __pyx_L5_error) + __pyx_t_1 = PyList_New(0); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 30, __pyx_L5_error) __Pyx_GOTREF(__pyx_t_1); - __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_v_X, __pyx_n_s_shape); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 29, __pyx_L5_error) + __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_v_X, __pyx_n_s_shape); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 30, __pyx_L5_error) __Pyx_GOTREF(__pyx_t_2); - __pyx_t_3 = __Pyx_GetItemInt(__pyx_t_2, 1, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 29, __pyx_L5_error) + __pyx_t_3 = __Pyx_GetItemInt(__pyx_t_2, 1, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 30, __pyx_L5_error) __Pyx_GOTREF(__pyx_t_3); __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __pyx_t_2 = __Pyx_PyObject_CallOneArg(__pyx_builtin_range, __pyx_t_3); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 29, __pyx_L5_error) + __pyx_t_2 = __Pyx_PyObject_CallOneArg(__pyx_builtin_range, __pyx_t_3); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 30, __pyx_L5_error) __Pyx_GOTREF(__pyx_t_2); __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; if (likely(PyList_CheckExact(__pyx_t_2)) || PyTuple_CheckExact(__pyx_t_2)) { __pyx_t_3 = __pyx_t_2; __Pyx_INCREF(__pyx_t_3); __pyx_t_4 = 0; __pyx_t_5 = NULL; } else { - __pyx_t_4 = -1; __pyx_t_3 = PyObject_GetIter(__pyx_t_2); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 29, __pyx_L5_error) + __pyx_t_4 = -1; __pyx_t_3 = PyObject_GetIter(__pyx_t_2); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 30, __pyx_L5_error) __Pyx_GOTREF(__pyx_t_3); - __pyx_t_5 = Py_TYPE(__pyx_t_3)->tp_iternext; if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 29, __pyx_L5_error) + __pyx_t_5 = Py_TYPE(__pyx_t_3)->tp_iternext; if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 30, __pyx_L5_error) } __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; for (;;) { @@ -1868,17 +1869,17 @@ static PyObject *__pyx_pf_10bayesclass_8BayesNet_12BayesNetwork_4fit(struct __py if (likely(PyList_CheckExact(__pyx_t_3))) { if (__pyx_t_4 >= PyList_GET_SIZE(__pyx_t_3)) break; #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS - __pyx_t_2 = PyList_GET_ITEM(__pyx_t_3, __pyx_t_4); __Pyx_INCREF(__pyx_t_2); __pyx_t_4++; if (unlikely(0 < 0)) __PYX_ERR(0, 29, __pyx_L5_error) + __pyx_t_2 = PyList_GET_ITEM(__pyx_t_3, __pyx_t_4); __Pyx_INCREF(__pyx_t_2); __pyx_t_4++; if (unlikely(0 < 0)) __PYX_ERR(0, 30, __pyx_L5_error) #else - __pyx_t_2 = PySequence_ITEM(__pyx_t_3, __pyx_t_4); __pyx_t_4++; if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 29, __pyx_L5_error) + __pyx_t_2 = PySequence_ITEM(__pyx_t_3, __pyx_t_4); __pyx_t_4++; if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 30, __pyx_L5_error) __Pyx_GOTREF(__pyx_t_2); #endif } else { if (__pyx_t_4 >= PyTuple_GET_SIZE(__pyx_t_3)) break; #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS - __pyx_t_2 = PyTuple_GET_ITEM(__pyx_t_3, __pyx_t_4); __Pyx_INCREF(__pyx_t_2); __pyx_t_4++; if (unlikely(0 < 0)) __PYX_ERR(0, 29, __pyx_L5_error) + __pyx_t_2 = PyTuple_GET_ITEM(__pyx_t_3, __pyx_t_4); __Pyx_INCREF(__pyx_t_2); __pyx_t_4++; if (unlikely(0 < 0)) __PYX_ERR(0, 30, __pyx_L5_error) #else - __pyx_t_2 = PySequence_ITEM(__pyx_t_3, __pyx_t_4); __pyx_t_4++; if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 29, __pyx_L5_error) + __pyx_t_2 = PySequence_ITEM(__pyx_t_3, __pyx_t_4); __pyx_t_4++; if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 30, __pyx_L5_error) __Pyx_GOTREF(__pyx_t_2); #endif } @@ -1888,7 +1889,7 @@ static PyObject *__pyx_pf_10bayesclass_8BayesNet_12BayesNetwork_4fit(struct __py PyObject* exc_type = PyErr_Occurred(); if (exc_type) { if (likely(__Pyx_PyErr_GivenExceptionMatches(exc_type, PyExc_StopIteration))) PyErr_Clear(); - else __PYX_ERR(0, 29, __pyx_L5_error) + else __PYX_ERR(0, 30, __pyx_L5_error) } break; } @@ -1896,7 +1897,7 @@ static PyObject *__pyx_pf_10bayesclass_8BayesNet_12BayesNetwork_4fit(struct __py } __Pyx_XDECREF_SET(__pyx_7genexpr__pyx_v_i, __pyx_t_2); __pyx_t_2 = 0; - __pyx_t_2 = PyTuple_New(2); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 29, __pyx_L5_error) + __pyx_t_2 = PyTuple_New(2); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 30, __pyx_L5_error) __Pyx_GOTREF(__pyx_t_2); __Pyx_INCREF(__pyx_slice_); __Pyx_GIVEREF(__pyx_slice_); @@ -1904,10 +1905,10 @@ static PyObject *__pyx_pf_10bayesclass_8BayesNet_12BayesNetwork_4fit(struct __py __Pyx_INCREF(__pyx_7genexpr__pyx_v_i); __Pyx_GIVEREF(__pyx_7genexpr__pyx_v_i); PyTuple_SET_ITEM(__pyx_t_2, 1, __pyx_7genexpr__pyx_v_i); - __pyx_t_6 = __Pyx_PyObject_GetItem(__pyx_v_X, __pyx_t_2); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 29, __pyx_L5_error) + __pyx_t_6 = __Pyx_PyObject_GetItem(__pyx_v_X, __pyx_t_2); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 30, __pyx_L5_error) __Pyx_GOTREF(__pyx_t_6); __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - if (unlikely(__Pyx_ListComp_Append(__pyx_t_1, (PyObject*)__pyx_t_6))) __PYX_ERR(0, 29, __pyx_L5_error) + if (unlikely(__Pyx_ListComp_Append(__pyx_t_1, (PyObject*)__pyx_t_6))) __PYX_ERR(0, 30, __pyx_L5_error) __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; } __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; @@ -1921,7 +1922,7 @@ static PyObject *__pyx_pf_10bayesclass_8BayesNet_12BayesNetwork_4fit(struct __py __pyx_v_X_ = ((PyObject*)__pyx_t_1); __pyx_t_1 = 0; - /* "bayesclass/BayesNetwork.pyx":30 + /* "bayesclass/BayesNetwork.pyx":31 * def fit(self, X, y, features, className): * X_ = [X[:, i] for i in range(X.shape[1])] * features_bytes = [x.encode() for x in features] # <<<<<<<<<<<<<< @@ -1929,32 +1930,32 @@ static PyObject *__pyx_pf_10bayesclass_8BayesNet_12BayesNetwork_4fit(struct __py * return self */ { /* enter inner scope */ - __pyx_t_1 = PyList_New(0); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 30, __pyx_L11_error) + __pyx_t_1 = PyList_New(0); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 31, __pyx_L11_error) __Pyx_GOTREF(__pyx_t_1); if (likely(PyList_CheckExact(__pyx_v_features)) || PyTuple_CheckExact(__pyx_v_features)) { __pyx_t_3 = __pyx_v_features; __Pyx_INCREF(__pyx_t_3); __pyx_t_4 = 0; __pyx_t_5 = NULL; } else { - __pyx_t_4 = -1; __pyx_t_3 = PyObject_GetIter(__pyx_v_features); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 30, __pyx_L11_error) + __pyx_t_4 = -1; __pyx_t_3 = PyObject_GetIter(__pyx_v_features); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 31, __pyx_L11_error) __Pyx_GOTREF(__pyx_t_3); - __pyx_t_5 = Py_TYPE(__pyx_t_3)->tp_iternext; if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 30, __pyx_L11_error) + __pyx_t_5 = Py_TYPE(__pyx_t_3)->tp_iternext; if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 31, __pyx_L11_error) } for (;;) { if (likely(!__pyx_t_5)) { if (likely(PyList_CheckExact(__pyx_t_3))) { if (__pyx_t_4 >= PyList_GET_SIZE(__pyx_t_3)) break; #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS - __pyx_t_6 = PyList_GET_ITEM(__pyx_t_3, __pyx_t_4); __Pyx_INCREF(__pyx_t_6); __pyx_t_4++; if (unlikely(0 < 0)) __PYX_ERR(0, 30, __pyx_L11_error) + __pyx_t_6 = PyList_GET_ITEM(__pyx_t_3, __pyx_t_4); __Pyx_INCREF(__pyx_t_6); __pyx_t_4++; if (unlikely(0 < 0)) __PYX_ERR(0, 31, __pyx_L11_error) #else - __pyx_t_6 = PySequence_ITEM(__pyx_t_3, __pyx_t_4); __pyx_t_4++; if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 30, __pyx_L11_error) + __pyx_t_6 = PySequence_ITEM(__pyx_t_3, __pyx_t_4); __pyx_t_4++; if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 31, __pyx_L11_error) __Pyx_GOTREF(__pyx_t_6); #endif } else { if (__pyx_t_4 >= PyTuple_GET_SIZE(__pyx_t_3)) break; #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS - __pyx_t_6 = PyTuple_GET_ITEM(__pyx_t_3, __pyx_t_4); __Pyx_INCREF(__pyx_t_6); __pyx_t_4++; if (unlikely(0 < 0)) __PYX_ERR(0, 30, __pyx_L11_error) + __pyx_t_6 = PyTuple_GET_ITEM(__pyx_t_3, __pyx_t_4); __Pyx_INCREF(__pyx_t_6); __pyx_t_4++; if (unlikely(0 < 0)) __PYX_ERR(0, 31, __pyx_L11_error) #else - __pyx_t_6 = PySequence_ITEM(__pyx_t_3, __pyx_t_4); __pyx_t_4++; if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 30, __pyx_L11_error) + __pyx_t_6 = PySequence_ITEM(__pyx_t_3, __pyx_t_4); __pyx_t_4++; if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 31, __pyx_L11_error) __Pyx_GOTREF(__pyx_t_6); #endif } @@ -1964,7 +1965,7 @@ static PyObject *__pyx_pf_10bayesclass_8BayesNet_12BayesNetwork_4fit(struct __py PyObject* exc_type = PyErr_Occurred(); if (exc_type) { if (likely(__Pyx_PyErr_GivenExceptionMatches(exc_type, PyExc_StopIteration))) PyErr_Clear(); - else __PYX_ERR(0, 30, __pyx_L11_error) + else __PYX_ERR(0, 31, __pyx_L11_error) } break; } @@ -1972,7 +1973,7 @@ static PyObject *__pyx_pf_10bayesclass_8BayesNet_12BayesNetwork_4fit(struct __py } __Pyx_XDECREF_SET(__pyx_8genexpr1__pyx_v_x, __pyx_t_6); __pyx_t_6 = 0; - __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_8genexpr1__pyx_v_x, __pyx_n_s_encode); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 30, __pyx_L11_error) + __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_8genexpr1__pyx_v_x, __pyx_n_s_encode); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 31, __pyx_L11_error) __Pyx_GOTREF(__pyx_t_2); __pyx_t_7 = NULL; if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_2))) { @@ -1986,10 +1987,10 @@ static PyObject *__pyx_pf_10bayesclass_8BayesNet_12BayesNetwork_4fit(struct __py } __pyx_t_6 = (__pyx_t_7) ? __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_t_7) : __Pyx_PyObject_CallNoArg(__pyx_t_2); __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0; - if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 30, __pyx_L11_error) + if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 31, __pyx_L11_error) __Pyx_GOTREF(__pyx_t_6); __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - if (unlikely(__Pyx_ListComp_Append(__pyx_t_1, (PyObject*)__pyx_t_6))) __PYX_ERR(0, 30, __pyx_L11_error) + if (unlikely(__Pyx_ListComp_Append(__pyx_t_1, (PyObject*)__pyx_t_6))) __PYX_ERR(0, 31, __pyx_L11_error) __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; } __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; @@ -2003,17 +2004,17 @@ static PyObject *__pyx_pf_10bayesclass_8BayesNet_12BayesNetwork_4fit(struct __py __pyx_v_features_bytes = ((PyObject*)__pyx_t_1); __pyx_t_1 = 0; - /* "bayesclass/BayesNetwork.pyx":31 + /* "bayesclass/BayesNetwork.pyx":32 * X_ = [X[:, i] for i in range(X.shape[1])] * features_bytes = [x.encode() for x in features] * self.thisptr.fit(X_, y, features_bytes, className.encode()) # <<<<<<<<<<<<<< * return self * def predict(self, X): */ - __pyx_t_8 = __pyx_convert_vector_from_py_std_3a__3a_vector_3c_int_3e___(__pyx_v_X_); if (unlikely(PyErr_Occurred())) __PYX_ERR(0, 31, __pyx_L1_error) - __pyx_t_9 = __pyx_convert_vector_from_py_int(__pyx_v_y); if (unlikely(PyErr_Occurred())) __PYX_ERR(0, 31, __pyx_L1_error) - __pyx_t_10 = __pyx_convert_vector_from_py_std_3a__3a_string(__pyx_v_features_bytes); if (unlikely(PyErr_Occurred())) __PYX_ERR(0, 31, __pyx_L1_error) - __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_v_className, __pyx_n_s_encode); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 31, __pyx_L1_error) + __pyx_t_8 = __pyx_convert_vector_from_py_std_3a__3a_vector_3c_int_3e___(__pyx_v_X_); if (unlikely(PyErr_Occurred())) __PYX_ERR(0, 32, __pyx_L1_error) + __pyx_t_9 = __pyx_convert_vector_from_py_int(__pyx_v_y); if (unlikely(PyErr_Occurred())) __PYX_ERR(0, 32, __pyx_L1_error) + __pyx_t_10 = __pyx_convert_vector_from_py_std_3a__3a_string(__pyx_v_features_bytes); if (unlikely(PyErr_Occurred())) __PYX_ERR(0, 32, __pyx_L1_error) + __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_v_className, __pyx_n_s_encode); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 32, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __pyx_t_6 = NULL; if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_3))) { @@ -2027,14 +2028,14 @@ static PyObject *__pyx_pf_10bayesclass_8BayesNet_12BayesNetwork_4fit(struct __py } __pyx_t_1 = (__pyx_t_6) ? __Pyx_PyObject_CallOneArg(__pyx_t_3, __pyx_t_6) : __Pyx_PyObject_CallNoArg(__pyx_t_3); __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0; - if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 31, __pyx_L1_error) + if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 32, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __pyx_t_11 = __pyx_convert_string_from_py_std__in_string(__pyx_t_1); if (unlikely(PyErr_Occurred())) __PYX_ERR(0, 31, __pyx_L1_error) + __pyx_t_11 = __pyx_convert_string_from_py_std__in_string(__pyx_t_1); if (unlikely(PyErr_Occurred())) __PYX_ERR(0, 32, __pyx_L1_error) __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; __pyx_v_self->thisptr->fit(__pyx_t_8, __pyx_t_9, __pyx_t_10, __pyx_t_11); - /* "bayesclass/BayesNetwork.pyx":32 + /* "bayesclass/BayesNetwork.pyx":33 * features_bytes = [x.encode() for x in features] * self.thisptr.fit(X_, y, features_bytes, className.encode()) * return self # <<<<<<<<<<<<<< @@ -2046,7 +2047,7 @@ static PyObject *__pyx_pf_10bayesclass_8BayesNet_12BayesNetwork_4fit(struct __py __pyx_r = ((PyObject *)__pyx_v_self); goto __pyx_L0; - /* "bayesclass/BayesNetwork.pyx":28 + /* "bayesclass/BayesNetwork.pyx":29 * def __dealloc__(self): * del self.thisptr * def fit(self, X, y, features, className): # <<<<<<<<<<<<<< @@ -2073,7 +2074,7 @@ static PyObject *__pyx_pf_10bayesclass_8BayesNet_12BayesNetwork_4fit(struct __py return __pyx_r; } -/* "bayesclass/BayesNetwork.pyx":33 +/* "bayesclass/BayesNetwork.pyx":34 * self.thisptr.fit(X_, y, features_bytes, className.encode()) * return self * def predict(self, X): # <<<<<<<<<<<<<< @@ -2111,7 +2112,7 @@ static PyObject *__pyx_pf_10bayesclass_8BayesNet_12BayesNetwork_6predict(struct int __pyx_clineno = 0; __Pyx_RefNannySetupContext("predict", 0); - /* "bayesclass/BayesNetwork.pyx":34 + /* "bayesclass/BayesNetwork.pyx":35 * return self * def predict(self, X): * X_ = [X[:, i] for i in range(X.shape[1])] # <<<<<<<<<<<<<< @@ -2119,23 +2120,23 @@ static PyObject *__pyx_pf_10bayesclass_8BayesNet_12BayesNetwork_6predict(struct * def predict_proba(self, X): */ { /* enter inner scope */ - __pyx_t_1 = PyList_New(0); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 34, __pyx_L5_error) + __pyx_t_1 = PyList_New(0); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 35, __pyx_L5_error) __Pyx_GOTREF(__pyx_t_1); - __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_v_X, __pyx_n_s_shape); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 34, __pyx_L5_error) + __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_v_X, __pyx_n_s_shape); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 35, __pyx_L5_error) __Pyx_GOTREF(__pyx_t_2); - __pyx_t_3 = __Pyx_GetItemInt(__pyx_t_2, 1, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 34, __pyx_L5_error) + __pyx_t_3 = __Pyx_GetItemInt(__pyx_t_2, 1, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 35, __pyx_L5_error) __Pyx_GOTREF(__pyx_t_3); __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __pyx_t_2 = __Pyx_PyObject_CallOneArg(__pyx_builtin_range, __pyx_t_3); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 34, __pyx_L5_error) + __pyx_t_2 = __Pyx_PyObject_CallOneArg(__pyx_builtin_range, __pyx_t_3); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 35, __pyx_L5_error) __Pyx_GOTREF(__pyx_t_2); __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; if (likely(PyList_CheckExact(__pyx_t_2)) || PyTuple_CheckExact(__pyx_t_2)) { __pyx_t_3 = __pyx_t_2; __Pyx_INCREF(__pyx_t_3); __pyx_t_4 = 0; __pyx_t_5 = NULL; } else { - __pyx_t_4 = -1; __pyx_t_3 = PyObject_GetIter(__pyx_t_2); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 34, __pyx_L5_error) + __pyx_t_4 = -1; __pyx_t_3 = PyObject_GetIter(__pyx_t_2); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 35, __pyx_L5_error) __Pyx_GOTREF(__pyx_t_3); - __pyx_t_5 = Py_TYPE(__pyx_t_3)->tp_iternext; if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 34, __pyx_L5_error) + __pyx_t_5 = Py_TYPE(__pyx_t_3)->tp_iternext; if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 35, __pyx_L5_error) } __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; for (;;) { @@ -2143,17 +2144,17 @@ static PyObject *__pyx_pf_10bayesclass_8BayesNet_12BayesNetwork_6predict(struct if (likely(PyList_CheckExact(__pyx_t_3))) { if (__pyx_t_4 >= PyList_GET_SIZE(__pyx_t_3)) break; #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS - __pyx_t_2 = PyList_GET_ITEM(__pyx_t_3, __pyx_t_4); __Pyx_INCREF(__pyx_t_2); __pyx_t_4++; if (unlikely(0 < 0)) __PYX_ERR(0, 34, __pyx_L5_error) + __pyx_t_2 = PyList_GET_ITEM(__pyx_t_3, __pyx_t_4); __Pyx_INCREF(__pyx_t_2); __pyx_t_4++; if (unlikely(0 < 0)) __PYX_ERR(0, 35, __pyx_L5_error) #else - __pyx_t_2 = PySequence_ITEM(__pyx_t_3, __pyx_t_4); __pyx_t_4++; if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 34, __pyx_L5_error) + __pyx_t_2 = PySequence_ITEM(__pyx_t_3, __pyx_t_4); __pyx_t_4++; if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 35, __pyx_L5_error) __Pyx_GOTREF(__pyx_t_2); #endif } else { if (__pyx_t_4 >= PyTuple_GET_SIZE(__pyx_t_3)) break; #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS - __pyx_t_2 = PyTuple_GET_ITEM(__pyx_t_3, __pyx_t_4); __Pyx_INCREF(__pyx_t_2); __pyx_t_4++; if (unlikely(0 < 0)) __PYX_ERR(0, 34, __pyx_L5_error) + __pyx_t_2 = PyTuple_GET_ITEM(__pyx_t_3, __pyx_t_4); __Pyx_INCREF(__pyx_t_2); __pyx_t_4++; if (unlikely(0 < 0)) __PYX_ERR(0, 35, __pyx_L5_error) #else - __pyx_t_2 = PySequence_ITEM(__pyx_t_3, __pyx_t_4); __pyx_t_4++; if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 34, __pyx_L5_error) + __pyx_t_2 = PySequence_ITEM(__pyx_t_3, __pyx_t_4); __pyx_t_4++; if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 35, __pyx_L5_error) __Pyx_GOTREF(__pyx_t_2); #endif } @@ -2163,7 +2164,7 @@ static PyObject *__pyx_pf_10bayesclass_8BayesNet_12BayesNetwork_6predict(struct PyObject* exc_type = PyErr_Occurred(); if (exc_type) { if (likely(__Pyx_PyErr_GivenExceptionMatches(exc_type, PyExc_StopIteration))) PyErr_Clear(); - else __PYX_ERR(0, 34, __pyx_L5_error) + else __PYX_ERR(0, 35, __pyx_L5_error) } break; } @@ -2171,7 +2172,7 @@ static PyObject *__pyx_pf_10bayesclass_8BayesNet_12BayesNetwork_6predict(struct } __Pyx_XDECREF_SET(__pyx_8genexpr2__pyx_v_i, __pyx_t_2); __pyx_t_2 = 0; - __pyx_t_2 = PyTuple_New(2); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 34, __pyx_L5_error) + __pyx_t_2 = PyTuple_New(2); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 35, __pyx_L5_error) __Pyx_GOTREF(__pyx_t_2); __Pyx_INCREF(__pyx_slice_); __Pyx_GIVEREF(__pyx_slice_); @@ -2179,10 +2180,10 @@ static PyObject *__pyx_pf_10bayesclass_8BayesNet_12BayesNetwork_6predict(struct __Pyx_INCREF(__pyx_8genexpr2__pyx_v_i); __Pyx_GIVEREF(__pyx_8genexpr2__pyx_v_i); PyTuple_SET_ITEM(__pyx_t_2, 1, __pyx_8genexpr2__pyx_v_i); - __pyx_t_6 = __Pyx_PyObject_GetItem(__pyx_v_X, __pyx_t_2); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 34, __pyx_L5_error) + __pyx_t_6 = __Pyx_PyObject_GetItem(__pyx_v_X, __pyx_t_2); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 35, __pyx_L5_error) __Pyx_GOTREF(__pyx_t_6); __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - if (unlikely(__Pyx_ListComp_Append(__pyx_t_1, (PyObject*)__pyx_t_6))) __PYX_ERR(0, 34, __pyx_L5_error) + if (unlikely(__Pyx_ListComp_Append(__pyx_t_1, (PyObject*)__pyx_t_6))) __PYX_ERR(0, 35, __pyx_L5_error) __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; } __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; @@ -2196,7 +2197,7 @@ static PyObject *__pyx_pf_10bayesclass_8BayesNet_12BayesNetwork_6predict(struct __pyx_v_X_ = ((PyObject*)__pyx_t_1); __pyx_t_1 = 0; - /* "bayesclass/BayesNetwork.pyx":35 + /* "bayesclass/BayesNetwork.pyx":36 * def predict(self, X): * X_ = [X[:, i] for i in range(X.shape[1])] * return self.thisptr.predict(X_) # <<<<<<<<<<<<<< @@ -2204,14 +2205,14 @@ static PyObject *__pyx_pf_10bayesclass_8BayesNet_12BayesNetwork_6predict(struct * X_ = [X[:, i] for i in range(X.shape[1])] */ __Pyx_XDECREF(__pyx_r); - __pyx_t_7 = __pyx_convert_vector_from_py_std_3a__3a_vector_3c_int_3e___(__pyx_v_X_); if (unlikely(PyErr_Occurred())) __PYX_ERR(0, 35, __pyx_L1_error) - __pyx_t_1 = __pyx_convert_vector_to_py_int(__pyx_v_self->thisptr->predict(__pyx_t_7)); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 35, __pyx_L1_error) + __pyx_t_7 = __pyx_convert_vector_from_py_std_3a__3a_vector_3c_int_3e___(__pyx_v_X_); if (unlikely(PyErr_Occurred())) __PYX_ERR(0, 36, __pyx_L1_error) + __pyx_t_1 = __pyx_convert_vector_to_py_int(__pyx_v_self->thisptr->predict(__pyx_t_7)); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 36, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __pyx_r = __pyx_t_1; __pyx_t_1 = 0; goto __pyx_L0; - /* "bayesclass/BayesNetwork.pyx":33 + /* "bayesclass/BayesNetwork.pyx":34 * self.thisptr.fit(X_, y, features_bytes, className.encode()) * return self * def predict(self, X): # <<<<<<<<<<<<<< @@ -2235,7 +2236,7 @@ static PyObject *__pyx_pf_10bayesclass_8BayesNet_12BayesNetwork_6predict(struct return __pyx_r; } -/* "bayesclass/BayesNetwork.pyx":36 +/* "bayesclass/BayesNetwork.pyx":37 * X_ = [X[:, i] for i in range(X.shape[1])] * return self.thisptr.predict(X_) * def predict_proba(self, X): # <<<<<<<<<<<<<< @@ -2273,7 +2274,7 @@ static PyObject *__pyx_pf_10bayesclass_8BayesNet_12BayesNetwork_8predict_proba(s int __pyx_clineno = 0; __Pyx_RefNannySetupContext("predict_proba", 0); - /* "bayesclass/BayesNetwork.pyx":37 + /* "bayesclass/BayesNetwork.pyx":38 * return self.thisptr.predict(X_) * def predict_proba(self, X): * X_ = [X[:, i] for i in range(X.shape[1])] # <<<<<<<<<<<<<< @@ -2281,23 +2282,23 @@ static PyObject *__pyx_pf_10bayesclass_8BayesNet_12BayesNetwork_8predict_proba(s * def score(self, X, y): */ { /* enter inner scope */ - __pyx_t_1 = PyList_New(0); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 37, __pyx_L5_error) + __pyx_t_1 = PyList_New(0); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 38, __pyx_L5_error) __Pyx_GOTREF(__pyx_t_1); - __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_v_X, __pyx_n_s_shape); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 37, __pyx_L5_error) + __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_v_X, __pyx_n_s_shape); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 38, __pyx_L5_error) __Pyx_GOTREF(__pyx_t_2); - __pyx_t_3 = __Pyx_GetItemInt(__pyx_t_2, 1, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 37, __pyx_L5_error) + __pyx_t_3 = __Pyx_GetItemInt(__pyx_t_2, 1, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 38, __pyx_L5_error) __Pyx_GOTREF(__pyx_t_3); __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __pyx_t_2 = __Pyx_PyObject_CallOneArg(__pyx_builtin_range, __pyx_t_3); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 37, __pyx_L5_error) + __pyx_t_2 = __Pyx_PyObject_CallOneArg(__pyx_builtin_range, __pyx_t_3); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 38, __pyx_L5_error) __Pyx_GOTREF(__pyx_t_2); __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; if (likely(PyList_CheckExact(__pyx_t_2)) || PyTuple_CheckExact(__pyx_t_2)) { __pyx_t_3 = __pyx_t_2; __Pyx_INCREF(__pyx_t_3); __pyx_t_4 = 0; __pyx_t_5 = NULL; } else { - __pyx_t_4 = -1; __pyx_t_3 = PyObject_GetIter(__pyx_t_2); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 37, __pyx_L5_error) + __pyx_t_4 = -1; __pyx_t_3 = PyObject_GetIter(__pyx_t_2); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 38, __pyx_L5_error) __Pyx_GOTREF(__pyx_t_3); - __pyx_t_5 = Py_TYPE(__pyx_t_3)->tp_iternext; if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 37, __pyx_L5_error) + __pyx_t_5 = Py_TYPE(__pyx_t_3)->tp_iternext; if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 38, __pyx_L5_error) } __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; for (;;) { @@ -2305,17 +2306,17 @@ static PyObject *__pyx_pf_10bayesclass_8BayesNet_12BayesNetwork_8predict_proba(s if (likely(PyList_CheckExact(__pyx_t_3))) { if (__pyx_t_4 >= PyList_GET_SIZE(__pyx_t_3)) break; #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS - __pyx_t_2 = PyList_GET_ITEM(__pyx_t_3, __pyx_t_4); __Pyx_INCREF(__pyx_t_2); __pyx_t_4++; if (unlikely(0 < 0)) __PYX_ERR(0, 37, __pyx_L5_error) + __pyx_t_2 = PyList_GET_ITEM(__pyx_t_3, __pyx_t_4); __Pyx_INCREF(__pyx_t_2); __pyx_t_4++; if (unlikely(0 < 0)) __PYX_ERR(0, 38, __pyx_L5_error) #else - __pyx_t_2 = PySequence_ITEM(__pyx_t_3, __pyx_t_4); __pyx_t_4++; if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 37, __pyx_L5_error) + __pyx_t_2 = PySequence_ITEM(__pyx_t_3, __pyx_t_4); __pyx_t_4++; if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 38, __pyx_L5_error) __Pyx_GOTREF(__pyx_t_2); #endif } else { if (__pyx_t_4 >= PyTuple_GET_SIZE(__pyx_t_3)) break; #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS - __pyx_t_2 = PyTuple_GET_ITEM(__pyx_t_3, __pyx_t_4); __Pyx_INCREF(__pyx_t_2); __pyx_t_4++; if (unlikely(0 < 0)) __PYX_ERR(0, 37, __pyx_L5_error) + __pyx_t_2 = PyTuple_GET_ITEM(__pyx_t_3, __pyx_t_4); __Pyx_INCREF(__pyx_t_2); __pyx_t_4++; if (unlikely(0 < 0)) __PYX_ERR(0, 38, __pyx_L5_error) #else - __pyx_t_2 = PySequence_ITEM(__pyx_t_3, __pyx_t_4); __pyx_t_4++; if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 37, __pyx_L5_error) + __pyx_t_2 = PySequence_ITEM(__pyx_t_3, __pyx_t_4); __pyx_t_4++; if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 38, __pyx_L5_error) __Pyx_GOTREF(__pyx_t_2); #endif } @@ -2325,7 +2326,7 @@ static PyObject *__pyx_pf_10bayesclass_8BayesNet_12BayesNetwork_8predict_proba(s PyObject* exc_type = PyErr_Occurred(); if (exc_type) { if (likely(__Pyx_PyErr_GivenExceptionMatches(exc_type, PyExc_StopIteration))) PyErr_Clear(); - else __PYX_ERR(0, 37, __pyx_L5_error) + else __PYX_ERR(0, 38, __pyx_L5_error) } break; } @@ -2333,7 +2334,7 @@ static PyObject *__pyx_pf_10bayesclass_8BayesNet_12BayesNetwork_8predict_proba(s } __Pyx_XDECREF_SET(__pyx_8genexpr3__pyx_v_i, __pyx_t_2); __pyx_t_2 = 0; - __pyx_t_2 = PyTuple_New(2); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 37, __pyx_L5_error) + __pyx_t_2 = PyTuple_New(2); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 38, __pyx_L5_error) __Pyx_GOTREF(__pyx_t_2); __Pyx_INCREF(__pyx_slice_); __Pyx_GIVEREF(__pyx_slice_); @@ -2341,10 +2342,10 @@ static PyObject *__pyx_pf_10bayesclass_8BayesNet_12BayesNetwork_8predict_proba(s __Pyx_INCREF(__pyx_8genexpr3__pyx_v_i); __Pyx_GIVEREF(__pyx_8genexpr3__pyx_v_i); PyTuple_SET_ITEM(__pyx_t_2, 1, __pyx_8genexpr3__pyx_v_i); - __pyx_t_6 = __Pyx_PyObject_GetItem(__pyx_v_X, __pyx_t_2); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 37, __pyx_L5_error) + __pyx_t_6 = __Pyx_PyObject_GetItem(__pyx_v_X, __pyx_t_2); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 38, __pyx_L5_error) __Pyx_GOTREF(__pyx_t_6); __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - if (unlikely(__Pyx_ListComp_Append(__pyx_t_1, (PyObject*)__pyx_t_6))) __PYX_ERR(0, 37, __pyx_L5_error) + if (unlikely(__Pyx_ListComp_Append(__pyx_t_1, (PyObject*)__pyx_t_6))) __PYX_ERR(0, 38, __pyx_L5_error) __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; } __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; @@ -2358,7 +2359,7 @@ static PyObject *__pyx_pf_10bayesclass_8BayesNet_12BayesNetwork_8predict_proba(s __pyx_v_X_ = ((PyObject*)__pyx_t_1); __pyx_t_1 = 0; - /* "bayesclass/BayesNetwork.pyx":38 + /* "bayesclass/BayesNetwork.pyx":39 * def predict_proba(self, X): * X_ = [X[:, i] for i in range(X.shape[1])] * return self.thisptr.predict_proba(X_) # <<<<<<<<<<<<<< @@ -2366,14 +2367,14 @@ static PyObject *__pyx_pf_10bayesclass_8BayesNet_12BayesNetwork_8predict_proba(s * X_ = [X[:, i] for i in range(X.shape[1])] */ __Pyx_XDECREF(__pyx_r); - __pyx_t_7 = __pyx_convert_vector_from_py_std_3a__3a_vector_3c_int_3e___(__pyx_v_X_); if (unlikely(PyErr_Occurred())) __PYX_ERR(0, 38, __pyx_L1_error) - __pyx_t_1 = __pyx_convert_vector_to_py_std_3a__3a_vector_3c_double_3e___(__pyx_v_self->thisptr->predict_proba(__pyx_t_7)); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 38, __pyx_L1_error) + __pyx_t_7 = __pyx_convert_vector_from_py_std_3a__3a_vector_3c_int_3e___(__pyx_v_X_); if (unlikely(PyErr_Occurred())) __PYX_ERR(0, 39, __pyx_L1_error) + __pyx_t_1 = __pyx_convert_vector_to_py_std_3a__3a_vector_3c_double_3e___(__pyx_v_self->thisptr->predict_proba(__pyx_t_7)); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 39, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __pyx_r = __pyx_t_1; __pyx_t_1 = 0; goto __pyx_L0; - /* "bayesclass/BayesNetwork.pyx":36 + /* "bayesclass/BayesNetwork.pyx":37 * X_ = [X[:, i] for i in range(X.shape[1])] * return self.thisptr.predict(X_) * def predict_proba(self, X): # <<<<<<<<<<<<<< @@ -2397,7 +2398,7 @@ static PyObject *__pyx_pf_10bayesclass_8BayesNet_12BayesNetwork_8predict_proba(s return __pyx_r; } -/* "bayesclass/BayesNetwork.pyx":39 +/* "bayesclass/BayesNetwork.pyx":40 * X_ = [X[:, i] for i in range(X.shape[1])] * return self.thisptr.predict_proba(X_) * def score(self, X, y): # <<<<<<<<<<<<<< @@ -2439,11 +2440,11 @@ static PyObject *__pyx_pw_10bayesclass_8BayesNet_12BayesNetwork_11score(PyObject case 1: if (likely((values[1] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_y)) != 0)) kw_args--; else { - __Pyx_RaiseArgtupleInvalid("score", 1, 2, 2, 1); __PYX_ERR(0, 39, __pyx_L3_error) + __Pyx_RaiseArgtupleInvalid("score", 1, 2, 2, 1); __PYX_ERR(0, 40, __pyx_L3_error) } } if (unlikely(kw_args > 0)) { - if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "score") < 0)) __PYX_ERR(0, 39, __pyx_L3_error) + if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "score") < 0)) __PYX_ERR(0, 40, __pyx_L3_error) } } else if (PyTuple_GET_SIZE(__pyx_args) != 2) { goto __pyx_L5_argtuple_error; @@ -2456,7 +2457,7 @@ static PyObject *__pyx_pw_10bayesclass_8BayesNet_12BayesNetwork_11score(PyObject } goto __pyx_L4_argument_unpacking_done; __pyx_L5_argtuple_error:; - __Pyx_RaiseArgtupleInvalid("score", 1, 2, 2, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 39, __pyx_L3_error) + __Pyx_RaiseArgtupleInvalid("score", 1, 2, 2, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 40, __pyx_L3_error) __pyx_L3_error:; __Pyx_AddTraceback("bayesclass.BayesNet.BayesNetwork.score", __pyx_clineno, __pyx_lineno, __pyx_filename); __Pyx_RefNannyFinishContext(); @@ -2487,7 +2488,7 @@ static PyObject *__pyx_pf_10bayesclass_8BayesNet_12BayesNetwork_10score(struct _ int __pyx_clineno = 0; __Pyx_RefNannySetupContext("score", 0); - /* "bayesclass/BayesNetwork.pyx":40 + /* "bayesclass/BayesNetwork.pyx":41 * return self.thisptr.predict_proba(X_) * def score(self, X, y): * X_ = [X[:, i] for i in range(X.shape[1])] # <<<<<<<<<<<<<< @@ -2495,23 +2496,23 @@ static PyObject *__pyx_pf_10bayesclass_8BayesNet_12BayesNetwork_10score(struct _ * def addNode(self, name, states): */ { /* enter inner scope */ - __pyx_t_1 = PyList_New(0); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 40, __pyx_L5_error) + __pyx_t_1 = PyList_New(0); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 41, __pyx_L5_error) __Pyx_GOTREF(__pyx_t_1); - __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_v_X, __pyx_n_s_shape); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 40, __pyx_L5_error) + __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_v_X, __pyx_n_s_shape); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 41, __pyx_L5_error) __Pyx_GOTREF(__pyx_t_2); - __pyx_t_3 = __Pyx_GetItemInt(__pyx_t_2, 1, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 40, __pyx_L5_error) + __pyx_t_3 = __Pyx_GetItemInt(__pyx_t_2, 1, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 41, __pyx_L5_error) __Pyx_GOTREF(__pyx_t_3); __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __pyx_t_2 = __Pyx_PyObject_CallOneArg(__pyx_builtin_range, __pyx_t_3); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 40, __pyx_L5_error) + __pyx_t_2 = __Pyx_PyObject_CallOneArg(__pyx_builtin_range, __pyx_t_3); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 41, __pyx_L5_error) __Pyx_GOTREF(__pyx_t_2); __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; if (likely(PyList_CheckExact(__pyx_t_2)) || PyTuple_CheckExact(__pyx_t_2)) { __pyx_t_3 = __pyx_t_2; __Pyx_INCREF(__pyx_t_3); __pyx_t_4 = 0; __pyx_t_5 = NULL; } else { - __pyx_t_4 = -1; __pyx_t_3 = PyObject_GetIter(__pyx_t_2); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 40, __pyx_L5_error) + __pyx_t_4 = -1; __pyx_t_3 = PyObject_GetIter(__pyx_t_2); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 41, __pyx_L5_error) __Pyx_GOTREF(__pyx_t_3); - __pyx_t_5 = Py_TYPE(__pyx_t_3)->tp_iternext; if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 40, __pyx_L5_error) + __pyx_t_5 = Py_TYPE(__pyx_t_3)->tp_iternext; if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 41, __pyx_L5_error) } __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; for (;;) { @@ -2519,17 +2520,17 @@ static PyObject *__pyx_pf_10bayesclass_8BayesNet_12BayesNetwork_10score(struct _ if (likely(PyList_CheckExact(__pyx_t_3))) { if (__pyx_t_4 >= PyList_GET_SIZE(__pyx_t_3)) break; #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS - __pyx_t_2 = PyList_GET_ITEM(__pyx_t_3, __pyx_t_4); __Pyx_INCREF(__pyx_t_2); __pyx_t_4++; if (unlikely(0 < 0)) __PYX_ERR(0, 40, __pyx_L5_error) + __pyx_t_2 = PyList_GET_ITEM(__pyx_t_3, __pyx_t_4); __Pyx_INCREF(__pyx_t_2); __pyx_t_4++; if (unlikely(0 < 0)) __PYX_ERR(0, 41, __pyx_L5_error) #else - __pyx_t_2 = PySequence_ITEM(__pyx_t_3, __pyx_t_4); __pyx_t_4++; if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 40, __pyx_L5_error) + __pyx_t_2 = PySequence_ITEM(__pyx_t_3, __pyx_t_4); __pyx_t_4++; if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 41, __pyx_L5_error) __Pyx_GOTREF(__pyx_t_2); #endif } else { if (__pyx_t_4 >= PyTuple_GET_SIZE(__pyx_t_3)) break; #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS - __pyx_t_2 = PyTuple_GET_ITEM(__pyx_t_3, __pyx_t_4); __Pyx_INCREF(__pyx_t_2); __pyx_t_4++; if (unlikely(0 < 0)) __PYX_ERR(0, 40, __pyx_L5_error) + __pyx_t_2 = PyTuple_GET_ITEM(__pyx_t_3, __pyx_t_4); __Pyx_INCREF(__pyx_t_2); __pyx_t_4++; if (unlikely(0 < 0)) __PYX_ERR(0, 41, __pyx_L5_error) #else - __pyx_t_2 = PySequence_ITEM(__pyx_t_3, __pyx_t_4); __pyx_t_4++; if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 40, __pyx_L5_error) + __pyx_t_2 = PySequence_ITEM(__pyx_t_3, __pyx_t_4); __pyx_t_4++; if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 41, __pyx_L5_error) __Pyx_GOTREF(__pyx_t_2); #endif } @@ -2539,7 +2540,7 @@ static PyObject *__pyx_pf_10bayesclass_8BayesNet_12BayesNetwork_10score(struct _ PyObject* exc_type = PyErr_Occurred(); if (exc_type) { if (likely(__Pyx_PyErr_GivenExceptionMatches(exc_type, PyExc_StopIteration))) PyErr_Clear(); - else __PYX_ERR(0, 40, __pyx_L5_error) + else __PYX_ERR(0, 41, __pyx_L5_error) } break; } @@ -2547,7 +2548,7 @@ static PyObject *__pyx_pf_10bayesclass_8BayesNet_12BayesNetwork_10score(struct _ } __Pyx_XDECREF_SET(__pyx_8genexpr4__pyx_v_i, __pyx_t_2); __pyx_t_2 = 0; - __pyx_t_2 = PyTuple_New(2); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 40, __pyx_L5_error) + __pyx_t_2 = PyTuple_New(2); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 41, __pyx_L5_error) __Pyx_GOTREF(__pyx_t_2); __Pyx_INCREF(__pyx_slice_); __Pyx_GIVEREF(__pyx_slice_); @@ -2555,10 +2556,10 @@ static PyObject *__pyx_pf_10bayesclass_8BayesNet_12BayesNetwork_10score(struct _ __Pyx_INCREF(__pyx_8genexpr4__pyx_v_i); __Pyx_GIVEREF(__pyx_8genexpr4__pyx_v_i); PyTuple_SET_ITEM(__pyx_t_2, 1, __pyx_8genexpr4__pyx_v_i); - __pyx_t_6 = __Pyx_PyObject_GetItem(__pyx_v_X, __pyx_t_2); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 40, __pyx_L5_error) + __pyx_t_6 = __Pyx_PyObject_GetItem(__pyx_v_X, __pyx_t_2); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 41, __pyx_L5_error) __Pyx_GOTREF(__pyx_t_6); __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - if (unlikely(__Pyx_ListComp_Append(__pyx_t_1, (PyObject*)__pyx_t_6))) __PYX_ERR(0, 40, __pyx_L5_error) + if (unlikely(__Pyx_ListComp_Append(__pyx_t_1, (PyObject*)__pyx_t_6))) __PYX_ERR(0, 41, __pyx_L5_error) __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; } __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; @@ -2572,7 +2573,7 @@ static PyObject *__pyx_pf_10bayesclass_8BayesNet_12BayesNetwork_10score(struct _ __pyx_v_X_ = ((PyObject*)__pyx_t_1); __pyx_t_1 = 0; - /* "bayesclass/BayesNetwork.pyx":41 + /* "bayesclass/BayesNetwork.pyx":42 * def score(self, X, y): * X_ = [X[:, i] for i in range(X.shape[1])] * return self.thisptr.score(X_, y) # <<<<<<<<<<<<<< @@ -2580,15 +2581,15 @@ static PyObject *__pyx_pf_10bayesclass_8BayesNet_12BayesNetwork_10score(struct _ * self.thisptr.addNode(str.encode(name), states) */ __Pyx_XDECREF(__pyx_r); - __pyx_t_7 = __pyx_convert_vector_from_py_std_3a__3a_vector_3c_int_3e___(__pyx_v_X_); if (unlikely(PyErr_Occurred())) __PYX_ERR(0, 41, __pyx_L1_error) - __pyx_t_8 = __pyx_convert_vector_from_py_int(__pyx_v_y); if (unlikely(PyErr_Occurred())) __PYX_ERR(0, 41, __pyx_L1_error) - __pyx_t_1 = PyFloat_FromDouble(__pyx_v_self->thisptr->score(__pyx_t_7, __pyx_t_8)); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 41, __pyx_L1_error) + __pyx_t_7 = __pyx_convert_vector_from_py_std_3a__3a_vector_3c_int_3e___(__pyx_v_X_); if (unlikely(PyErr_Occurred())) __PYX_ERR(0, 42, __pyx_L1_error) + __pyx_t_8 = __pyx_convert_vector_from_py_int(__pyx_v_y); if (unlikely(PyErr_Occurred())) __PYX_ERR(0, 42, __pyx_L1_error) + __pyx_t_1 = PyFloat_FromDouble(__pyx_v_self->thisptr->score(__pyx_t_7, __pyx_t_8)); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 42, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __pyx_r = __pyx_t_1; __pyx_t_1 = 0; goto __pyx_L0; - /* "bayesclass/BayesNetwork.pyx":39 + /* "bayesclass/BayesNetwork.pyx":40 * X_ = [X[:, i] for i in range(X.shape[1])] * return self.thisptr.predict_proba(X_) * def score(self, X, y): # <<<<<<<<<<<<<< @@ -2612,7 +2613,7 @@ static PyObject *__pyx_pf_10bayesclass_8BayesNet_12BayesNetwork_10score(struct _ return __pyx_r; } -/* "bayesclass/BayesNetwork.pyx":42 +/* "bayesclass/BayesNetwork.pyx":43 * X_ = [X[:, i] for i in range(X.shape[1])] * return self.thisptr.score(X_, y) * def addNode(self, name, states): # <<<<<<<<<<<<<< @@ -2654,11 +2655,11 @@ static PyObject *__pyx_pw_10bayesclass_8BayesNet_12BayesNetwork_13addNode(PyObje case 1: if (likely((values[1] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_states)) != 0)) kw_args--; else { - __Pyx_RaiseArgtupleInvalid("addNode", 1, 2, 2, 1); __PYX_ERR(0, 42, __pyx_L3_error) + __Pyx_RaiseArgtupleInvalid("addNode", 1, 2, 2, 1); __PYX_ERR(0, 43, __pyx_L3_error) } } if (unlikely(kw_args > 0)) { - if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "addNode") < 0)) __PYX_ERR(0, 42, __pyx_L3_error) + if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "addNode") < 0)) __PYX_ERR(0, 43, __pyx_L3_error) } } else if (PyTuple_GET_SIZE(__pyx_args) != 2) { goto __pyx_L5_argtuple_error; @@ -2671,7 +2672,7 @@ static PyObject *__pyx_pw_10bayesclass_8BayesNet_12BayesNetwork_13addNode(PyObje } goto __pyx_L4_argument_unpacking_done; __pyx_L5_argtuple_error:; - __Pyx_RaiseArgtupleInvalid("addNode", 1, 2, 2, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 42, __pyx_L3_error) + __Pyx_RaiseArgtupleInvalid("addNode", 1, 2, 2, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 43, __pyx_L3_error) __pyx_L3_error:; __Pyx_AddTraceback("bayesclass.BayesNet.BayesNetwork.addNode", __pyx_clineno, __pyx_lineno, __pyx_filename); __Pyx_RefNannyFinishContext(); @@ -2697,14 +2698,14 @@ static PyObject *__pyx_pf_10bayesclass_8BayesNet_12BayesNetwork_12addNode(struct int __pyx_clineno = 0; __Pyx_RefNannySetupContext("addNode", 0); - /* "bayesclass/BayesNetwork.pyx":43 + /* "bayesclass/BayesNetwork.pyx":44 * return self.thisptr.score(X_, y) * def addNode(self, name, states): * self.thisptr.addNode(str.encode(name), states) # <<<<<<<<<<<<<< * def addEdge(self, source, destination): * self.thisptr.addEdge(str.encode(source), str.encode(destination)) */ - __pyx_t_2 = __Pyx_PyObject_GetAttrStr(((PyObject *)(&PyUnicode_Type)), __pyx_n_s_encode); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 43, __pyx_L1_error) + __pyx_t_2 = __Pyx_PyObject_GetAttrStr(((PyObject *)(&PyUnicode_Type)), __pyx_n_s_encode); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 44, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __pyx_t_3 = NULL; if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_2))) { @@ -2718,15 +2719,15 @@ static PyObject *__pyx_pf_10bayesclass_8BayesNet_12BayesNetwork_12addNode(struct } __pyx_t_1 = (__pyx_t_3) ? __Pyx_PyObject_Call2Args(__pyx_t_2, __pyx_t_3, __pyx_v_name) : __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_v_name); __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0; - if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 43, __pyx_L1_error) + if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 44, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __pyx_t_4 = __pyx_convert_string_from_py_std__in_string(__pyx_t_1); if (unlikely(PyErr_Occurred())) __PYX_ERR(0, 43, __pyx_L1_error) + __pyx_t_4 = __pyx_convert_string_from_py_std__in_string(__pyx_t_1); if (unlikely(PyErr_Occurred())) __PYX_ERR(0, 44, __pyx_L1_error) __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __pyx_t_5 = __Pyx_PyInt_As_int(__pyx_v_states); if (unlikely((__pyx_t_5 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 43, __pyx_L1_error) + __pyx_t_5 = __Pyx_PyInt_As_int(__pyx_v_states); if (unlikely((__pyx_t_5 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 44, __pyx_L1_error) __pyx_v_self->thisptr->addNode(__pyx_t_4, __pyx_t_5); - /* "bayesclass/BayesNetwork.pyx":42 + /* "bayesclass/BayesNetwork.pyx":43 * X_ = [X[:, i] for i in range(X.shape[1])] * return self.thisptr.score(X_, y) * def addNode(self, name, states): # <<<<<<<<<<<<<< @@ -2749,7 +2750,7 @@ static PyObject *__pyx_pf_10bayesclass_8BayesNet_12BayesNetwork_12addNode(struct return __pyx_r; } -/* "bayesclass/BayesNetwork.pyx":44 +/* "bayesclass/BayesNetwork.pyx":45 * def addNode(self, name, states): * self.thisptr.addNode(str.encode(name), states) * def addEdge(self, source, destination): # <<<<<<<<<<<<<< @@ -2791,11 +2792,11 @@ static PyObject *__pyx_pw_10bayesclass_8BayesNet_12BayesNetwork_15addEdge(PyObje case 1: if (likely((values[1] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_destination)) != 0)) kw_args--; else { - __Pyx_RaiseArgtupleInvalid("addEdge", 1, 2, 2, 1); __PYX_ERR(0, 44, __pyx_L3_error) + __Pyx_RaiseArgtupleInvalid("addEdge", 1, 2, 2, 1); __PYX_ERR(0, 45, __pyx_L3_error) } } if (unlikely(kw_args > 0)) { - if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "addEdge") < 0)) __PYX_ERR(0, 44, __pyx_L3_error) + if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "addEdge") < 0)) __PYX_ERR(0, 45, __pyx_L3_error) } } else if (PyTuple_GET_SIZE(__pyx_args) != 2) { goto __pyx_L5_argtuple_error; @@ -2808,7 +2809,7 @@ static PyObject *__pyx_pw_10bayesclass_8BayesNet_12BayesNetwork_15addEdge(PyObje } goto __pyx_L4_argument_unpacking_done; __pyx_L5_argtuple_error:; - __Pyx_RaiseArgtupleInvalid("addEdge", 1, 2, 2, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 44, __pyx_L3_error) + __Pyx_RaiseArgtupleInvalid("addEdge", 1, 2, 2, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 45, __pyx_L3_error) __pyx_L3_error:; __Pyx_AddTraceback("bayesclass.BayesNet.BayesNetwork.addEdge", __pyx_clineno, __pyx_lineno, __pyx_filename); __Pyx_RefNannyFinishContext(); @@ -2834,14 +2835,14 @@ static PyObject *__pyx_pf_10bayesclass_8BayesNet_12BayesNetwork_14addEdge(struct int __pyx_clineno = 0; __Pyx_RefNannySetupContext("addEdge", 0); - /* "bayesclass/BayesNetwork.pyx":45 + /* "bayesclass/BayesNetwork.pyx":46 * self.thisptr.addNode(str.encode(name), states) * def addEdge(self, source, destination): * self.thisptr.addEdge(str.encode(source), str.encode(destination)) # <<<<<<<<<<<<<< * def getFeatures(self): * res = self.thisptr.getFeatures() */ - __pyx_t_2 = __Pyx_PyObject_GetAttrStr(((PyObject *)(&PyUnicode_Type)), __pyx_n_s_encode); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 45, __pyx_L1_error) + __pyx_t_2 = __Pyx_PyObject_GetAttrStr(((PyObject *)(&PyUnicode_Type)), __pyx_n_s_encode); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 46, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __pyx_t_3 = NULL; if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_2))) { @@ -2855,12 +2856,12 @@ static PyObject *__pyx_pf_10bayesclass_8BayesNet_12BayesNetwork_14addEdge(struct } __pyx_t_1 = (__pyx_t_3) ? __Pyx_PyObject_Call2Args(__pyx_t_2, __pyx_t_3, __pyx_v_source) : __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_v_source); __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0; - if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 45, __pyx_L1_error) + if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 46, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __pyx_t_4 = __pyx_convert_string_from_py_std__in_string(__pyx_t_1); if (unlikely(PyErr_Occurred())) __PYX_ERR(0, 45, __pyx_L1_error) + __pyx_t_4 = __pyx_convert_string_from_py_std__in_string(__pyx_t_1); if (unlikely(PyErr_Occurred())) __PYX_ERR(0, 46, __pyx_L1_error) __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __pyx_t_2 = __Pyx_PyObject_GetAttrStr(((PyObject *)(&PyUnicode_Type)), __pyx_n_s_encode); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 45, __pyx_L1_error) + __pyx_t_2 = __Pyx_PyObject_GetAttrStr(((PyObject *)(&PyUnicode_Type)), __pyx_n_s_encode); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 46, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __pyx_t_3 = NULL; if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_2))) { @@ -2874,19 +2875,19 @@ static PyObject *__pyx_pf_10bayesclass_8BayesNet_12BayesNetwork_14addEdge(struct } __pyx_t_1 = (__pyx_t_3) ? __Pyx_PyObject_Call2Args(__pyx_t_2, __pyx_t_3, __pyx_v_destination) : __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_v_destination); __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0; - if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 45, __pyx_L1_error) + if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 46, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __pyx_t_5 = __pyx_convert_string_from_py_std__in_string(__pyx_t_1); if (unlikely(PyErr_Occurred())) __PYX_ERR(0, 45, __pyx_L1_error) + __pyx_t_5 = __pyx_convert_string_from_py_std__in_string(__pyx_t_1); if (unlikely(PyErr_Occurred())) __PYX_ERR(0, 46, __pyx_L1_error) __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; try { __pyx_v_self->thisptr->addEdge(__pyx_t_4, __pyx_t_5); } catch(...) { __Pyx_CppExn2PyErr(); - __PYX_ERR(0, 45, __pyx_L1_error) + __PYX_ERR(0, 46, __pyx_L1_error) } - /* "bayesclass/BayesNetwork.pyx":44 + /* "bayesclass/BayesNetwork.pyx":45 * def addNode(self, name, states): * self.thisptr.addNode(str.encode(name), states) * def addEdge(self, source, destination): # <<<<<<<<<<<<<< @@ -2909,7 +2910,7 @@ static PyObject *__pyx_pf_10bayesclass_8BayesNet_12BayesNetwork_14addEdge(struct return __pyx_r; } -/* "bayesclass/BayesNetwork.pyx":46 +/* "bayesclass/BayesNetwork.pyx":47 * def addEdge(self, source, destination): * self.thisptr.addEdge(str.encode(source), str.encode(destination)) * def getFeatures(self): # <<<<<<<<<<<<<< @@ -2944,7 +2945,7 @@ static PyObject *__pyx_pf_10bayesclass_8BayesNet_12BayesNetwork_16getFeatures(st int __pyx_clineno = 0; __Pyx_RefNannySetupContext("getFeatures", 0); - /* "bayesclass/BayesNetwork.pyx":47 + /* "bayesclass/BayesNetwork.pyx":48 * self.thisptr.addEdge(str.encode(source), str.encode(destination)) * def getFeatures(self): * res = self.thisptr.getFeatures() # <<<<<<<<<<<<<< @@ -2953,7 +2954,7 @@ static PyObject *__pyx_pf_10bayesclass_8BayesNet_12BayesNetwork_16getFeatures(st */ __pyx_v_res = __pyx_v_self->thisptr->getFeatures(); - /* "bayesclass/BayesNetwork.pyx":48 + /* "bayesclass/BayesNetwork.pyx":49 * def getFeatures(self): * res = self.thisptr.getFeatures() * return [x.decode() for x in res] # <<<<<<<<<<<<<< @@ -2962,7 +2963,7 @@ static PyObject *__pyx_pf_10bayesclass_8BayesNet_12BayesNetwork_16getFeatures(st */ __Pyx_XDECREF(__pyx_r); { /* enter inner scope */ - __pyx_t_1 = PyList_New(0); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 48, __pyx_L1_error) + __pyx_t_1 = PyList_New(0); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 49, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __pyx_t_2 = __pyx_v_res.begin(); for (;;) { @@ -2970,9 +2971,9 @@ static PyObject *__pyx_pf_10bayesclass_8BayesNet_12BayesNetwork_16getFeatures(st __pyx_t_3 = *__pyx_t_2; ++__pyx_t_2; __pyx_8genexpr5__pyx_v_x = __pyx_t_3; - __pyx_t_4 = __Pyx_decode_cpp_string(__pyx_8genexpr5__pyx_v_x, 0, PY_SSIZE_T_MAX, NULL, NULL, NULL); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 48, __pyx_L1_error) + __pyx_t_4 = __Pyx_decode_cpp_string(__pyx_8genexpr5__pyx_v_x, 0, PY_SSIZE_T_MAX, NULL, NULL, NULL); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 49, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); - if (unlikely(__Pyx_ListComp_Append(__pyx_t_1, (PyObject*)__pyx_t_4))) __PYX_ERR(0, 48, __pyx_L1_error) + if (unlikely(__Pyx_ListComp_Append(__pyx_t_1, (PyObject*)__pyx_t_4))) __PYX_ERR(0, 49, __pyx_L1_error) __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; } } /* exit inner scope */ @@ -2980,7 +2981,7 @@ static PyObject *__pyx_pf_10bayesclass_8BayesNet_12BayesNetwork_16getFeatures(st __pyx_t_1 = 0; goto __pyx_L0; - /* "bayesclass/BayesNetwork.pyx":46 + /* "bayesclass/BayesNetwork.pyx":47 * def addEdge(self, source, destination): * self.thisptr.addEdge(str.encode(source), str.encode(destination)) * def getFeatures(self): # <<<<<<<<<<<<<< @@ -3000,7 +3001,7 @@ static PyObject *__pyx_pf_10bayesclass_8BayesNet_12BayesNetwork_16getFeatures(st return __pyx_r; } -/* "bayesclass/BayesNetwork.pyx":49 +/* "bayesclass/BayesNetwork.pyx":50 * res = self.thisptr.getFeatures() * return [x.decode() for x in res] * def getStates(self): # <<<<<<<<<<<<<< @@ -3030,7 +3031,7 @@ static PyObject *__pyx_pf_10bayesclass_8BayesNet_12BayesNetwork_18getStates(stru int __pyx_clineno = 0; __Pyx_RefNannySetupContext("getStates", 0); - /* "bayesclass/BayesNetwork.pyx":50 + /* "bayesclass/BayesNetwork.pyx":51 * return [x.decode() for x in res] * def getStates(self): * return self.thisptr.getStates() # <<<<<<<<<<<<<< @@ -3038,13 +3039,13 @@ static PyObject *__pyx_pf_10bayesclass_8BayesNet_12BayesNetwork_18getStates(stru * return self.thisptr.getClassName().decode() */ __Pyx_XDECREF(__pyx_r); - __pyx_t_1 = __Pyx_PyInt_From_int(__pyx_v_self->thisptr->getStates()); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 50, __pyx_L1_error) + __pyx_t_1 = __Pyx_PyInt_From_int(__pyx_v_self->thisptr->getStates()); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 51, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __pyx_r = __pyx_t_1; __pyx_t_1 = 0; goto __pyx_L0; - /* "bayesclass/BayesNetwork.pyx":49 + /* "bayesclass/BayesNetwork.pyx":50 * res = self.thisptr.getFeatures() * return [x.decode() for x in res] * def getStates(self): # <<<<<<<<<<<<<< @@ -3063,7 +3064,7 @@ static PyObject *__pyx_pf_10bayesclass_8BayesNet_12BayesNetwork_18getStates(stru return __pyx_r; } -/* "bayesclass/BayesNetwork.pyx":51 +/* "bayesclass/BayesNetwork.pyx":52 * def getStates(self): * return self.thisptr.getStates() * def getClassName(self): # <<<<<<<<<<<<<< @@ -3093,7 +3094,7 @@ static PyObject *__pyx_pf_10bayesclass_8BayesNet_12BayesNetwork_20getClassName(s int __pyx_clineno = 0; __Pyx_RefNannySetupContext("getClassName", 0); - /* "bayesclass/BayesNetwork.pyx":52 + /* "bayesclass/BayesNetwork.pyx":53 * return self.thisptr.getStates() * def getClassName(self): * return self.thisptr.getClassName().decode() # <<<<<<<<<<<<<< @@ -3101,13 +3102,13 @@ static PyObject *__pyx_pf_10bayesclass_8BayesNet_12BayesNetwork_20getClassName(s * return self.thisptr.getClassNumStates() */ __Pyx_XDECREF(__pyx_r); - __pyx_t_1 = __Pyx_decode_cpp_string(__pyx_v_self->thisptr->getClassName(), 0, PY_SSIZE_T_MAX, NULL, NULL, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 52, __pyx_L1_error) + __pyx_t_1 = __Pyx_decode_cpp_string(__pyx_v_self->thisptr->getClassName(), 0, PY_SSIZE_T_MAX, NULL, NULL, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 53, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __pyx_r = __pyx_t_1; __pyx_t_1 = 0; goto __pyx_L0; - /* "bayesclass/BayesNetwork.pyx":51 + /* "bayesclass/BayesNetwork.pyx":52 * def getStates(self): * return self.thisptr.getStates() * def getClassName(self): # <<<<<<<<<<<<<< @@ -3126,12 +3127,12 @@ static PyObject *__pyx_pf_10bayesclass_8BayesNet_12BayesNetwork_20getClassName(s return __pyx_r; } -/* "bayesclass/BayesNetwork.pyx":53 +/* "bayesclass/BayesNetwork.pyx":54 * def getClassName(self): * return self.thisptr.getClassName().decode() * def getClassNumStates(self): # <<<<<<<<<<<<<< * return self.thisptr.getClassNumStates() - * def __reduce__(self): + * def show(self): */ /* Python wrapper */ @@ -3156,26 +3157,26 @@ static PyObject *__pyx_pf_10bayesclass_8BayesNet_12BayesNetwork_22getClassNumSta int __pyx_clineno = 0; __Pyx_RefNannySetupContext("getClassNumStates", 0); - /* "bayesclass/BayesNetwork.pyx":54 + /* "bayesclass/BayesNetwork.pyx":55 * return self.thisptr.getClassName().decode() * def getClassNumStates(self): * return self.thisptr.getClassNumStates() # <<<<<<<<<<<<<< - * def __reduce__(self): - * return (BayesNetwork, ()) + * def show(self): + * return self.thisptr.show() */ __Pyx_XDECREF(__pyx_r); - __pyx_t_1 = __Pyx_PyInt_From_int(__pyx_v_self->thisptr->getClassNumStates()); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 54, __pyx_L1_error) + __pyx_t_1 = __Pyx_PyInt_From_int(__pyx_v_self->thisptr->getClassNumStates()); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 55, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __pyx_r = __pyx_t_1; __pyx_t_1 = 0; goto __pyx_L0; - /* "bayesclass/BayesNetwork.pyx":53 + /* "bayesclass/BayesNetwork.pyx":54 * def getClassName(self): * return self.thisptr.getClassName().decode() * def getClassNumStates(self): # <<<<<<<<<<<<<< * return self.thisptr.getClassNumStates() - * def __reduce__(self): + * def show(self): */ /* function exit code */ @@ -3189,28 +3190,91 @@ static PyObject *__pyx_pf_10bayesclass_8BayesNet_12BayesNetwork_22getClassNumSta return __pyx_r; } -/* "bayesclass/BayesNetwork.pyx":55 +/* "bayesclass/BayesNetwork.pyx":56 * def getClassNumStates(self): * return self.thisptr.getClassNumStates() - * def __reduce__(self): # <<<<<<<<<<<<<< - * return (BayesNetwork, ()) - * + * def show(self): # <<<<<<<<<<<<<< + * return self.thisptr.show() + * def __reduce__(self): */ /* Python wrapper */ -static PyObject *__pyx_pw_10bayesclass_8BayesNet_12BayesNetwork_25__reduce__(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/ -static PyObject *__pyx_pw_10bayesclass_8BayesNet_12BayesNetwork_25__reduce__(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) { +static PyObject *__pyx_pw_10bayesclass_8BayesNet_12BayesNetwork_25show(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/ +static PyObject *__pyx_pw_10bayesclass_8BayesNet_12BayesNetwork_25show(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) { PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("__reduce__ (wrapper)", 0); - __pyx_r = __pyx_pf_10bayesclass_8BayesNet_12BayesNetwork_24__reduce__(((struct __pyx_obj_10bayesclass_8BayesNet_BayesNetwork *)__pyx_v_self)); + __Pyx_RefNannySetupContext("show (wrapper)", 0); + __pyx_r = __pyx_pf_10bayesclass_8BayesNet_12BayesNetwork_24show(((struct __pyx_obj_10bayesclass_8BayesNet_BayesNetwork *)__pyx_v_self)); /* function exit code */ __Pyx_RefNannyFinishContext(); return __pyx_r; } -static PyObject *__pyx_pf_10bayesclass_8BayesNet_12BayesNetwork_24__reduce__(CYTHON_UNUSED struct __pyx_obj_10bayesclass_8BayesNet_BayesNetwork *__pyx_v_self) { +static PyObject *__pyx_pf_10bayesclass_8BayesNet_12BayesNetwork_24show(struct __pyx_obj_10bayesclass_8BayesNet_BayesNetwork *__pyx_v_self) { + PyObject *__pyx_r = NULL; + __Pyx_RefNannyDeclarations + PyObject *__pyx_t_1 = NULL; + int __pyx_lineno = 0; + const char *__pyx_filename = NULL; + int __pyx_clineno = 0; + __Pyx_RefNannySetupContext("show", 0); + + /* "bayesclass/BayesNetwork.pyx":57 + * return self.thisptr.getClassNumStates() + * def show(self): + * return self.thisptr.show() # <<<<<<<<<<<<<< + * def __reduce__(self): + * return (BayesNetwork, ()) + */ + __Pyx_XDECREF(__pyx_r); + __pyx_t_1 = __Pyx_void_to_None(__pyx_v_self->thisptr->show()); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 57, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_r = __pyx_t_1; + __pyx_t_1 = 0; + goto __pyx_L0; + + /* "bayesclass/BayesNetwork.pyx":56 + * def getClassNumStates(self): + * return self.thisptr.getClassNumStates() + * def show(self): # <<<<<<<<<<<<<< + * return self.thisptr.show() + * def __reduce__(self): + */ + + /* function exit code */ + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_1); + __Pyx_AddTraceback("bayesclass.BayesNet.BayesNetwork.show", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; + __pyx_L0:; + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "bayesclass/BayesNetwork.pyx":58 + * def show(self): + * return self.thisptr.show() + * def __reduce__(self): # <<<<<<<<<<<<<< + * return (BayesNetwork, ()) + * + */ + +/* Python wrapper */ +static PyObject *__pyx_pw_10bayesclass_8BayesNet_12BayesNetwork_27__reduce__(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/ +static PyObject *__pyx_pw_10bayesclass_8BayesNet_12BayesNetwork_27__reduce__(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) { + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__reduce__ (wrapper)", 0); + __pyx_r = __pyx_pf_10bayesclass_8BayesNet_12BayesNetwork_26__reduce__(((struct __pyx_obj_10bayesclass_8BayesNet_BayesNetwork *)__pyx_v_self)); + + /* function exit code */ + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +static PyObject *__pyx_pf_10bayesclass_8BayesNet_12BayesNetwork_26__reduce__(CYTHON_UNUSED struct __pyx_obj_10bayesclass_8BayesNet_BayesNetwork *__pyx_v_self) { PyObject *__pyx_r = NULL; __Pyx_RefNannyDeclarations PyObject *__pyx_t_1 = NULL; @@ -3219,15 +3283,15 @@ static PyObject *__pyx_pf_10bayesclass_8BayesNet_12BayesNetwork_24__reduce__(CYT int __pyx_clineno = 0; __Pyx_RefNannySetupContext("__reduce__", 0); - /* "bayesclass/BayesNetwork.pyx":56 - * return self.thisptr.getClassNumStates() + /* "bayesclass/BayesNetwork.pyx":59 + * return self.thisptr.show() * def __reduce__(self): * return (BayesNetwork, ()) # <<<<<<<<<<<<<< * * cdef extern from "Metrics.hpp" namespace "bayesnet": */ __Pyx_XDECREF(__pyx_r); - __pyx_t_1 = PyTuple_New(2); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 56, __pyx_L1_error) + __pyx_t_1 = PyTuple_New(2); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 59, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_INCREF(((PyObject *)__pyx_ptype_10bayesclass_8BayesNet_BayesNetwork)); __Pyx_GIVEREF(((PyObject *)__pyx_ptype_10bayesclass_8BayesNet_BayesNetwork)); @@ -3239,9 +3303,9 @@ static PyObject *__pyx_pf_10bayesclass_8BayesNet_12BayesNetwork_24__reduce__(CYT __pyx_t_1 = 0; goto __pyx_L0; - /* "bayesclass/BayesNetwork.pyx":55 - * def getClassNumStates(self): - * return self.thisptr.getClassNumStates() + /* "bayesclass/BayesNetwork.pyx":58 + * def show(self): + * return self.thisptr.show() * def __reduce__(self): # <<<<<<<<<<<<<< * return (BayesNetwork, ()) * @@ -3258,7 +3322,7 @@ static PyObject *__pyx_pf_10bayesclass_8BayesNet_12BayesNetwork_24__reduce__(CYT return __pyx_r; } -/* "bayesclass/BayesNetwork.pyx":65 +/* "bayesclass/BayesNetwork.pyx":68 * cdef class CMetrics: * cdef Metrics *thisptr * def __cinit__(self, X, y, features, className, classStates): # <<<<<<<<<<<<<< @@ -3309,29 +3373,29 @@ static int __pyx_pw_10bayesclass_8BayesNet_8CMetrics_1__cinit__(PyObject *__pyx_ case 1: if (likely((values[1] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_y)) != 0)) kw_args--; else { - __Pyx_RaiseArgtupleInvalid("__cinit__", 1, 5, 5, 1); __PYX_ERR(0, 65, __pyx_L3_error) + __Pyx_RaiseArgtupleInvalid("__cinit__", 1, 5, 5, 1); __PYX_ERR(0, 68, __pyx_L3_error) } CYTHON_FALLTHROUGH; case 2: if (likely((values[2] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_features)) != 0)) kw_args--; else { - __Pyx_RaiseArgtupleInvalid("__cinit__", 1, 5, 5, 2); __PYX_ERR(0, 65, __pyx_L3_error) + __Pyx_RaiseArgtupleInvalid("__cinit__", 1, 5, 5, 2); __PYX_ERR(0, 68, __pyx_L3_error) } CYTHON_FALLTHROUGH; case 3: if (likely((values[3] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_className)) != 0)) kw_args--; else { - __Pyx_RaiseArgtupleInvalid("__cinit__", 1, 5, 5, 3); __PYX_ERR(0, 65, __pyx_L3_error) + __Pyx_RaiseArgtupleInvalid("__cinit__", 1, 5, 5, 3); __PYX_ERR(0, 68, __pyx_L3_error) } CYTHON_FALLTHROUGH; case 4: if (likely((values[4] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_classStates)) != 0)) kw_args--; else { - __Pyx_RaiseArgtupleInvalid("__cinit__", 1, 5, 5, 4); __PYX_ERR(0, 65, __pyx_L3_error) + __Pyx_RaiseArgtupleInvalid("__cinit__", 1, 5, 5, 4); __PYX_ERR(0, 68, __pyx_L3_error) } } if (unlikely(kw_args > 0)) { - if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "__cinit__") < 0)) __PYX_ERR(0, 65, __pyx_L3_error) + if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "__cinit__") < 0)) __PYX_ERR(0, 68, __pyx_L3_error) } } else if (PyTuple_GET_SIZE(__pyx_args) != 5) { goto __pyx_L5_argtuple_error; @@ -3350,7 +3414,7 @@ static int __pyx_pw_10bayesclass_8BayesNet_8CMetrics_1__cinit__(PyObject *__pyx_ } goto __pyx_L4_argument_unpacking_done; __pyx_L5_argtuple_error:; - __Pyx_RaiseArgtupleInvalid("__cinit__", 1, 5, 5, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 65, __pyx_L3_error) + __Pyx_RaiseArgtupleInvalid("__cinit__", 1, 5, 5, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 68, __pyx_L3_error) __pyx_L3_error:; __Pyx_AddTraceback("bayesclass.BayesNet.CMetrics.__cinit__", __pyx_clineno, __pyx_lineno, __pyx_filename); __Pyx_RefNannyFinishContext(); @@ -3388,7 +3452,7 @@ static int __pyx_pf_10bayesclass_8BayesNet_8CMetrics___cinit__(struct __pyx_obj_ int __pyx_clineno = 0; __Pyx_RefNannySetupContext("__cinit__", 0); - /* "bayesclass/BayesNetwork.pyx":66 + /* "bayesclass/BayesNetwork.pyx":69 * cdef Metrics *thisptr * def __cinit__(self, X, y, features, className, classStates): * X_ = [X[:, i] for i in range(X.shape[1])] # <<<<<<<<<<<<<< @@ -3396,23 +3460,23 @@ static int __pyx_pf_10bayesclass_8BayesNet_8CMetrics___cinit__(struct __pyx_obj_ * self.thisptr = new Metrics(X_, y, features_bytes, className.encode(), classStates) */ { /* enter inner scope */ - __pyx_t_1 = PyList_New(0); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 66, __pyx_L5_error) + __pyx_t_1 = PyList_New(0); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 69, __pyx_L5_error) __Pyx_GOTREF(__pyx_t_1); - __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_v_X, __pyx_n_s_shape); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 66, __pyx_L5_error) + __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_v_X, __pyx_n_s_shape); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 69, __pyx_L5_error) __Pyx_GOTREF(__pyx_t_2); - __pyx_t_3 = __Pyx_GetItemInt(__pyx_t_2, 1, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 66, __pyx_L5_error) + __pyx_t_3 = __Pyx_GetItemInt(__pyx_t_2, 1, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 69, __pyx_L5_error) __Pyx_GOTREF(__pyx_t_3); __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __pyx_t_2 = __Pyx_PyObject_CallOneArg(__pyx_builtin_range, __pyx_t_3); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 66, __pyx_L5_error) + __pyx_t_2 = __Pyx_PyObject_CallOneArg(__pyx_builtin_range, __pyx_t_3); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 69, __pyx_L5_error) __Pyx_GOTREF(__pyx_t_2); __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; if (likely(PyList_CheckExact(__pyx_t_2)) || PyTuple_CheckExact(__pyx_t_2)) { __pyx_t_3 = __pyx_t_2; __Pyx_INCREF(__pyx_t_3); __pyx_t_4 = 0; __pyx_t_5 = NULL; } else { - __pyx_t_4 = -1; __pyx_t_3 = PyObject_GetIter(__pyx_t_2); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 66, __pyx_L5_error) + __pyx_t_4 = -1; __pyx_t_3 = PyObject_GetIter(__pyx_t_2); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 69, __pyx_L5_error) __Pyx_GOTREF(__pyx_t_3); - __pyx_t_5 = Py_TYPE(__pyx_t_3)->tp_iternext; if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 66, __pyx_L5_error) + __pyx_t_5 = Py_TYPE(__pyx_t_3)->tp_iternext; if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 69, __pyx_L5_error) } __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; for (;;) { @@ -3420,17 +3484,17 @@ static int __pyx_pf_10bayesclass_8BayesNet_8CMetrics___cinit__(struct __pyx_obj_ if (likely(PyList_CheckExact(__pyx_t_3))) { if (__pyx_t_4 >= PyList_GET_SIZE(__pyx_t_3)) break; #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS - __pyx_t_2 = PyList_GET_ITEM(__pyx_t_3, __pyx_t_4); __Pyx_INCREF(__pyx_t_2); __pyx_t_4++; if (unlikely(0 < 0)) __PYX_ERR(0, 66, __pyx_L5_error) + __pyx_t_2 = PyList_GET_ITEM(__pyx_t_3, __pyx_t_4); __Pyx_INCREF(__pyx_t_2); __pyx_t_4++; if (unlikely(0 < 0)) __PYX_ERR(0, 69, __pyx_L5_error) #else - __pyx_t_2 = PySequence_ITEM(__pyx_t_3, __pyx_t_4); __pyx_t_4++; if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 66, __pyx_L5_error) + __pyx_t_2 = PySequence_ITEM(__pyx_t_3, __pyx_t_4); __pyx_t_4++; if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 69, __pyx_L5_error) __Pyx_GOTREF(__pyx_t_2); #endif } else { if (__pyx_t_4 >= PyTuple_GET_SIZE(__pyx_t_3)) break; #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS - __pyx_t_2 = PyTuple_GET_ITEM(__pyx_t_3, __pyx_t_4); __Pyx_INCREF(__pyx_t_2); __pyx_t_4++; if (unlikely(0 < 0)) __PYX_ERR(0, 66, __pyx_L5_error) + __pyx_t_2 = PyTuple_GET_ITEM(__pyx_t_3, __pyx_t_4); __Pyx_INCREF(__pyx_t_2); __pyx_t_4++; if (unlikely(0 < 0)) __PYX_ERR(0, 69, __pyx_L5_error) #else - __pyx_t_2 = PySequence_ITEM(__pyx_t_3, __pyx_t_4); __pyx_t_4++; if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 66, __pyx_L5_error) + __pyx_t_2 = PySequence_ITEM(__pyx_t_3, __pyx_t_4); __pyx_t_4++; if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 69, __pyx_L5_error) __Pyx_GOTREF(__pyx_t_2); #endif } @@ -3440,7 +3504,7 @@ static int __pyx_pf_10bayesclass_8BayesNet_8CMetrics___cinit__(struct __pyx_obj_ PyObject* exc_type = PyErr_Occurred(); if (exc_type) { if (likely(__Pyx_PyErr_GivenExceptionMatches(exc_type, PyExc_StopIteration))) PyErr_Clear(); - else __PYX_ERR(0, 66, __pyx_L5_error) + else __PYX_ERR(0, 69, __pyx_L5_error) } break; } @@ -3448,7 +3512,7 @@ static int __pyx_pf_10bayesclass_8BayesNet_8CMetrics___cinit__(struct __pyx_obj_ } __Pyx_XDECREF_SET(__pyx_8genexpr6__pyx_v_i, __pyx_t_2); __pyx_t_2 = 0; - __pyx_t_2 = PyTuple_New(2); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 66, __pyx_L5_error) + __pyx_t_2 = PyTuple_New(2); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 69, __pyx_L5_error) __Pyx_GOTREF(__pyx_t_2); __Pyx_INCREF(__pyx_slice_); __Pyx_GIVEREF(__pyx_slice_); @@ -3456,10 +3520,10 @@ static int __pyx_pf_10bayesclass_8BayesNet_8CMetrics___cinit__(struct __pyx_obj_ __Pyx_INCREF(__pyx_8genexpr6__pyx_v_i); __Pyx_GIVEREF(__pyx_8genexpr6__pyx_v_i); PyTuple_SET_ITEM(__pyx_t_2, 1, __pyx_8genexpr6__pyx_v_i); - __pyx_t_6 = __Pyx_PyObject_GetItem(__pyx_v_X, __pyx_t_2); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 66, __pyx_L5_error) + __pyx_t_6 = __Pyx_PyObject_GetItem(__pyx_v_X, __pyx_t_2); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 69, __pyx_L5_error) __Pyx_GOTREF(__pyx_t_6); __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - if (unlikely(__Pyx_ListComp_Append(__pyx_t_1, (PyObject*)__pyx_t_6))) __PYX_ERR(0, 66, __pyx_L5_error) + if (unlikely(__Pyx_ListComp_Append(__pyx_t_1, (PyObject*)__pyx_t_6))) __PYX_ERR(0, 69, __pyx_L5_error) __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; } __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; @@ -3473,7 +3537,7 @@ static int __pyx_pf_10bayesclass_8BayesNet_8CMetrics___cinit__(struct __pyx_obj_ __pyx_v_X_ = ((PyObject*)__pyx_t_1); __pyx_t_1 = 0; - /* "bayesclass/BayesNetwork.pyx":67 + /* "bayesclass/BayesNetwork.pyx":70 * def __cinit__(self, X, y, features, className, classStates): * X_ = [X[:, i] for i in range(X.shape[1])] * features_bytes = [x.encode() for x in features] # <<<<<<<<<<<<<< @@ -3481,32 +3545,32 @@ static int __pyx_pf_10bayesclass_8BayesNet_8CMetrics___cinit__(struct __pyx_obj_ * def __dealloc__(self): */ { /* enter inner scope */ - __pyx_t_1 = PyList_New(0); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 67, __pyx_L11_error) + __pyx_t_1 = PyList_New(0); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 70, __pyx_L11_error) __Pyx_GOTREF(__pyx_t_1); if (likely(PyList_CheckExact(__pyx_v_features)) || PyTuple_CheckExact(__pyx_v_features)) { __pyx_t_3 = __pyx_v_features; __Pyx_INCREF(__pyx_t_3); __pyx_t_4 = 0; __pyx_t_5 = NULL; } else { - __pyx_t_4 = -1; __pyx_t_3 = PyObject_GetIter(__pyx_v_features); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 67, __pyx_L11_error) + __pyx_t_4 = -1; __pyx_t_3 = PyObject_GetIter(__pyx_v_features); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 70, __pyx_L11_error) __Pyx_GOTREF(__pyx_t_3); - __pyx_t_5 = Py_TYPE(__pyx_t_3)->tp_iternext; if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 67, __pyx_L11_error) + __pyx_t_5 = Py_TYPE(__pyx_t_3)->tp_iternext; if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 70, __pyx_L11_error) } for (;;) { if (likely(!__pyx_t_5)) { if (likely(PyList_CheckExact(__pyx_t_3))) { if (__pyx_t_4 >= PyList_GET_SIZE(__pyx_t_3)) break; #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS - __pyx_t_6 = PyList_GET_ITEM(__pyx_t_3, __pyx_t_4); __Pyx_INCREF(__pyx_t_6); __pyx_t_4++; if (unlikely(0 < 0)) __PYX_ERR(0, 67, __pyx_L11_error) + __pyx_t_6 = PyList_GET_ITEM(__pyx_t_3, __pyx_t_4); __Pyx_INCREF(__pyx_t_6); __pyx_t_4++; if (unlikely(0 < 0)) __PYX_ERR(0, 70, __pyx_L11_error) #else - __pyx_t_6 = PySequence_ITEM(__pyx_t_3, __pyx_t_4); __pyx_t_4++; if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 67, __pyx_L11_error) + __pyx_t_6 = PySequence_ITEM(__pyx_t_3, __pyx_t_4); __pyx_t_4++; if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 70, __pyx_L11_error) __Pyx_GOTREF(__pyx_t_6); #endif } else { if (__pyx_t_4 >= PyTuple_GET_SIZE(__pyx_t_3)) break; #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS - __pyx_t_6 = PyTuple_GET_ITEM(__pyx_t_3, __pyx_t_4); __Pyx_INCREF(__pyx_t_6); __pyx_t_4++; if (unlikely(0 < 0)) __PYX_ERR(0, 67, __pyx_L11_error) + __pyx_t_6 = PyTuple_GET_ITEM(__pyx_t_3, __pyx_t_4); __Pyx_INCREF(__pyx_t_6); __pyx_t_4++; if (unlikely(0 < 0)) __PYX_ERR(0, 70, __pyx_L11_error) #else - __pyx_t_6 = PySequence_ITEM(__pyx_t_3, __pyx_t_4); __pyx_t_4++; if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 67, __pyx_L11_error) + __pyx_t_6 = PySequence_ITEM(__pyx_t_3, __pyx_t_4); __pyx_t_4++; if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 70, __pyx_L11_error) __Pyx_GOTREF(__pyx_t_6); #endif } @@ -3516,7 +3580,7 @@ static int __pyx_pf_10bayesclass_8BayesNet_8CMetrics___cinit__(struct __pyx_obj_ PyObject* exc_type = PyErr_Occurred(); if (exc_type) { if (likely(__Pyx_PyErr_GivenExceptionMatches(exc_type, PyExc_StopIteration))) PyErr_Clear(); - else __PYX_ERR(0, 67, __pyx_L11_error) + else __PYX_ERR(0, 70, __pyx_L11_error) } break; } @@ -3524,7 +3588,7 @@ static int __pyx_pf_10bayesclass_8BayesNet_8CMetrics___cinit__(struct __pyx_obj_ } __Pyx_XDECREF_SET(__pyx_8genexpr7__pyx_v_x, __pyx_t_6); __pyx_t_6 = 0; - __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_8genexpr7__pyx_v_x, __pyx_n_s_encode); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 67, __pyx_L11_error) + __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_8genexpr7__pyx_v_x, __pyx_n_s_encode); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 70, __pyx_L11_error) __Pyx_GOTREF(__pyx_t_2); __pyx_t_7 = NULL; if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_2))) { @@ -3538,10 +3602,10 @@ static int __pyx_pf_10bayesclass_8BayesNet_8CMetrics___cinit__(struct __pyx_obj_ } __pyx_t_6 = (__pyx_t_7) ? __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_t_7) : __Pyx_PyObject_CallNoArg(__pyx_t_2); __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0; - if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 67, __pyx_L11_error) + if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 70, __pyx_L11_error) __Pyx_GOTREF(__pyx_t_6); __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - if (unlikely(__Pyx_ListComp_Append(__pyx_t_1, (PyObject*)__pyx_t_6))) __PYX_ERR(0, 67, __pyx_L11_error) + if (unlikely(__Pyx_ListComp_Append(__pyx_t_1, (PyObject*)__pyx_t_6))) __PYX_ERR(0, 70, __pyx_L11_error) __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; } __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; @@ -3555,17 +3619,17 @@ static int __pyx_pf_10bayesclass_8BayesNet_8CMetrics___cinit__(struct __pyx_obj_ __pyx_v_features_bytes = ((PyObject*)__pyx_t_1); __pyx_t_1 = 0; - /* "bayesclass/BayesNetwork.pyx":68 + /* "bayesclass/BayesNetwork.pyx":71 * X_ = [X[:, i] for i in range(X.shape[1])] * features_bytes = [x.encode() for x in features] * self.thisptr = new Metrics(X_, y, features_bytes, className.encode(), classStates) # <<<<<<<<<<<<<< * def __dealloc__(self): * del self.thisptr */ - __pyx_t_8 = __pyx_convert_vector_from_py_std_3a__3a_vector_3c_int_3e___(__pyx_v_X_); if (unlikely(PyErr_Occurred())) __PYX_ERR(0, 68, __pyx_L1_error) - __pyx_t_9 = __pyx_convert_vector_from_py_int(__pyx_v_y); if (unlikely(PyErr_Occurred())) __PYX_ERR(0, 68, __pyx_L1_error) - __pyx_t_10 = __pyx_convert_vector_from_py_std_3a__3a_string(__pyx_v_features_bytes); if (unlikely(PyErr_Occurred())) __PYX_ERR(0, 68, __pyx_L1_error) - __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_v_className, __pyx_n_s_encode); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 68, __pyx_L1_error) + __pyx_t_8 = __pyx_convert_vector_from_py_std_3a__3a_vector_3c_int_3e___(__pyx_v_X_); if (unlikely(PyErr_Occurred())) __PYX_ERR(0, 71, __pyx_L1_error) + __pyx_t_9 = __pyx_convert_vector_from_py_int(__pyx_v_y); if (unlikely(PyErr_Occurred())) __PYX_ERR(0, 71, __pyx_L1_error) + __pyx_t_10 = __pyx_convert_vector_from_py_std_3a__3a_string(__pyx_v_features_bytes); if (unlikely(PyErr_Occurred())) __PYX_ERR(0, 71, __pyx_L1_error) + __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_v_className, __pyx_n_s_encode); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 71, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __pyx_t_6 = NULL; if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_3))) { @@ -3579,21 +3643,21 @@ static int __pyx_pf_10bayesclass_8BayesNet_8CMetrics___cinit__(struct __pyx_obj_ } __pyx_t_1 = (__pyx_t_6) ? __Pyx_PyObject_CallOneArg(__pyx_t_3, __pyx_t_6) : __Pyx_PyObject_CallNoArg(__pyx_t_3); __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0; - if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 68, __pyx_L1_error) + if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 71, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __pyx_t_11 = __pyx_convert_string_from_py_std__in_string(__pyx_t_1); if (unlikely(PyErr_Occurred())) __PYX_ERR(0, 68, __pyx_L1_error) + __pyx_t_11 = __pyx_convert_string_from_py_std__in_string(__pyx_t_1); if (unlikely(PyErr_Occurred())) __PYX_ERR(0, 71, __pyx_L1_error) __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __pyx_t_12 = __Pyx_PyInt_As_int(__pyx_v_classStates); if (unlikely((__pyx_t_12 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 68, __pyx_L1_error) + __pyx_t_12 = __Pyx_PyInt_As_int(__pyx_v_classStates); if (unlikely((__pyx_t_12 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 71, __pyx_L1_error) try { __pyx_t_13 = new bayesnet::Metrics(__pyx_t_8, __pyx_t_9, __pyx_t_10, __pyx_t_11, __pyx_t_12); } catch(...) { __Pyx_CppExn2PyErr(); - __PYX_ERR(0, 68, __pyx_L1_error) + __PYX_ERR(0, 71, __pyx_L1_error) } __pyx_v_self->thisptr = __pyx_t_13; - /* "bayesclass/BayesNetwork.pyx":65 + /* "bayesclass/BayesNetwork.pyx":68 * cdef class CMetrics: * cdef Metrics *thisptr * def __cinit__(self, X, y, features, className, classStates): # <<<<<<<<<<<<<< @@ -3621,7 +3685,7 @@ static int __pyx_pf_10bayesclass_8BayesNet_8CMetrics___cinit__(struct __pyx_obj_ return __pyx_r; } -/* "bayesclass/BayesNetwork.pyx":69 +/* "bayesclass/BayesNetwork.pyx":72 * features_bytes = [x.encode() for x in features] * self.thisptr = new Metrics(X_, y, features_bytes, className.encode(), classStates) * def __dealloc__(self): # <<<<<<<<<<<<<< @@ -3644,7 +3708,7 @@ static void __pyx_pf_10bayesclass_8BayesNet_8CMetrics_2__dealloc__(struct __pyx_ __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("__dealloc__", 0); - /* "bayesclass/BayesNetwork.pyx":70 + /* "bayesclass/BayesNetwork.pyx":73 * self.thisptr = new Metrics(X_, y, features_bytes, className.encode(), classStates) * def __dealloc__(self): * del self.thisptr # <<<<<<<<<<<<<< @@ -3653,7 +3717,7 @@ static void __pyx_pf_10bayesclass_8BayesNet_8CMetrics_2__dealloc__(struct __pyx_ */ delete __pyx_v_self->thisptr; - /* "bayesclass/BayesNetwork.pyx":69 + /* "bayesclass/BayesNetwork.pyx":72 * features_bytes = [x.encode() for x in features] * self.thisptr = new Metrics(X_, y, features_bytes, className.encode(), classStates) * def __dealloc__(self): # <<<<<<<<<<<<<< @@ -3665,7 +3729,7 @@ static void __pyx_pf_10bayesclass_8BayesNet_8CMetrics_2__dealloc__(struct __pyx_ __Pyx_RefNannyFinishContext(); } -/* "bayesclass/BayesNetwork.pyx":71 +/* "bayesclass/BayesNetwork.pyx":74 * def __dealloc__(self): * del self.thisptr * def conditionalEdgeWeights(self, n_vars): # <<<<<<<<<<<<<< @@ -3701,7 +3765,7 @@ static PyObject *__pyx_pf_10bayesclass_8BayesNet_8CMetrics_4conditionalEdgeWeigh int __pyx_clineno = 0; __Pyx_RefNannySetupContext("conditionalEdgeWeights", 0); - /* "bayesclass/BayesNetwork.pyx":72 + /* "bayesclass/BayesNetwork.pyx":75 * del self.thisptr * def conditionalEdgeWeights(self, n_vars): * return np.reshape(self.thisptr.conditionalEdgeWeights(), (n_vars, n_vars)) # <<<<<<<<<<<<<< @@ -3709,14 +3773,14 @@ static PyObject *__pyx_pf_10bayesclass_8BayesNet_8CMetrics_4conditionalEdgeWeigh * return (CMetrics, ()) */ __Pyx_XDECREF(__pyx_r); - __Pyx_GetModuleGlobalName(__pyx_t_2, __pyx_n_s_np); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 72, __pyx_L1_error) + __Pyx_GetModuleGlobalName(__pyx_t_2, __pyx_n_s_np); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 75, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); - __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_reshape); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 72, __pyx_L1_error) + __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_reshape); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 75, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __pyx_t_2 = __pyx_convert_vector_to_py_float(__pyx_v_self->thisptr->conditionalEdgeWeights()); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 72, __pyx_L1_error) + __pyx_t_2 = __pyx_convert_vector_to_py_float(__pyx_v_self->thisptr->conditionalEdgeWeights()); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 75, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); - __pyx_t_4 = PyTuple_New(2); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 72, __pyx_L1_error) + __pyx_t_4 = PyTuple_New(2); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 75, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); __Pyx_INCREF(__pyx_v_n_vars); __Pyx_GIVEREF(__pyx_v_n_vars); @@ -3739,7 +3803,7 @@ static PyObject *__pyx_pf_10bayesclass_8BayesNet_8CMetrics_4conditionalEdgeWeigh #if CYTHON_FAST_PYCALL if (PyFunction_Check(__pyx_t_3)) { PyObject *__pyx_temp[3] = {__pyx_t_5, __pyx_t_2, __pyx_t_4}; - __pyx_t_1 = __Pyx_PyFunction_FastCall(__pyx_t_3, __pyx_temp+1-__pyx_t_6, 2+__pyx_t_6); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 72, __pyx_L1_error) + __pyx_t_1 = __Pyx_PyFunction_FastCall(__pyx_t_3, __pyx_temp+1-__pyx_t_6, 2+__pyx_t_6); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 75, __pyx_L1_error) __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0; __Pyx_GOTREF(__pyx_t_1); __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; @@ -3749,7 +3813,7 @@ static PyObject *__pyx_pf_10bayesclass_8BayesNet_8CMetrics_4conditionalEdgeWeigh #if CYTHON_FAST_PYCCALL if (__Pyx_PyFastCFunction_Check(__pyx_t_3)) { PyObject *__pyx_temp[3] = {__pyx_t_5, __pyx_t_2, __pyx_t_4}; - __pyx_t_1 = __Pyx_PyCFunction_FastCall(__pyx_t_3, __pyx_temp+1-__pyx_t_6, 2+__pyx_t_6); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 72, __pyx_L1_error) + __pyx_t_1 = __Pyx_PyCFunction_FastCall(__pyx_t_3, __pyx_temp+1-__pyx_t_6, 2+__pyx_t_6); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 75, __pyx_L1_error) __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0; __Pyx_GOTREF(__pyx_t_1); __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; @@ -3757,7 +3821,7 @@ static PyObject *__pyx_pf_10bayesclass_8BayesNet_8CMetrics_4conditionalEdgeWeigh } else #endif { - __pyx_t_7 = PyTuple_New(2+__pyx_t_6); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 72, __pyx_L1_error) + __pyx_t_7 = PyTuple_New(2+__pyx_t_6); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 75, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_7); if (__pyx_t_5) { __Pyx_GIVEREF(__pyx_t_5); PyTuple_SET_ITEM(__pyx_t_7, 0, __pyx_t_5); __pyx_t_5 = NULL; @@ -3768,7 +3832,7 @@ static PyObject *__pyx_pf_10bayesclass_8BayesNet_8CMetrics_4conditionalEdgeWeigh PyTuple_SET_ITEM(__pyx_t_7, 1+__pyx_t_6, __pyx_t_4); __pyx_t_2 = 0; __pyx_t_4 = 0; - __pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_3, __pyx_t_7, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 72, __pyx_L1_error) + __pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_3, __pyx_t_7, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 75, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; } @@ -3777,7 +3841,7 @@ static PyObject *__pyx_pf_10bayesclass_8BayesNet_8CMetrics_4conditionalEdgeWeigh __pyx_t_1 = 0; goto __pyx_L0; - /* "bayesclass/BayesNetwork.pyx":71 + /* "bayesclass/BayesNetwork.pyx":74 * def __dealloc__(self): * del self.thisptr * def conditionalEdgeWeights(self, n_vars): # <<<<<<<<<<<<<< @@ -3801,7 +3865,7 @@ static PyObject *__pyx_pf_10bayesclass_8BayesNet_8CMetrics_4conditionalEdgeWeigh return __pyx_r; } -/* "bayesclass/BayesNetwork.pyx":73 +/* "bayesclass/BayesNetwork.pyx":76 * def conditionalEdgeWeights(self, n_vars): * return np.reshape(self.thisptr.conditionalEdgeWeights(), (n_vars, n_vars)) * def __reduce__(self): # <<<<<<<<<<<<<< @@ -3831,14 +3895,14 @@ static PyObject *__pyx_pf_10bayesclass_8BayesNet_8CMetrics_6__reduce__(CYTHON_UN int __pyx_clineno = 0; __Pyx_RefNannySetupContext("__reduce__", 0); - /* "bayesclass/BayesNetwork.pyx":74 + /* "bayesclass/BayesNetwork.pyx":77 * return np.reshape(self.thisptr.conditionalEdgeWeights(), (n_vars, n_vars)) * def __reduce__(self): * return (CMetrics, ()) # <<<<<<<<<<<<<< * */ __Pyx_XDECREF(__pyx_r); - __pyx_t_1 = PyTuple_New(2); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 74, __pyx_L1_error) + __pyx_t_1 = PyTuple_New(2); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 77, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_INCREF(((PyObject *)__pyx_ptype_10bayesclass_8BayesNet_CMetrics)); __Pyx_GIVEREF(((PyObject *)__pyx_ptype_10bayesclass_8BayesNet_CMetrics)); @@ -3850,7 +3914,7 @@ static PyObject *__pyx_pf_10bayesclass_8BayesNet_8CMetrics_6__reduce__(CYTHON_UN __pyx_t_1 = 0; goto __pyx_L0; - /* "bayesclass/BayesNetwork.pyx":73 + /* "bayesclass/BayesNetwork.pyx":76 * def conditionalEdgeWeights(self, n_vars): * return np.reshape(self.thisptr.conditionalEdgeWeights(), (n_vars, n_vars)) * def __reduce__(self): # <<<<<<<<<<<<<< @@ -4828,7 +4892,8 @@ static PyMethodDef __pyx_methods_10bayesclass_8BayesNet_BayesNetwork[] = { {"getStates", (PyCFunction)__pyx_pw_10bayesclass_8BayesNet_12BayesNetwork_19getStates, METH_NOARGS, 0}, {"getClassName", (PyCFunction)__pyx_pw_10bayesclass_8BayesNet_12BayesNetwork_21getClassName, METH_NOARGS, 0}, {"getClassNumStates", (PyCFunction)__pyx_pw_10bayesclass_8BayesNet_12BayesNetwork_23getClassNumStates, METH_NOARGS, 0}, - {"__reduce__", (PyCFunction)__pyx_pw_10bayesclass_8BayesNet_12BayesNetwork_25__reduce__, METH_NOARGS, 0}, + {"show", (PyCFunction)__pyx_pw_10bayesclass_8BayesNet_12BayesNetwork_25show, METH_NOARGS, 0}, + {"__reduce__", (PyCFunction)__pyx_pw_10bayesclass_8BayesNet_12BayesNetwork_27__reduce__, METH_NOARGS, 0}, {0, 0, 0, 0} }; @@ -5087,7 +5152,7 @@ static __Pyx_StringTabEntry __pyx_string_tab[] = { {0, 0, 0, 0, 0, 0, 0} }; static CYTHON_SMALL_CODE int __Pyx_InitCachedBuiltins(void) { - __pyx_builtin_range = __Pyx_GetBuiltinName(__pyx_n_s_range); if (!__pyx_builtin_range) __PYX_ERR(0, 29, __pyx_L1_error) + __pyx_builtin_range = __Pyx_GetBuiltinName(__pyx_n_s_range); if (!__pyx_builtin_range) __PYX_ERR(0, 30, __pyx_L1_error) return 0; __pyx_L1_error:; return -1; @@ -5097,14 +5162,14 @@ static CYTHON_SMALL_CODE int __Pyx_InitCachedConstants(void) { __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("__Pyx_InitCachedConstants", 0); - /* "bayesclass/BayesNetwork.pyx":29 + /* "bayesclass/BayesNetwork.pyx":30 * del self.thisptr * def fit(self, X, y, features, className): * X_ = [X[:, i] for i in range(X.shape[1])] # <<<<<<<<<<<<<< * features_bytes = [x.encode() for x in features] * self.thisptr.fit(X_, y, features_bytes, className.encode()) */ - __pyx_slice_ = PySlice_New(Py_None, Py_None, Py_None); if (unlikely(!__pyx_slice_)) __PYX_ERR(0, 29, __pyx_L1_error) + __pyx_slice_ = PySlice_New(Py_None, Py_None, Py_None); if (unlikely(!__pyx_slice_)) __PYX_ERR(0, 30, __pyx_L1_error) __Pyx_GOTREF(__pyx_slice_); __Pyx_GIVEREF(__pyx_slice_); __Pyx_RefNannyFinishContext(); @@ -5162,23 +5227,23 @@ static int __Pyx_modinit_type_init_code(void) { int __pyx_clineno = 0; __Pyx_RefNannySetupContext("__Pyx_modinit_type_init_code", 0); /*--- Type init code ---*/ - if (PyType_Ready(&__pyx_type_10bayesclass_8BayesNet_BayesNetwork) < 0) __PYX_ERR(0, 22, __pyx_L1_error) + if (PyType_Ready(&__pyx_type_10bayesclass_8BayesNet_BayesNetwork) < 0) __PYX_ERR(0, 23, __pyx_L1_error) #if PY_VERSION_HEX < 0x030800B1 __pyx_type_10bayesclass_8BayesNet_BayesNetwork.tp_print = 0; #endif if ((CYTHON_USE_TYPE_SLOTS && CYTHON_USE_PYTYPE_LOOKUP) && likely(!__pyx_type_10bayesclass_8BayesNet_BayesNetwork.tp_dictoffset && __pyx_type_10bayesclass_8BayesNet_BayesNetwork.tp_getattro == PyObject_GenericGetAttr)) { __pyx_type_10bayesclass_8BayesNet_BayesNetwork.tp_getattro = __Pyx_PyObject_GenericGetAttr; } - if (PyObject_SetAttr(__pyx_m, __pyx_n_s_BayesNetwork, (PyObject *)&__pyx_type_10bayesclass_8BayesNet_BayesNetwork) < 0) __PYX_ERR(0, 22, __pyx_L1_error) + if (PyObject_SetAttr(__pyx_m, __pyx_n_s_BayesNetwork, (PyObject *)&__pyx_type_10bayesclass_8BayesNet_BayesNetwork) < 0) __PYX_ERR(0, 23, __pyx_L1_error) __pyx_ptype_10bayesclass_8BayesNet_BayesNetwork = &__pyx_type_10bayesclass_8BayesNet_BayesNetwork; - if (PyType_Ready(&__pyx_type_10bayesclass_8BayesNet_CMetrics) < 0) __PYX_ERR(0, 63, __pyx_L1_error) + if (PyType_Ready(&__pyx_type_10bayesclass_8BayesNet_CMetrics) < 0) __PYX_ERR(0, 66, __pyx_L1_error) #if PY_VERSION_HEX < 0x030800B1 __pyx_type_10bayesclass_8BayesNet_CMetrics.tp_print = 0; #endif if ((CYTHON_USE_TYPE_SLOTS && CYTHON_USE_PYTYPE_LOOKUP) && likely(!__pyx_type_10bayesclass_8BayesNet_CMetrics.tp_dictoffset && __pyx_type_10bayesclass_8BayesNet_CMetrics.tp_getattro == PyObject_GenericGetAttr)) { __pyx_type_10bayesclass_8BayesNet_CMetrics.tp_getattro = __Pyx_PyObject_GenericGetAttr; } - if (PyObject_SetAttr(__pyx_m, __pyx_n_s_CMetrics, (PyObject *)&__pyx_type_10bayesclass_8BayesNet_CMetrics) < 0) __PYX_ERR(0, 63, __pyx_L1_error) + if (PyObject_SetAttr(__pyx_m, __pyx_n_s_CMetrics, (PyObject *)&__pyx_type_10bayesclass_8BayesNet_CMetrics) < 0) __PYX_ERR(0, 66, __pyx_L1_error) __pyx_ptype_10bayesclass_8BayesNet_CMetrics = &__pyx_type_10bayesclass_8BayesNet_CMetrics; __Pyx_RefNannyFinishContext(); return 0; diff --git a/bayesclass/BayesNetwork.pyx b/bayesclass/BayesNetwork.pyx index 0e19cf9..1546087 100644 --- a/bayesclass/BayesNetwork.pyx +++ b/bayesclass/BayesNetwork.pyx @@ -18,6 +18,7 @@ cdef extern from "Network.h" namespace "bayesnet": int getStates() string getClassName() string version() + void show() cdef class BayesNetwork: cdef Network *thisptr @@ -52,6 +53,8 @@ cdef class BayesNetwork: return self.thisptr.getClassName().decode() def getClassNumStates(self): return self.thisptr.getClassNumStates() + def show(self): + return self.thisptr.show() def __reduce__(self): return (BayesNetwork, ()) diff --git a/bayesclass/KDB.cc b/bayesclass/KDB.cc new file mode 100644 index 0000000..7cf174f --- /dev/null +++ b/bayesclass/KDB.cc @@ -0,0 +1,110 @@ +#include "KDB.h" +#include "Metrics.hpp" + +namespace bayesnet { + using namespace std; + using namespace torch; + vector argsort(vector& nums) + { + int n = nums.size(); + vector indices(n); + iota(indices.begin(), indices.end(), 0); + sort(indices.begin(), indices.end(), [&nums](int i, int j) {return nums[i] > nums[j];}); + return indices; + } + KDB::KDB(int k, float theta) : BaseClassifier(Network()), k(k), theta(theta) {} + void KDB::train() + { + /* + 1. For each feature Xi, compute mutual information, I(X;C), + where C is the class. + 2. Compute class conditional mutual information I(Xi;XjIC), f or each + pair of features Xi and Xj, where i#j. + 3. Let the used variable list, S, be empty. + 4. Let the DAG network being constructed, BN, begin with a single + class node, C. + 5. Repeat until S includes all domain features + 5.1. Select feature Xmax which is not in S and has the largest value + I(Xmax;C). + 5.2. Add a node to BN representing Xmax. + 5.3. Add an arc from C to Xmax in BN. + 5.4. Add m = min(lSl,/c) arcs from m distinct features Xj in S with + the highest value for I(Xmax;X,jC). + 5.5. Add Xmax to S. + Compute the conditional probabilility infered by the structure of BN by + using counts from DB, and output BN. + */ + // 1. For each feature Xi, compute mutual information, I(X;C), + // where C is the class. + cout << "Computing mutual information between features and class" << endl; + auto n_classes = states[className].size(); + auto metrics = Metrics(dataset, features, className, n_classes); + vector mi; + for (auto i = 0; i < features.size(); i++) { + Tensor firstFeature = X.index({ "...", i }); + mi.push_back(metrics.mutualInformation(firstFeature, y)); + cout << "Mutual information between " << features[i] << " and " << className << " is " << mi[i] << endl; + } + // 2. Compute class conditional mutual information I(Xi;XjIC), f or each + auto conditionalEdgeWeights = metrics.conditionalEdge(); + cout << "Conditional edge weights" << endl; + cout << conditionalEdgeWeights << endl; + // 3. Let the used variable list, S, be empty. + vector S; + // 4. Let the DAG network being constructed, BN, begin with a single + // class node, C. + model.addNode(className, states[className].size()); + cout << "Adding node " << className << " to the network" << endl; + // 5. Repeat until S includes all domain features + // 5.1. Select feature Xmax which is not in S and has the largest value + // I(Xmax;C). + auto order = argsort(mi); + for (auto idx : order) { + cout << idx << " " << mi[idx] << endl; + // 5.2. Add a node to BN representing Xmax. + model.addNode(features[idx], states[features[idx]].size()); + // 5.3. Add an arc from C to Xmax in BN. + model.addEdge(className, features[idx]); + // 5.4. Add m = min(lSl,/c) arcs from m distinct features Xj in S with + // the highest value for I(Xmax;X,jC). + add_m_edges(idx, S, conditionalEdgeWeights); + // 5.5. Add Xmax to S. + S.push_back(idx); + } + } + void KDB::add_m_edges(int idx, vector& S, Tensor& weights) + { + auto n_edges = min(k, static_cast(S.size())); + auto cond_w = clone(weights); + cout << "Conditional edge weights cloned for idx " << idx << endl; + cout << cond_w << endl; + bool exit_cond = k == 0; + int num = 0; + while (!exit_cond) { + auto max_minfo = argmax(cond_w.index({ idx, "..." })).item(); + auto belongs = find(S.begin(), S.end(), max_minfo) != S.end(); + if (belongs && cond_w.index({ idx, max_minfo }).item() > theta) { + try { + model.addEdge(features[max_minfo], features[idx]); + num++; + } + catch (const invalid_argument& e) { + // Loops are not allowed + } + } + cond_w.index_put_({ idx, max_minfo }, -1); + cout << "Conditional edge weights cloned for idx " << idx << " After -1" << endl; + cout << cond_w << endl; + cout << "cond_w.index({ idx, '...'})" << endl; + cout << cond_w.index({ idx, "..." }) << endl; + auto candidates_mask = cond_w.index({ idx, "..." }).gt(theta); + auto candidates = candidates_mask.nonzero(); + cout << "Candidates mask" << endl; + cout << candidates_mask << endl; + cout << "Candidates: " << endl; + cout << candidates << endl; + cout << "Candidates size: " << candidates.size(0) << endl; + exit_cond = num == n_edges || candidates.size(0) == 0; + } + } +} \ No newline at end of file diff --git a/bayesclass/KDB.h b/bayesclass/KDB.h new file mode 100644 index 0000000..64f1f7b --- /dev/null +++ b/bayesclass/KDB.h @@ -0,0 +1,18 @@ +#ifndef KDB_H +#define KDB_H +#include "BaseClassifier.h" +namespace bayesnet { + using namespace std; + using namespace torch; + class KDB : public BaseClassifier { + private: + int k; + float theta; + void add_m_edges(int idx, vector& S, Tensor& weights); + protected: + void train(); + public: + KDB(int k, float theta=0.03); + }; +} +#endif \ No newline at end of file diff --git a/bayesclass/Metrics.cc b/bayesclass/Metrics.cc index e3ac651..f8174c1 100644 --- a/bayesclass/Metrics.cc +++ b/bayesclass/Metrics.cc @@ -30,7 +30,7 @@ namespace bayesnet { } return result; } - vector Metrics::conditionalEdgeWeights() + torch::Tensor Metrics::conditionalEdge() { auto result = vector(); auto source = vector(features); @@ -65,6 +65,11 @@ namespace bayesnet { matrix[x][y] = result[i]; matrix[y][x] = result[i]; } + return matrix; + } + vector Metrics::conditionalEdgeWeights() + { + auto matrix = conditionalEdge(); std::vector v(matrix.data_ptr(), matrix.data_ptr() + matrix.numel()); return v; } @@ -89,7 +94,7 @@ namespace bayesnet { totalWeight += 1; } if (totalWeight == 0) - return 0; + throw invalid_argument("Total weight should not be zero"); double entropyValue = 0; for (int value = 0; value < featureCounts.sizes()[0]; ++value) { double p_f = featureCounts[value].item() / totalWeight; diff --git a/bayesclass/Metrics.hpp b/bayesclass/Metrics.hpp index 2587d80..f939e44 100644 --- a/bayesclass/Metrics.hpp +++ b/bayesclass/Metrics.hpp @@ -14,11 +14,12 @@ namespace bayesnet { vector> doCombinations(const vector&); double entropy(torch::Tensor&); double conditionalEntropy(torch::Tensor&, torch::Tensor&); - double mutualInformation(torch::Tensor&, torch::Tensor&); public: + double mutualInformation(torch::Tensor&, torch::Tensor&); Metrics(torch::Tensor&, vector&, string&, int); Metrics(const vector>&, const vector&, const vector&, const string&, const int); vector conditionalEdgeWeights(); + torch::Tensor conditionalEdge(); }; } #endif \ No newline at end of file diff --git a/bayesclass/Network.cc b/bayesclass/Network.cc index b1094c3..495ee4f 100644 --- a/bayesclass/Network.cc +++ b/bayesclass/Network.cc @@ -245,5 +245,16 @@ namespace bayesnet { } return result; } + void Network::show() + { + // Draw the network + for (auto node : nodes) { + cout << node.first << " -> "; + for (auto child : node.second->getChildren()) { + cout << child->getName() << ", "; + } + cout << endl; + } + } } diff --git a/bayesclass/Network.h b/bayesclass/Network.h index 42403a7..bc6402d 100644 --- a/bayesclass/Network.h +++ b/bayesclass/Network.h @@ -4,7 +4,6 @@ #include #include - namespace bayesnet { class Network { private: @@ -45,6 +44,7 @@ namespace bayesnet { torch::Tensor conditionalEdgeWeight(); vector> predict_proba(const vector>&); double score(const vector>&, const vector&); + void show(); inline string version() { return "0.1.0"; } }; } diff --git a/bayesclass/clfs.py b/bayesclass/clfs.py index b154e95..e9ec021 100644 --- a/bayesclass/clfs.py +++ b/bayesclass/clfs.py @@ -423,7 +423,7 @@ class KDB(BayesBase): self.model_.addNode(self.class_name_, self.n_classes_) # 5. Repeat until S includes all domain features # 5.1 Select feature Xmax which is not in S and has the largest value - for idx in np.argsort(mutual): + for idx in np.argsort(-mutual): # 5.2 Add a node to BN representing Xmax. feature = self.feature_names_in_[idx] self.model_.addNode(feature, num_states[feature])