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

Specialize this package to only contain Activation functors

parent 8a800933
include LICENSE README.rst bootstrap.py buildout.cfg
recursive-include doc conf.py *.rst
recursive-include xbob *.cpp *.h
recursive-include xbob/machine/data *.*
......@@ -2,12 +2,12 @@
.. Andre Anjos <andre.anjos@idiap.ch>
.. Fri 13 Dec 2013 12:35:22 CET
=================================
Python bindings for bob.machine
=================================
==========================================
Python bindings for bob.learn.activation
==========================================
This package contains a set of Pythonic bindings for Bob's machine packages and
functionality.
This package contains a set of Pythonic bindings for Bob's machine Activation
functors.
Installation
------------
......@@ -31,7 +31,7 @@ Testing
You can run a set of tests using the nose test runner::
$ nosetests -sv xbob.machine
$ nosetests -sv xbob.learn.activation
.. warning::
......@@ -48,7 +48,7 @@ You can run our documentation tests using sphinx itself::
You can test overall test coverage with::
$ nosetests --with-coverage --cover-package=xbob.machine
$ nosetests --with-coverage --cover-package=xbob.learn.activation
The ``coverage`` egg must be installed for this to work properly.
......
......@@ -3,8 +3,8 @@
; Mon 16 Apr 08:29:18 2012 CEST
[buildout]
parts = xbob.blitz xbob.io xbob.machine scripts
eggs = xbob.machine
parts = xbob.blitz xbob.io xbob.learn.activation scripts
eggs = xbob.learn.activation
ipdb
extensions = mr.developer
auto-checkout = *
......@@ -26,7 +26,7 @@ recipe = xbob.buildout:develop
setup = src/xbob.io
eggs = xbob.blitz xbob.buildout xbob.extension
[xbob.machine]
[xbob.learn.activation]
recipe = xbob.buildout:develop
eggs = xbob.blitz xbob.io
......
This diff is collapsed.
......@@ -4,13 +4,13 @@
..
.. Copyright (C) 2011-2013 Idiap Research Institute, Martigny, Switzerland
==============
Bob Machines
==============
=========================
Bob Activation Functors
=========================
This module contains base functionality from Bob bound to Python, available in
the C++ counter-part ``bob::machine``. It includes machines from our Machine
Learning core.
This module contains some functionality from Bob bound to Python, available in
the C++ counter-part ``bob::machine``. It includes Activation functors from the
Machine Learning core.
Reference
---------
......@@ -18,7 +18,6 @@ Reference
.. toctree::
:maxdepth: 2
guide
py_api
c_cpp_api
......
......@@ -7,8 +7,8 @@
============
This section includes information for using the pure Python API of
``xbob.machine``.
``xbob.learn.activation``.
.. automodule:: xbob.machine
.. automodule:: xbob.learn.activation
......@@ -10,7 +10,7 @@ import xbob.io
import os
package_dir = os.path.dirname(os.path.realpath(__file__))
package_dir = os.path.join(package_dir, 'xbob', 'machine', 'include')
package_dir = os.path.join(package_dir, 'xbob', 'learn', 'activation', 'include')
include_dirs = [package_dir, xbob.io.get_include()]
packages = ['bob-machine >= 1.3']
......@@ -18,10 +18,10 @@ version = '2.0.0a0'
setup(
name='xbob.machine',
name='xbob.learn.activation',
version=version,
description='Bindings for bob.machine',
url='http://github.com/anjos/xbob.machine',
description='Bindings for bob.machine\'s Activation functors',
url='http://github.com/anjos/xbob.learn.activation',
license='BSD',
author='Andre Anjos',
author_email='andre.anjos@idiap.ch',
......@@ -39,27 +39,19 @@ setup(
namespace_packages=[
"xbob",
"xbob.learn",
],
ext_modules = [
Extension("xbob.machine._externals",
Extension("xbob.learn.activation._library",
[
"xbob/machine/externals.cpp",
],
packages = packages,
include_dirs = include_dirs,
version = version,
),
Extension("xbob.machine._library",
[
"xbob/machine/activation.cpp",
"xbob/machine/identity_activation.cpp",
"xbob/machine/linear_activation.cpp",
"xbob/machine/logistic_activation.cpp",
"xbob/machine/tanh_activation.cpp",
"xbob/machine/mult_tanh_activation.cpp",
"xbob/machine/linear.cpp",
"xbob/machine/main.cpp",
"xbob/learn/activation/activation.cpp",
"xbob/learn/activation/identity.cpp",
"xbob/learn/activation/linear.cpp",
"xbob/learn/activation/logistic.cpp",
"xbob/learn/activation/tanh.cpp",
"xbob/learn/activation/mult_tanh.cpp",
"xbob/learn/activation/main.cpp",
],
packages = packages,
include_dirs = include_dirs,
......@@ -67,11 +59,6 @@ setup(
),
],
entry_points={
'console_scripts': [
],
},
classifiers = [
'Development Status :: 3 - Alpha',
'Intended Audience :: Developers',
......
#see http://peak.telecommunity.com/DevCenter/setuptools#namespace-packages
__import__('pkg_resources').declare_namespace(__name__)
from ._library import *
from ._library import __version__, __api_version__
......@@ -7,9 +7,9 @@
* Copyright (C) 2011-2014 Idiap Research Institute, Martigny, Switzerland
*/
#define XBOB_MACHINE_MODULE
#define XBOB_LEARN_ACTIVATION_MODULE
#include "cleanup.h"
#include <xbob.machine/api.h>
#include <xbob.learn.activation/api.h>
#include <xbob.io/api.h>
#include <xbob.blitz/cppapi.h>
#include <bob/machine/Activation.h>
......@@ -24,7 +24,7 @@
PyDoc_STRVAR(s_activation_str, XBOB_EXT_MODULE_PREFIX ".Activation");
PyDoc_STRVAR(s_activation_doc,
"Base class for activation functions (actually, *functors*).\n\
"Base class for activation functors.\n\
\n\
.. warning::\n\
\n\
......@@ -43,7 +43,8 @@ PyDoc_STRVAR(s_activation_doc,
\n\
");
static int PyBobMachineActivation_init(PyBobMachineActivationObject* self, PyObject*, PyObject*) {
static int PyBobLearnActivation_init(PyBobLearnActivationObject* self,
PyObject*, PyObject*) {
PyErr_Format(PyExc_NotImplementedError, "cannot initialize object of base type `%s' - use one of the inherited classes", s_activation_str);
return -1;
......@@ -98,7 +99,7 @@ static int apply(boost::function<double (double)> function,
}
static PyObject* PyBobMachineActivation_call1(PyBobMachineActivationObject* o,
static PyObject* PyBobLearnActivation_call1(PyBobLearnActivationObject* o,
double (bob::machine::Activation::*method) (double) const,
PyObject* args, PyObject* kwds) {
......@@ -162,7 +163,7 @@ static PyObject* PyBobMachineActivation_call1(PyBobMachineActivationObject* o,
}
static PyObject* PyBobMachineActivation_call2(PyBobMachineActivationObject* o,
static PyObject* PyBobLearnActivation_call2(PyBobLearnActivationObject* o,
double (bob::machine::Activation::*method) (double) const,
PyObject* args, PyObject* kwds) {
......@@ -248,7 +249,7 @@ error otherwise.\n\
\n\
");
static PyObject* PyBobMachineActivation_call(PyBobMachineActivationObject* o,
static PyObject* PyBobLearnActivation_call(PyBobLearnActivationObject* o,
PyObject* args, PyObject* kwds) {
Py_ssize_t nargs = args?PyTuple_Size(args):0 + kwds?PyDict_Size(kwds):0;
......@@ -256,12 +257,12 @@ static PyObject* PyBobMachineActivation_call(PyBobMachineActivationObject* o,
switch (nargs) {
case 1:
return PyBobMachineActivation_call1
return PyBobLearnActivation_call1
(o, &bob::machine::Activation::f, args, kwds);
break;
case 2:
return PyBobMachineActivation_call2
return PyBobLearnActivation_call2
(o, &bob::machine::Activation::f, args, kwds);
break;
......@@ -300,7 +301,7 @@ error otherwise.\n\
\n\
");
static PyObject* PyBobMachineActivation_f_prime(PyBobMachineActivationObject* o,
static PyObject* PyBobLearnActivation_f_prime(PyBobLearnActivationObject* o,
PyObject* args, PyObject* kwds) {
Py_ssize_t nargs = args?PyTuple_Size(args):0 + kwds?PyDict_Size(kwds):0;
......@@ -308,12 +309,12 @@ static PyObject* PyBobMachineActivation_f_prime(PyBobMachineActivationObject* o,
switch (nargs) {
case 1:
return PyBobMachineActivation_call1
return PyBobLearnActivation_call1
(o, &bob::machine::Activation::f_prime, args, kwds);
break;
case 2:
return PyBobMachineActivation_call2
return PyBobLearnActivation_call2
(o, &bob::machine::Activation::f_prime, args, kwds);
break;
......@@ -352,7 +353,7 @@ error otherwise.\n\
\n\
");
static PyObject* PyBobMachineActivation_f_prime_from_f(PyBobMachineActivationObject* o,
static PyObject* PyBobLearnActivation_f_prime_from_f(PyBobLearnActivationObject* o,
PyObject* args, PyObject* kwds) {
Py_ssize_t nargs = args?PyTuple_Size(args):0 + kwds?PyDict_Size(kwds):0;
......@@ -360,12 +361,12 @@ static PyObject* PyBobMachineActivation_f_prime_from_f(PyBobMachineActivationObj
switch (nargs) {
case 1:
return PyBobMachineActivation_call1
return PyBobLearnActivation_call1
(o, &bob::machine::Activation::f_prime_from_f, args, kwds);
break;
case 2:
return PyBobMachineActivation_call2
return PyBobLearnActivation_call2
(o, &bob::machine::Activation::f_prime_from_f, args, kwds);
break;
......@@ -388,7 +389,7 @@ in connection with the Activation registry.\n\
\n\
");
static PyObject* PyBobMachineActivation_UniqueIdentifier (PyBobMachineActivationObject* o) {
static PyObject* PyBobLearnActivation_UniqueIdentifier (PyBobLearnActivationObject* o) {
return Py_BuildValue("s", o->base->unique_identifier().c_str());
}
......@@ -400,7 +401,7 @@ Loads itself from a :py:class:`xbob.io.HDF5File`\n\
\n\
");
static PyObject* PyBobMachineActivation_Load(PyBobMachineActivationObject* o,
static PyObject* PyBobLearnActivation_Load(PyBobLearnActivationObject* o,
PyObject* f) {
if (!PyBobIoHDF5File_Check(f)) {
......@@ -434,7 +435,7 @@ Loads itself from a :py:class:`xbob.io.HDF5File`\n\
\n\
");
static PyObject* PyBobMachineActivation_Save(PyBobMachineActivationObject* o,
static PyObject* PyBobLearnActivation_Save(PyBobLearnActivationObject* o,
PyObject* f) {
if (!PyBobIoHDF5File_Check(f)) {
......@@ -460,59 +461,59 @@ static PyObject* PyBobMachineActivation_Save(PyBobMachineActivationObject* o,
Py_RETURN_NONE;
}
static PyMethodDef PyBobMachineActivation_methods[] = {
static PyMethodDef PyBobLearnActivation_methods[] = {
{
s_call_str,
(PyCFunction)PyBobMachineActivation_call,
(PyCFunction)PyBobLearnActivation_call,
METH_VARARGS|METH_KEYWORDS,
s_call_doc
},
{
s_f_prime_str,
(PyCFunction)PyBobMachineActivation_f_prime,
(PyCFunction)PyBobLearnActivation_f_prime,
METH_VARARGS|METH_KEYWORDS,
s_f_prime_doc
},
{
s_f_prime_from_f_str,
(PyCFunction)PyBobMachineActivation_f_prime_from_f,
(PyCFunction)PyBobLearnActivation_f_prime_from_f,
METH_VARARGS|METH_KEYWORDS,
s_f_prime_from_f_doc
},
{
s_unique_id_str,
(PyCFunction)PyBobMachineActivation_UniqueIdentifier,
(PyCFunction)PyBobLearnActivation_UniqueIdentifier,
METH_NOARGS,
s_unique_id_doc
},
{
s_load_str,
(PyCFunction)PyBobMachineActivation_Load,
(PyCFunction)PyBobLearnActivation_Load,
METH_O,
s_load_doc
},
{
s_save_str,
(PyCFunction)PyBobMachineActivation_Save,
(PyCFunction)PyBobLearnActivation_Save,
METH_O,
s_save_doc
},
{0} /* Sentinel */
};
int PyBobMachineActivation_Check(PyObject* o) {
return PyObject_IsInstance(o, reinterpret_cast<PyObject*>(&PyBobMachineActivation_Type));
int PyBobLearnActivation_Check(PyObject* o) {
return PyObject_IsInstance(o, reinterpret_cast<PyObject*>(&PyBobLearnActivation_Type));
}
static PyObject* PyBobMachineActivation_RichCompare (PyBobMachineActivationObject* self, PyObject* other, int op) {
static PyObject* PyBobLearnActivation_RichCompare (PyBobLearnActivationObject* self, PyObject* other, int op) {
if (!PyBobMachineActivation_Check(other)) {
if (!PyBobLearnActivation_Check(other)) {
PyErr_Format(PyExc_TypeError, "cannot compare `%s' with `%s'",
s_activation_str, other->ob_type->tp_name);
return 0;
}
auto other_ = reinterpret_cast<PyBobMachineActivationObject*>(other);
auto other_ = reinterpret_cast<PyBobLearnActivationObject*>(other);
switch (op) {
case Py_EQ:
......@@ -530,48 +531,48 @@ static PyObject* PyBobMachineActivation_RichCompare (PyBobMachineActivationObjec
}
static PyObject* PyBobMachineActivation_Str (PyBobMachineActivationObject* o) {
static PyObject* PyBobLearnActivation_Str (PyBobLearnActivationObject* o) {
return Py_BuildValue("s", o->base->str().c_str());
}
PyTypeObject PyBobMachineActivation_Type = {
PyTypeObject PyBobLearnActivation_Type = {
PyObject_HEAD_INIT(0)
0, /* ob_size */
s_activation_str, /* tp_name */
sizeof(PyBobMachineActivationObject), /* tp_basicsize */
0, /* tp_itemsize */
0, /* tp_dealloc */
0, /* tp_print */
0, /* tp_getattr */
0, /* tp_setattr */
0, /* tp_compare */
0, /* tp_repr */
0, /* tp_as_number */
0, /* tp_as_sequence */
0, /* tp_as_mapping */
0, /* tp_hash */
(ternaryfunc)PyBobMachineActivation_call, /* tp_call */
(reprfunc)PyBobMachineActivation_Str, /* tp_str */
0, /* tp_getattro */
0, /* tp_setattro */
0, /* tp_as_buffer */
Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags */
s_activation_doc, /* tp_doc */
0, /* tp_traverse */
0, /* tp_clear */
(richcmpfunc)PyBobMachineActivation_RichCompare, /* tp_richcompare */
0, /* tp_weaklistoffset */
0, /* tp_iter */
0, /* tp_iternext */
PyBobMachineActivation_methods, /* tp_methods */
0, /* tp_members */
0, /* tp_getset */
0, /* tp_base */
0, /* tp_dict */
0, /* tp_descr_get */
0, /* tp_descr_set */
0, /* tp_dictoffset */
(initproc)PyBobMachineActivation_init, /* tp_init */
0, /* tp_alloc */
0, /* tp_new */
0, /* ob_size */
s_activation_str, /* tp_name */
sizeof(PyBobLearnActivationObject), /* tp_basicsize */
0, /* tp_itemsize */
0, /* tp_dealloc */
0, /* tp_print */
0, /* tp_getattr */
0, /* tp_setattr */
0, /* tp_compare */
0, /* tp_repr */
0, /* tp_as_number */
0, /* tp_as_sequence */
0, /* tp_as_mapping */
0, /* tp_hash */
(ternaryfunc)PyBobLearnActivation_call, /* tp_call */
(reprfunc)PyBobLearnActivation_Str, /* tp_str */
0, /* tp_getattro */
0, /* tp_setattro */
0, /* tp_as_buffer */
Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags */
s_activation_doc, /* tp_doc */
0, /* tp_traverse */
0, /* tp_clear */
(richcmpfunc)PyBobLearnActivation_RichCompare, /* tp_richcompare */
0, /* tp_weaklistoffset */
0, /* tp_iter */
0, /* tp_iternext */
PyBobLearnActivation_methods, /* tp_methods */
0, /* tp_members */
0, /* tp_getset */
0, /* tp_base */
0, /* tp_dict */
0, /* tp_descr_get */
0, /* tp_descr_set */
0, /* tp_dictoffset */
(initproc)PyBobLearnActivation_init, /* tp_init */
0, /* tp_alloc */
0, /* tp_new */
};
......@@ -5,21 +5,21 @@
* @brief Implementation of the Identity Activation function
*/
#define XBOB_MACHINE_MODULE
#include <xbob.machine/api.h>
#define XBOB_LEARN_ACTIVATION_MODULE
#include <xbob.learn.activation/api.h>
PyDoc_STRVAR(s_identityactivation_str,
XBOB_EXT_MODULE_PREFIX ".IdentityActivation");
XBOB_EXT_MODULE_PREFIX ".Identity");
PyDoc_STRVAR(s_identityactivation_doc,
"IdentityActivation() -> new IdentityActivation\n\
"Identity() -> new Identity activation functor\n\
\n\
Computes :math:`f(z) = z` as activation function.\n\
\n\
");
static int PyBobMachineIdentityActivation_init
(PyBobMachineIdentityActivationObject* self, PyObject* args, PyObject* kwds) {
static int PyBobLearnIdentityActivation_init
(PyBobLearnIdentityActivationObject* self, PyObject* args, PyObject* kwds) {
/* Parses input arguments in a single shot */
static const char* const_kwlist[] = {0};
......@@ -45,8 +45,8 @@ static int PyBobMachineIdentityActivation_init
}
static void PyBobMachineIdentityActivation_delete
(PyBobMachineIdentityActivationObject* self) {
static void PyBobLearnIdentityActivation_delete
(PyBobLearnIdentityActivationObject* self) {
delete self->base;
self->parent.base = 0;
......@@ -55,13 +55,13 @@ static void PyBobMachineIdentityActivation_delete
}
PyTypeObject PyBobMachineIdentityActivation_Type = {
PyTypeObject PyBobLearnIdentityActivation_Type = {
PyObject_HEAD_INIT(0)
0, /*ob_size*/
s_identityactivation_str, /*tp_name*/
sizeof(PyBobMachineIdentityActivationObject), /*tp_basicsize*/
sizeof(PyBobLearnIdentityActivationObject), /*tp_basicsize*/
0, /*tp_itemsize*/
(destructor)PyBobMachineIdentityActivation_delete, /*tp_dealloc*/
(destructor)PyBobLearnIdentityActivation_delete, /*tp_dealloc*/
0, /*tp_print*/
0, /*tp_getattr*/
0, /*tp_setattr*/
......@@ -92,7 +92,7 @@ PyTypeObject PyBobMachineIdentityActivation_Type = {
0, /* tp_descr_get */
0, /* tp_descr_set */
0, /* tp_dictoffset */
(initproc)PyBobMachineIdentityActivation_init, /* tp_init */
(initproc)PyBobLearnIdentityActivation_init, /* tp_init */
0, /* tp_alloc */
0, /* tp_new */
};
/**
* @author Andre Anjos <andre.anjos@idiap.ch>
* @date Wed 15 Jan 2014 10:15:21 CET
*
* @brief C/C++ Python API for activation functors in bob::machine
*/
#ifndef XBOB_LEARN_ACTIVATION_H
#define XBOB_LEARN_ACTIVATION_H
#include <Python.h>
#include <xbob.learn.activation/config.h>
#include <bob/machine/Activation.h>
#include <bob/machine/LinearMachine.h>
#define XBOB_LEARN_ACTIVATION_MODULE_PREFIX xbob.learn.activation
#define XBOB_LEARN_ACTIVATION_MODULE_NAME _library
/*******************
* C API functions *
*******************/
/**************
* Versioning *
**************/
#define PyXbobLearnActivation_APIVersion_NUM 0
#define PyXbobLearnActivation_APIVersion_TYPE int
/*************************************************
* Bindings for xbob.learn.activation.Activation *
*************************************************/
typedef struct {
PyObject_HEAD
bob::machine::Activation* base;
} PyBobLearnActivationObject;
#define PyBobLearnActivation_Type_NUM 1
#define PyBobLearnActivation_Type_TYPE PyTypeObject
#define PyBobLearnActivation_Check_NUM 2
#define PyBobLearnActivation_Check_RET int
#define PyBobLearnActivation_Check_PROTO (PyObject* o)
/***********************************************
* Bindings for xbob.learn.activation.Identity *
***********************************************/
typedef struct {
PyBobLearnActivationObject parent;
bob::machine::IdentityActivation* base;
} PyBobLearnIdentityActivationObject;
#define PyBobLearnIdentityActivation_Type_NUM 3
#define PyBobLearnIdentityActivation_Type_TYPE PyTypeObject
/*********************************************
* Bindings for xbob.learn.activation.Linear *
*********************************************/
typedef struct {
PyBobLearnActivationObject parent;
bob::machine::LinearActivation* base;
} PyBobLearnLinearActivationObject;
#define PyBobLearnLinearActivation_Type_NUM 4
#define PyBobLearnLinearActivation_Type_TYPE PyTypeObject
/***********************************************
* Bindings for xbob.learn.activation.Logistic *
***********************************************/