Commit bcc9d326 authored by André Anjos's avatar André Anjos 💬
Browse files

Better comments on defaults and values

parent 3d9f7edf
...@@ -294,7 +294,9 @@ static int PyBobLearnLibsvmTrainer_setStopEpsilon ...@@ -294,7 +294,9 @@ static int PyBobLearnLibsvmTrainer_setStopEpsilon
PyDoc_STRVAR(s_cost_str, "cost"); PyDoc_STRVAR(s_cost_str, "cost");
PyDoc_STRVAR(s_cost_doc, PyDoc_STRVAR(s_cost_doc,
"The cost value for ``C_SVC``, ``EPSILON_SVR`` or ``NU_SVR``"); "The cost value for ``C_SVC``, ``EPSILON_SVR`` or ``NU_SVR``.\n\
This parameter is normally referred only as :math:`C` on\n\
literature. It should be a non-negative floating-point number.");
static PyObject* PyBobLearnLibsvmTrainer_getCost static PyObject* PyBobLearnLibsvmTrainer_getCost
(PyBobLearnLibsvmTrainerObject* self, void* /*closure*/) { (PyBobLearnLibsvmTrainerObject* self, void* /*closure*/) {
...@@ -307,14 +309,20 @@ static int PyBobLearnLibsvmTrainer_setCost ...@@ -307,14 +309,20 @@ static int PyBobLearnLibsvmTrainer_setCost
PyErr_SetString(PyExc_TypeError, "cannot delete attribute"); PyErr_SetString(PyExc_TypeError, "cannot delete attribute");
return -1; return -1;
} }
self->cxx->setCost(PyFloat_AsDouble(o)); double value = PyFloat_AsDouble(o);
if (PyErr_Occurred()) return -1; if (PyErr_Occurred()) return -1;
if (value < 0) {
PyErr_SetString(PyExc_ValueError, "cost (C) has to be >= 0.0");
return -1;
}
self->cxx->setCost(value);
return 0; return 0;
} }
PyDoc_STRVAR(s_nu_str, "nu"); PyDoc_STRVAR(s_nu_str, "nu");
PyDoc_STRVAR(s_nu_doc, PyDoc_STRVAR(s_nu_doc,
"The nu value for ``NU_SVC``, ``ONE_CLASS`` or ``NU_SVR``"); "The nu value for ``NU_SVC``, ``ONE_CLASS`` or ``NU_SVR``.\n\
This parameter should live in the range [0, 1].");
static PyObject* PyBobLearnLibsvmTrainer_getNu static PyObject* PyBobLearnLibsvmTrainer_getNu
(PyBobLearnLibsvmTrainerObject* self, void* /*closure*/) { (PyBobLearnLibsvmTrainerObject* self, void* /*closure*/) {
...@@ -327,8 +335,13 @@ static int PyBobLearnLibsvmTrainer_setNu ...@@ -327,8 +335,13 @@ static int PyBobLearnLibsvmTrainer_setNu
PyErr_SetString(PyExc_TypeError, "cannot delete attribute"); PyErr_SetString(PyExc_TypeError, "cannot delete attribute");
return -1; return -1;
} }
self->cxx->setNu(PyFloat_AsDouble(o)); double value = PyFloat_AsDouble(o);
if (PyErr_Occurred()) return -1; if (PyErr_Occurred()) return -1;
if (value < 0 || value > 1) {
PyErr_SetString(PyExc_ValueError, "nu has to be in range [0,1]");
return -1;
}
self->cxx->setNu(value);
return 0; return 0;
} }
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment