Skip to content
Snippets Groups Projects
Commit b768b2f2 authored by André Anjos's avatar André Anjos :speech_balloon:
Browse files

All tests are passing

parent 5b96971f
No related branches found
No related tags found
No related merge requests found
......@@ -12,6 +12,7 @@ develop = src/xbob.extension
src/xbob.blitz
src/xbob.io
src/xbob.learn.activation
src/xbob.core
.
; options for xbob.buildout extension
......@@ -25,6 +26,7 @@ xbob.extension = git https://github.com/bioidiap/xbob.extension branch=prototype
xbob.blitz = git https://github.com/bioidiap/xbob.blitz
xbob.io = git https://github.com/bioidiap/xbob.io
xbob.learn.activation = git https://github.com/bioidiap/xbob.learn.activation
xbob.core = git https://github.com/bioidiap/xbob.core
[scripts]
recipe = xbob.buildout:scripts
......@@ -4,9 +4,10 @@
# Mon 16 Apr 08:18:08 2012 CEST
from setuptools import setup, find_packages, dist
dist.Distribution(dict(setup_requires=['xbob.blitz', 'xbob.io', 'xbob.learn.activation']))
dist.Distribution(dict(setup_requires=['xbob.blitz', 'xbob.io', 'xbob.learn.activation', 'xbob.core']))
from xbob.blitz.extension import Extension
import xbob.io
import xbob.core
import xbob.learn.activation
import os
......@@ -16,7 +17,8 @@ include_dirs = [
package_dir,
xbob.blitz.get_include(),
xbob.io.get_include(),
xbob.learn.activation.get_include()
xbob.learn.activation.get_include(),
xbob.core.get_include(),
]
packages = ['bob-machine >= 1.2.2', 'bob-trainer >= 1.2.2']
......@@ -42,6 +44,7 @@ setup(
'xbob.blitz',
'xbob.io',
'xbob.learn.activation',
'xbob.core',
],
namespace_packages=[
......
......@@ -13,6 +13,7 @@
#include <xbob.io/api.h>
#include <xbob.learn.activation/api.h>
#include <xbob.learn.mlp/api.h>
#include <xbob.core/random.h>
#include <structmember.h>
/****************************************
......@@ -942,6 +943,52 @@ static PyObject* PyBobLearnMLPMachine_IsSimilarTo
}
PyDoc_STRVAR(s_randomize_str, "randomize");
PyDoc_STRVAR(s_randomize_doc,
"o.randomize([lower_bound, [upper_bound, [rng]]]) -> None\n\
\n\
Resets parameters of this MLP using a random number generator.\n\
\n\
Sets all weights and biases of this MLP, with random values\n\
between :math:`[-0.1, 0.1)` as advised in textbooks.\n\nValues\n\
are drawn using ``boost::uniform_real`` class. The seed is\n\
picked using a time-based algorithm. Different calls spaced\n\
of at least 10 microseconds (machine clock) will be seeded\n\
differently. If lower and upper bound values are given, then\n\
new parameters are taken from ``[lower_bound, upper_bound)``,\n\
according to the ``boost::random`` documentation. The user may\n\
also pass the random number generator to be used. This allows\n\
you to set the seed to a specific value before randomizing\n\
the MLP parameters. If not set, this method will use an\n\
internal random number generator with a seed which is based\n\
on the current time.\n\
");
static PyObject* PyBobLearnMLPMachine_Randomize
(PyBobLearnMLPMachineObject* self, PyObject* args, PyObject* kwds) {
/* Parses input arguments in a single shot */
static const char* const_kwlist[] = {"lower_bound", "upper_bound", "rng", 0};
static char** kwlist = const_cast<char**>(const_kwlist);
double lower_bound = -0.1;
double upper_bound = 0.1;
PyBoostMt19937Object* rng = 0;
if (!PyArg_ParseTupleAndKeywords(args, kwds, "|ddO!", kwlist,
&lower_bound, &upper_bound, &PyBoostMt19937_Check, &rng)) return 0;
if (rng) {
self->cxx->randomize(*rng->rng, lower_bound, upper_bound);
}
else {
self->cxx->randomize(lower_bound, upper_bound);
}
Py_RETURN_NONE;
}
static PyMethodDef PyBobLearnMLPMachine_methods[] = {
{
s_forward_str,
......@@ -967,6 +1014,12 @@ static PyMethodDef PyBobLearnMLPMachine_methods[] = {
METH_VARARGS|METH_KEYWORDS,
s_is_similar_to_doc
},
{
s_randomize_str,
(PyCFunction)PyBobLearnMLPMachine_Randomize,
METH_VARARGS|METH_KEYWORDS,
s_randomize_doc
},
{0} /* Sentinel */
};
......
......@@ -15,6 +15,7 @@
#include <xbob.blitz/cleanup.h>
#include <xbob.io/api.h>
#include <xbob.learn.activation/api.h>
#include <xbob.core/random.h>
static PyMethodDef module_methods[] = {
{0} /* Sentinel */
......@@ -91,10 +92,30 @@ static PyObject* create_module (void) {
if (c_api_object) PyModule_AddObject(m, "_C_API", c_api_object);
/* imports xbob.learn.activation C-API + dependencies */
if (import_xbob_blitz() < 0) return 0;
if (import_xbob_io() < 0) return 0;
if (import_xbob_learn_activation() < 0) return 0;
/* imports dependencies */
if (import_xbob_blitz() < 0) {
PyErr_Print();
PyErr_Format(PyExc_ImportError, "cannot import `%s'", XBOB_EXT_MODULE_NAME);
return 0;
}
if (import_xbob_io() < 0) {
PyErr_Print();
PyErr_Format(PyExc_ImportError, "cannot import `%s'", XBOB_EXT_MODULE_NAME);
return 0;
}
if (import_xbob_learn_activation() < 0) {
PyErr_Print();
PyErr_Format(PyExc_ImportError, "cannot import `%s'", XBOB_EXT_MODULE_NAME);
return 0;
}
if (import_xbob_core_random() < 0) {
PyErr_Print();
PyErr_Format(PyExc_ImportError, "cannot import `%s'", XBOB_EXT_MODULE_NAME);
return 0;
}
Py_INCREF(m);
return m;
......
......@@ -24,6 +24,7 @@
#include <xbob.io/config.h>
#include <xbob.learn.activation/config.h>
#include <xbob.learn.mlp/config.h>
#include <xbob.core/config.h>
static int dict_set(PyObject* d, const char* key, const char* value) {
PyObject* v = Py_BuildValue("s", value);
......@@ -113,7 +114,14 @@ static PyObject* xbob_io_version() {
}
/**
* xbob.io c/c++ api version
* xbob.core c/c++ api version
*/
static PyObject* xbob_core_version() {
return Py_BuildValue("{ss}", "api", BOOST_PP_STRINGIZE(XBOB_CORE_API_VERSION));
}
/**
* xbob.learn.activation c/c++ api version
*/
static PyObject* xbob_learn_activation_version() {
return Py_BuildValue("{ss}", "api", BOOST_PP_STRINGIZE(XBOB_LEARN_ACTIVATION_API_VERSION));
......@@ -132,6 +140,7 @@ static PyObject* build_version_dictionary() {
if (!dict_steal(retval, "NumPy", numpy_version())) return 0;
if (!dict_steal(retval, "xbob.blitz", xbob_blitz_version())) return 0;
if (!dict_steal(retval, "xbob.io", xbob_io_version())) return 0;
if (!dict_steal(retval, "xbob.core", xbob_core_version())) return 0;
if (!dict_steal(retval, "xbob.learn.activation", xbob_learn_activation_version())) return 0;
if (!dict_steal(retval, "Bob", bob_version())) return 0;
......@@ -178,7 +187,7 @@ static PyObject* create_module (void) {
if (!externals) return 0;
if (PyModule_AddObject(m, "externals", externals) < 0) return 0;
/* imports xbob.io C-API + dependencies */
/* imports xbob.blitz C-API + dependencies */
if (import_xbob_blitz() < 0) return 0;
Py_INCREF(m);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment