diff --git a/bob/learn/misc/gaussian.cpp b/bob/learn/misc/gaussian.cpp index 43a18509b77101b94d362f0a70d4f6fe329cb123..6be320fdcca916fa6541c3f10759ae5e155d0acb 100644 --- a/bob/learn/misc/gaussian.cpp +++ b/bob/learn/misc/gaussian.cpp @@ -23,47 +23,607 @@ static auto Gaussian_doc = bob::extension::ClassDoc( "", true ) - .add_prototype("[n_inputs]") - //.add_prototype("tan_triggs", "") - //.add_parameter("gamma", "float", "[default: ``0.2``] The value of gamma for the gamma correction") - //.add_parameter("sigma0", "float", "[default: ``1.``] The standard deviation of the inner Gaussian") - //.add_parameter("sigma1", "float", "[default: ``2.``] The standard deviation of the outer Gaussian") - //.add_parameter("radius", "int", "[default: ``2``] The radius of the Difference of Gaussians filter along both axes (size of the kernel=2*radius+1)") - //.add_parameter("threshold", "float", "[default: ``10.``] The threshold used for the contrast equalization") - //.add_parameter("alpha", "float", "[default: ``0.1``] The alpha value used for the contrast equalization") - //.add_parameter("border", ":py:class:`bob.sp.BorderType`", "[default: ``bob.sp.BorderType.Mirror``] The extrapolation method used by the convolution at the border") - //.add_parameter("tan_triggs", ":py:class:`bob.ip.base.TanTriggs`", "The TanTriggs object to use for copy-construction") + .add_prototype("n_inputs") + .add_prototype("gaussian") + .add_prototype("hdf5") + .add_prototype("") + + .add_parameter("mean", "array_like<double, 1D>", "Mean of the Gaussian") + .add_parameter("variance", "array_like<double, 1D>", "Variance of the Gaussian") + .add_parameter("dim_d", "int", "Dimensionality of the input feature space") + .add_parameter("variance_thresholds", "array_like <double, 1D>", "The variance flooring thresholds, i.e. the minimum allowed value of variance in each dimension. The variance will be set to this value if an attempt is made to set it to a smaller value.") + .add_parameter("shape", "(int)", "A tuple that represents the dimensionality of the Gaussian ``(dim_d,)``.") ); + +static int PyBobLearnMiscGaussian_init_number(PyBobLearnMiscGaussianObject* self, PyObject* args, PyObject* kwargs) { + + char** kwlist = Gaussian_doc.kwlist(0); + size_t n_inputs=1; + //Parsing the input argments + if (!PyArg_ParseTupleAndKeywords(args, kwargs, "I", kwlist, &n_inputs)) + return -1; + + self->cxx.reset(new bob::learn::misc::Gaussian(n_inputs)); + return 0; +} + +static int PyBobLearnMiscGaussian_init_copy(PyBobLearnMiscGaussianObject* self, PyObject* args, PyObject* kwargs) { + + char** kwlist = Gaussian_doc.kwlist(1); + PyBobLearnMiscGaussianObject* tt; + if (!PyArg_ParseTupleAndKeywords(args, kwargs, "O!", kwlist, &PyBobLearnMiscGaussian_Type, &tt)) return -1; + + self->cxx.reset(new bob::learn::misc::Gaussian(*tt->cxx)); + return 0; +} + +static int PyBobLearnMiscGaussian_init_hdf5(PyBobLearnMiscGaussianObject* self, PyObject* args, PyObject* kwargs) { + + char** kwlist = Gaussian_doc.kwlist(2); + + PyObject* config = 0; + if (!PyArg_ParseTupleAndKeywords(args, kwargs, "O!", kwlist, &PyBobIoHDF5File_Type, &config)) + return -1; + auto h5f = reinterpret_cast<PyBobIoHDF5FileObject*>(config); + + try { + self->cxx.reset(new bob::learn::misc::Gaussian(*(h5f->f))); + } + catch (std::exception& ex) { + PyErr_SetString(PyExc_RuntimeError, ex.what()); + return -1; + } + catch (...) { + PyErr_Format(PyExc_RuntimeError, "cannot create new object of type `%s' - unknown exception thrown", Py_TYPE(self)->tp_name); + return -1; + } + + return 0; +} + + + static int PyBobLearnMiscGaussian_init(PyBobLearnMiscGaussianObject* self, PyObject* args, PyObject* kwargs) { - TRY - char* kwlist1[] = {c("n_inputs")}; - //char* kwlist2[] = {c("tan_triggs"), NULL}; + BOB_TRY // get the number of command line arguments Py_ssize_t nargs = (args?PyTuple_Size(args):0) + (kwargs?PyDict_Size(kwargs):0); + if (nargs==0){ + self->cxx.reset(new bob::learn::misc::Gaussian()); + return 0; + } + + //Reading the input argument + PyObject* arg = 0; + if (PyTuple_Size(args)) + arg = PyTuple_GET_ITEM(args, 0); + else { + PyObject* tmp = PyDict_Values(kwargs); + auto tmp_ = make_safe(tmp); + arg = PyList_GET_ITEM(tmp, 0); + } + + /**If the constructor input is a number**/ + if (PyNumber_Check(arg)) + return PyBobLearnMiscGaussian_init_number(self, args, kwargs); + /**If the constructor input is Gaussian object**/ + else if (PyBobLearnMiscGaussian_Check(arg)) + return PyBobLearnMiscGaussian_init_copy(self, args, kwargs); + /**If the constructor input is a HDF5**/ + else if (PyBobIoHDF5File_Check(arg)) + return PyBobLearnMiscGaussian_init_hdf5(self, args, kwargs); + + return -1; + + BOB_CATCH_MEMBER("cannot create Gaussian", 0) - /* - PyObject* k = Py_BuildValue("s", kwlist2[0]); - auto k_ = make_safe(k); - if (nargs == 1 && ((args && PyTuple_Size(args) == 1 && PyBobIpBaseTanTriggs_Check(PyTuple_GET_ITEM(args,0))) || (kwargs && PyDict_Contains(kwargs, k)))){ - // copy construct - PyBobIpBaseTanTriggsObject* tt; - if (!PyArg_ParseTupleAndKeywords(args, kwargs, "O!", kwlist2, &PyBobIpBaseTanTriggs_Type, &tt)) return -1; +} + + + +static void PyBobLearnMiscGaussian_delete(PyBobLearnMiscGaussianObject* self) { + self->cxx.reset(); + Py_TYPE(self)->tp_free((PyObject*)self); +} + +static PyObject* PyBobLearnMiscGaussian_RichCompare(PyBobLearnMiscGaussianObject* self, PyObject* other, int op) { + BOB_TRY - self->cxx.reset(new bob::ip::base::TanTriggs(*tt->cxx)); + if (!PyBobLearnMiscGaussian_Check(other)) { + PyErr_Format(PyExc_TypeError, "cannot compare `%s' with `%s'", Py_TYPE(self)->tp_name, Py_TYPE(other)->tp_name); return 0; - }*/ + } + auto other_ = reinterpret_cast<PyBobLearnMiscGaussianObject*>(other); + switch (op) { + case Py_EQ: + if (*self->cxx==*other_->cxx) Py_RETURN_TRUE; else Py_RETURN_FALSE; + case Py_NE: + if (*self->cxx==*other_->cxx) Py_RETURN_FALSE; else Py_RETURN_TRUE; + default: + Py_INCREF(Py_NotImplemented); + return Py_NotImplemented; + } + BOB_CATCH_MEMBER("cannot compare Gaussian objects", 0) +} - size_t n_inputs=0; - self->cxx.reset(new bob::learn::misc::Gaussian(n_inputs)); +int PyBobLearnMiscGaussian_Check(PyObject* o) { + return PyObject_IsInstance(o, reinterpret_cast<PyObject*>(&PyBobLearnMiscGaussian_Type)); +} + + +/******************************************************************/ +/************ Variables Section ***********************************/ +/******************************************************************/ + +/***** MEAN *****/ +static auto mean = bob::extension::VariableDoc( + "mean", + "array_like <double, 1D>", + "Mean of the Gaussian" +); +PyObject* PyBobLearnMiscGaussian_getMean(PyBobLearnMiscGaussianObject* self, void*){ + BOB_TRY + return PyBlitzArrayCxx_AsConstNumpy(self->cxx->getMean()); + BOB_CATCH_MEMBER("mean could not be read", 0) +} +int PyBobLearnMiscGaussian_setMean(PyBobLearnMiscGaussianObject* self, PyObject* value, void*){ + BOB_TRY + PyBlitzArrayObject* o; + if (!PyBlitzArray_Converter(value, &o)){ + PyErr_Format(PyExc_RuntimeError, "%s %s expects a 1D array of floats", Py_TYPE(self)->tp_name, mean.name()); + return -1; + } + auto b = PyBlitzArrayCxx_AsBlitz<double,1>(o, "mean"); + if (!b) return -1; + self->cxx->setMean(*b); return 0; + BOB_CATCH_MEMBER("mean could not be set", -1) +} - CATCH("cannot create Gaussian", -1) +/***** Variance *****/ +static auto variance = bob::extension::VariableDoc( + "variance", + "array_like <double, 1D>", + "Variance of the Gaussian" +); +PyObject* PyBobLearnMiscGaussian_getVariance(PyBobLearnMiscGaussianObject* self, void*){ + BOB_TRY + return PyBlitzArrayCxx_AsConstNumpy(self->cxx->getVariance()); + BOB_CATCH_MEMBER("variance could not be read", 0) +} +int PyBobLearnMiscGaussian_setVariance(PyBobLearnMiscGaussianObject* self, PyObject* value, void*){ + BOB_TRY + PyBlitzArrayObject* o; + if (!PyBlitzArray_Converter(value, &o)){ + PyErr_Format(PyExc_RuntimeError, "%s %s expects a 2D array of floats", Py_TYPE(self)->tp_name, variance.name()); + return -1; + } + auto b = PyBlitzArrayCxx_AsBlitz<double,1>(o, "variance"); + if (!b) return -1; + self->cxx->setVariance(*b); + return 0; + BOB_CATCH_MEMBER("variance could not be set", -1) +} + +/***** dim_d *****/ +static auto dimD = bob::extension::VariableDoc( + "dim_d", + "int", + "Dimensionality of the input feature space" +); +PyObject* PyBobLearnMiscGaussian_getdimD(PyBobLearnMiscGaussianObject* self, void*){ + BOB_TRY + return Py_BuildValue("i", self->cxx->getNInputs()); + BOB_CATCH_MEMBER("dimD could not be read", 0) } +int PyBobLearnMiscGaussian_setdimD(PyBobLearnMiscGaussianObject* self, PyObject* value, void*){ + BOB_TRY + if (!PyInt_Check(value)){ + PyErr_Format(PyExc_RuntimeError, "%s %s expects an int", Py_TYPE(self)->tp_name, dimD.name()); + return -1; + } + + if (PyInt_AS_LONG(value) <= 0){ + PyErr_Format(PyExc_TypeError, "dim_d must be greater than zero"); + return -1; + } + + self->cxx->setNInputs(PyInt_AS_LONG(value)); + return 0; + BOB_CATCH_MEMBER("dim_d could not be set", -1) +} + + +/***** variance_thresholds *****/ +static auto variance_thresholds = bob::extension::VariableDoc( + "variance_thresholds", + "array_like <double, 1D>", + "The variance flooring thresholds, i.e. the minimum allowed value of variance in each dimension. The variance will be set to this value if an attempt is made to set it to a smaller value." +); +PyObject* PyBobLearnMiscGaussian_getVarianceThresholds(PyBobLearnMiscGaussianObject* self, void*){ + BOB_TRY + return PyBlitzArrayCxx_AsConstNumpy(self->cxx->getVarianceThresholds()); + BOB_CATCH_MEMBER("variance_thresholds could not be read", 0) +} +int PyBobLearnMiscGaussian_setVarianceThresholds(PyBobLearnMiscGaussianObject* self, PyObject* value, void*){ + BOB_TRY + PyBlitzArrayObject* o; + if (!PyBlitzArray_Converter(value, &o)){ + PyErr_Format(PyExc_RuntimeError, "%s %s expects a 1D array of floats", Py_TYPE(self)->tp_name, variance_thresholds.name()); + return -1; + } + auto b = PyBlitzArrayCxx_AsBlitz<double,1>(o, "variance_thresholds"); + if (!b) return -1; + self->cxx->setVarianceThresholds(*b); + return 0; + BOB_CATCH_MEMBER("variance_thresholds could not be set", -1) +} + + +/***** shape *****/ +static auto shape = bob::extension::VariableDoc( + "shape", + "(int)", + "A tuple that represents the dimensionality of the Gaussian ``(dim_d,)``." +); +PyObject* PyBobLearnMiscGaussian_getShape(PyBobLearnMiscGaussianObject* self, void*) { + BOB_TRY + return Py_BuildValue("(n)", self->cxx->getNInputs()); + BOB_CATCH_MEMBER("shape could not be read", 0) +} +int PyBobLearnMiscGaussian_setShape(PyBobLearnMiscGaussianObject* self, PyObject* o, void*){ + BOB_TRY + + if (!PySequence_Check(o)) { + PyErr_Format(PyExc_TypeError, "`%s' shape can only be set using tuples (or sequences), not `%s'", Py_TYPE(self)->tp_name, Py_TYPE(o)->tp_name); + return -1; + } + + //getting the shape + PyObject* shape = PySequence_Tuple(o); + auto shape_ = make_safe(shape); + Py_ssize_t dim_d = PyNumber_AsSsize_t(PyTuple_GET_ITEM(shape, 0), PyExc_OverflowError); + + self->cxx->setNInputs(dim_d); + return 0; + + BOB_CATCH_MEMBER("variance_thresholds could not be set", -1) +} + + +static PyGetSetDef PyBobLearnMiscGaussian_getseters[] = { + { + mean.name(), + (getter)PyBobLearnMiscGaussian_getMean, + (setter)PyBobLearnMiscGaussian_setMean, + mean.doc(), + 0 + }, + { + variance.name(), + (getter)PyBobLearnMiscGaussian_getVariance, + (setter)PyBobLearnMiscGaussian_setVariance, + variance.doc(), + 0 + }, + { + dimD.name(), + (getter)PyBobLearnMiscGaussian_getdimD, + (setter)PyBobLearnMiscGaussian_setdimD, + dimD.doc(), + 0 + }, + { + variance_thresholds.name(), + (getter)PyBobLearnMiscGaussian_getVarianceThresholds, + (setter)PyBobLearnMiscGaussian_setVarianceThresholds, + variance_thresholds.doc(), + 0 + }, + { + shape.name(), + (getter)PyBobLearnMiscGaussian_getShape, + (setter)PyBobLearnMiscGaussian_setShape, + shape.doc(), + 0 + }, + + {0} // Sentinel +}; + + +/******************************************************************/ +/************ Functions Section ***********************************/ +/******************************************************************/ + +/*** resize ***/ +static auto resize = bob::extension::FunctionDoc( + "resize", + "int" + " Set the input dimensionality, reset the mean to zero and the variance to one." +) +.add_prototype("input") +.add_parameter("input", "int", "Tuple with the new shape"); +static PyObject* PyBobLearnMiscGaussian_resize(PyBobLearnMiscGaussianObject* self, PyObject* args, PyObject* kwargs) { + BOB_TRY + + /* Parses input arguments in a single shot */ + static const char* const_kwlist[] = {"input", 0}; + static char** kwlist = const_cast<char**>(const_kwlist); + + Py_ssize_t input = 0; + if (!PyArg_ParseTupleAndKeywords(args, kwargs, "n", kwlist, &input)) Py_RETURN_NONE; + if (input <= 0){ + PyErr_Format(PyExc_TypeError, "input must be greater than zero"); + Py_RETURN_NONE; + } + self->cxx->setNInputs(input); + + BOB_CATCH_MEMBER("cannot perform the resize method", 0) + + Py_RETURN_NONE; +} + +/*** log_likelihood ***/ +static auto forward = bob::extension::FunctionDoc( + "forward", + "array_like <double, 1D>" + " Output the log likelihood of the sample, x. The input size is checked." +) +.add_prototype("input","double") +.add_parameter("input", "array_like <double, 1D>", "Input vector") +.add_return("double","double","The log likelihood"); +/*** log_likelihood ***/ +static auto log_likelihood = bob::extension::FunctionDoc( + "log_likelihood", + "array_like <double, 1D>" + " Output the log likelihood of the sample, x. The input size is checked." +) +.add_prototype("input","double") +.add_parameter("input", "array_like <double, 1D>", "Input vector") +.add_return("double","double","The log likelihood"); +static PyObject* PyBobLearnMiscGaussian_loglikelihood(PyBobLearnMiscGaussianObject* self, PyObject* args, PyObject* kwargs) { + BOB_TRY + + static const char* const_kwlist[] = {"input", 0}; + static char** kwlist = const_cast<char**>(const_kwlist); + + PyBlitzArrayObject* input = 0; + + if (!PyArg_ParseTupleAndKeywords(args, kwargs, "O&", kwlist, &PyBlitzArray_Converter, &input)) Py_RETURN_NONE; + //protects acquired resources through this scope + auto input_ = make_safe(input); + + double value = self->cxx->logLikelihood(*PyBlitzArrayCxx_AsBlitz<double,1>(input)); + return Py_BuildValue("d", value); + + BOB_CATCH_MEMBER("cannot compute the likelihood", 0) +} + + +/*** log_likelihood_ ***/ +static auto log_likelihood_ = bob::extension::FunctionDoc( + "log_likelihood_", + "array_like <double, 1D>" + " Output the log likelihood given a sample. The input size is NOT checked." +) +.add_prototype("input","double") +.add_parameter("input", "array_like <double, 1D>", "Input vector") +.add_return("double","double","The log likelihood"); +static PyObject* PyBobLearnMiscGaussian_loglikelihood_(PyBobLearnMiscGaussianObject* self, PyObject* args, PyObject* kwargs) { + BOB_TRY + + static const char* const_kwlist[] = {"input", 0}; + static char** kwlist = const_cast<char**>(const_kwlist); + + PyBlitzArrayObject* input = 0; + + if (!PyArg_ParseTupleAndKeywords(args, kwargs, "O&", kwlist, &PyBlitzArray_Converter, &input)) Py_RETURN_NONE; + //protects acquired resources through this scope + auto input_ = make_safe(input); + + double value = self->cxx->logLikelihood_(*PyBlitzArrayCxx_AsBlitz<double,1>(input)); + return Py_BuildValue("d", value); + + BOB_CATCH_MEMBER("cannot compute the likelihood", 0) +} + + +/*** save ***/ +static auto save = bob::extension::FunctionDoc( + "save", + " Save the configuration of the Gassian Machine to a given HDF5 file", + 0, + true +) +.add_prototype("hdf5") +.add_parameter("hdf5", ":py:class:`bob.io.base.HDF5File`", "An HDF5 file open for writing") +; +static PyObject* PyBobLearnMiscGaussian_Save(PyBobLearnMiscGaussianObject* self, PyObject* args, PyObject* kwargs) { + // get list of arguments + char** kwlist = save.kwlist(0); + PyBobIoHDF5FileObject* hdf5 = 0; + if (!PyArg_ParseTupleAndKeywords(args, kwargs, "O&", kwlist, PyBobIoHDF5File_Converter, &hdf5)){ + save.print_usage(); + return NULL; + } + auto hdf5_ = make_safe(hdf5); + + try { + self->cxx->save(*hdf5->f); + } + catch (std::exception& e) { + PyErr_SetString(PyExc_RuntimeError, e.what()); + return 0; + } + catch (...) { + PyErr_Format(PyExc_RuntimeError, "`%s' cannot write data to file `%s' (at group `%s'): unknown exception caught", Py_TYPE(self)->tp_name, + hdf5->f->filename().c_str(), hdf5->f->cwd().c_str()); + return 0; + } + + Py_RETURN_NONE; +} + +/*** load ***/ +static auto load = bob::extension::FunctionDoc( + "load", + " Load the configuration of the Gassian Machine to a given HDF5 file", + 0, + true +); +static PyObject* PyBobLearnMiscGaussian_Load(PyBobLearnMiscGaussianObject* self, PyObject* f) { + + if (!PyBobIoHDF5File_Check(f)) { + PyErr_Format(PyExc_TypeError, "`%s' cannot load itself from `%s', only from an HDF5 file", Py_TYPE(self)->tp_name, Py_TYPE(f)->tp_name); + return 0; + } + + auto h5f = reinterpret_cast<PyBobIoHDF5FileObject*>(f); + + try { + self->cxx->load(*h5f->f); + } + catch (std::exception& e) { + PyErr_SetString(PyExc_RuntimeError, e.what()); + return 0; + } + catch (...) { + PyErr_Format(PyExc_RuntimeError, "cannot read data from file `%s' (at group `%s'): unknown exception caught", h5f->f->filename().c_str(), + h5f->f->cwd().c_str()); + return 0; + } + Py_RETURN_NONE; +} + + +/*** is_similar_to ***/ +static auto is_similar_to = bob::extension::FunctionDoc( + "is_similar_to", + + "Compares this Gaussian with the ``other`` one to be\n\ + approximately the same.\n\ + \n\ + The optional values ``r_epsilon`` and ``a_epsilon`` refer to the\n\ + relative and absolute precision for the ``weights``, ``biases``\n\ + and any other values internal to this machine.\n\ + \n\ + ", + + 0, + true +) +.add_prototype("other, [r_epsilon], [a_epsilon]","bool") +.add_parameter("other", ":py:class:`bob.learn.misc.Gaussian`", "A gaussian to be compared.") +.add_parameter("[r_epsilon]", "float", "Relative precision.") +.add_parameter("[a_epsilon]", "float", "Absolute precision.") +.add_return("bool","",""); +static PyObject* PyBobLearnMiscGaussian_IsSimilarTo(PyBobLearnMiscGaussianObject* self, PyObject* args, PyObject* kwds) { + + /* Parses input arguments in a single shot */ + static const char* const_kwlist[] = {"other", "r_epsilon", "a_epsilon", 0}; + static char** kwlist = const_cast<char**>(const_kwlist); + + PyObject* other = 0; + double r_epsilon = 1.e-5; + double a_epsilon = 1.e-8; + + if (!PyArg_ParseTupleAndKeywords(args, kwds, "O!|dd", kwlist, + &PyBobLearnMiscGaussian_Type, &other, + &r_epsilon, &a_epsilon)) return 0; + + auto other_ = reinterpret_cast<PyBobLearnMiscGaussianObject*>(other); + + if (self->cxx->is_similar_to(*other_->cxx, r_epsilon, a_epsilon)) + Py_RETURN_TRUE; + else + Py_RETURN_FALSE; +} + + +/*** set_variance_thresholds ***/ +static auto set_variance_thresholds = bob::extension::FunctionDoc( + "set_variance_thresholds", + "int" + " Set the variance flooring thresholds equal to the given threshold for all the dimensions." +) +.add_prototype("input") +.add_parameter("input","float","Threshold") +; +static PyObject* PyBobLearnMiscGaussian_SetVarianceThresholds(PyBobLearnMiscGaussianObject* self, PyObject* args, PyObject* kwargs) { + BOB_TRY + + /* Parses input arguments in a single shot */ + static const char* const_kwlist[] = {"input", 0}; + static char** kwlist = const_cast<char**>(const_kwlist); + + double input = 0; + if (!PyArg_ParseTupleAndKeywords(args, kwargs, "d", kwlist, &input)) Py_RETURN_NONE; + + self->cxx->setVarianceThresholds(input); + + BOB_CATCH_MEMBER("cannot perform the set_variance_Thresholds method", 0) + + Py_RETURN_NONE; +} + + +static PyMethodDef PyBobLearnMiscGaussian_methods[] = { + { + resize.name(), + (PyCFunction)PyBobLearnMiscGaussian_resize, + METH_VARARGS|METH_KEYWORDS, + resize.doc() + }, + { + log_likelihood.name(), + (PyCFunction)PyBobLearnMiscGaussian_loglikelihood, + METH_VARARGS|METH_KEYWORDS, + log_likelihood.doc() + }, + { + forward.name(), + (PyCFunction)PyBobLearnMiscGaussian_loglikelihood, + METH_VARARGS|METH_KEYWORDS, + forward.doc() + }, + { + log_likelihood_.name(), + (PyCFunction)PyBobLearnMiscGaussian_loglikelihood_, + METH_VARARGS|METH_KEYWORDS, + log_likelihood_.doc() + }, + { + save.name(), + (PyCFunction)PyBobLearnMiscGaussian_Save, + METH_VARARGS|METH_KEYWORDS, + save.doc() + }, + { + load.name(), + (PyCFunction)PyBobLearnMiscGaussian_Load, + METH_VARARGS|METH_KEYWORDS, + load.doc() + }, + { + is_similar_to.name(), + (PyCFunction)PyBobLearnMiscGaussian_IsSimilarTo, + METH_VARARGS|METH_KEYWORDS, + is_similar_to.doc() + }, + { + set_variance_thresholds.name(), + (PyCFunction)PyBobLearnMiscGaussian_SetVarianceThresholds, + METH_VARARGS|METH_KEYWORDS, + set_variance_thresholds.doc() + }, + + {0} /* Sentinel */ +}; /******************************************************************/ @@ -87,11 +647,11 @@ bool init_BobLearnMiscGaussian(PyObject* module) // set the functions PyBobLearnMiscGaussian_Type.tp_new = PyType_GenericNew; PyBobLearnMiscGaussian_Type.tp_init = reinterpret_cast<initproc>(PyBobLearnMiscGaussian_init); - //PyBobLearnMiscGaussian_Type.tp_dealloc = reinterpret_cast<destructor>(PyBobIpBaseTanTriggs_delete); - //PyBobLearnMiscGaussian_Type.tp_richcompare = reinterpret_cast<richcmpfunc>(PyBobIpBaseTanTriggs_RichCompare); - //PyBobLearnMiscGaussian_Type.tp_methods = PyBobIpBaseTanTriggs_methods; - //PyBobLearnMiscGaussian_Type.tp_getset = PyBobIpBaseTanTriggs_getseters; - //PyBobLearnMiscGaussian_Type.tp_call = reinterpret_cast<ternaryfunc>(PyBobIpBaseTanTriggs_process); + PyBobLearnMiscGaussian_Type.tp_dealloc = reinterpret_cast<destructor>(PyBobLearnMiscGaussian_delete); + PyBobLearnMiscGaussian_Type.tp_richcompare = reinterpret_cast<richcmpfunc>(PyBobLearnMiscGaussian_RichCompare); + PyBobLearnMiscGaussian_Type.tp_methods = PyBobLearnMiscGaussian_methods; + PyBobLearnMiscGaussian_Type.tp_getset = PyBobLearnMiscGaussian_getseters; + PyBobLearnMiscGaussian_Type.tp_call = reinterpret_cast<ternaryfunc>(PyBobLearnMiscGaussian_loglikelihood); // check that everything is fine if (PyType_Ready(&PyBobLearnMiscGaussian_Type) < 0) return false; diff --git a/bob/learn/misc/test_gaussian.py b/bob/learn/misc/test_gaussian.py index c6cc220f9cf06df50ab7ec8e816ab57e0cc9579c..4a798659272d6894e7515db68bf66101aa9be132 100644 --- a/bob/learn/misc/test_gaussian.py +++ b/bob/learn/misc/test_gaussian.py @@ -14,7 +14,7 @@ import tempfile import bob.io.base -from . import Gaussian +from bob.learn.misc import Gaussian def equals(x, y, epsilon): return (abs(x - y) < epsilon) diff --git a/buildout.cfg b/buildout.cfg index 82028e68a36cd762f8ec181b31f9297dce20aa44..f8fe5d99356b987f948868209ca33b3be0804182 100644 --- a/buildout.cfg +++ b/buildout.cfg @@ -7,9 +7,9 @@ parts = scripts eggs = bob.learn.misc extensions = bob.buildout ; mr.developer + ;auto-checkout = * develop = . - ;src/bob.extension ; src/bob.blitz ; src/bob.core @@ -18,6 +18,7 @@ develop = . ; src/bob.math ; src/bob.learn.activation ; src/bob.learn.linear +; src/bob.buildout ; . ; options for bob.buildout extension @@ -28,9 +29,9 @@ prefer-final = false [environ] BOB_BUILD_PARALLEL = 4 -BOB_PREFIX_PATH = /remote/filer.gx/group.torch5spro/externals/py278/usr ;[sources] +;bob.buildout = git https://github.com/bioidiap/bob.buildout ;bob.extension = git https://github.com/bioidiap/bob.extension ;bob.blitz = git https://github.com/bioidiap/bob.blitz ;bob.core = git https://github.com/bioidiap/bob.core