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

Re-start trainer from scratch

parent 239605df
......@@ -195,6 +195,7 @@ setup(
),
Extension("xbob.learn.libsvm._library",
[
"xbob/learn/libsvm/pytrainer.cpp",
"xbob/learn/libsvm/pyfile.cpp",
"xbob/learn/libsvm/pymachine.cpp",
"xbob/learn/libsvm/main.cpp",
......
......@@ -48,24 +48,34 @@ typedef struct {
* Bindings for xbob.learn.libsvm.Machine *
******************************************/
#define PyBobLearnLibsvmMachineSvmType_Type_NUM 3
#define PyBobLearnLibsvmMachineSvmType_Type_TYPE PyTypeObject
#define PyBobLearnLibsvmMachineSvmKernelType_Type_NUM 4
#define PyBobLearnLibsvmMachineSvmKernelType_Type_TYPE PyTypeObject
typedef struct {
PyObject_HEAD
bob::learn::libsvm::Machine* cxx;
} PyBobLearnLibsvmMachineObject;
#define PyBobLearnLibsvmMachine_Type_NUM 5
#define PyBobLearnLibsvmMachine_Type_NUM 3
#define PyBobLearnLibsvmMachine_Type_TYPE PyTypeObject
#define PyBobLearnLibsvmMachine_Check_NUM 6
#define PyBobLearnLibsvmMachine_Check_NUM 4
#define PyBobLearnLibsvmMachine_Check_RET int
#define PyBobLearnLibsvmMachine_Check_PROTO (PyObject* o)
/******************************************
* Bindings for xbob.learn.libsvm.Trainer *
******************************************/
typedef struct {
PyObject_HEAD
bob::learn::libsvm::Trainer* cxx;
} PyBobLearnLibsvmTrainerObject;
#define PyBobLearnLibsvmTrainer_Type_NUM 5
#define PyBobLearnLibsvmTrainer_Type_TYPE PyTypeObject
#define PyBobLearnLibsvmTrainer_Check_NUM 6
#define PyBobLearnLibsvmTrainer_Check_RET int
#define PyBobLearnLibsvmTrainer_Check_PROTO (PyObject* o)
/* Total number of C API pointers */
#define PyXbobLearnLibsvm_API_pointers 7
......@@ -91,14 +101,18 @@ typedef struct {
* Bindings for xbob.learn.libsvm.Machine *
******************************************/
extern PyBobLearnLibsvmMachineSvmType_Type_TYPE PyBobLearnLibsvmMachineSvmType_Type;
extern PyBobLearnLibsvmMachineSvmKernelType_Type_TYPE PyBobLearnLibsvmMachineSvmKernelType_Type;
extern PyBobLearnLibsvmMachine_Type_TYPE PyBobLearnLibsvmMachine_Type;
PyBobLearnLibsvmMachine_Check_RET PyBobLearnLibsvmMachine_Check PyBobLearnLibsvmMachine_Check_PROTO;
/******************************************
* Bindings for xbob.learn.libsvm.Trainer *
******************************************/
extern PyBobLearnLibsvmTrainer_Type_TYPE PyBobLearnLibsvmTrainer_Type;
PyBobLearnLibsvmTrainer_Check_RET PyBobLearnLibsvmTrainer_Check PyBobLearnLibsvmTrainer_Check_PROTO;
#else
/* This section is used in modules that use `xbob.learn.libsvm's' C-API */
......@@ -143,14 +157,18 @@ typedef struct {
* Bindings for xbob.learn.libsvm.Machine *
******************************************/
# define PyBobLearnLibsvmMachineSvmType_Type (*(PyBobLearnLibsvmMachineSvmType_Type_TYPE *)PyXbobLearnLibsvm_API[PyBobLearnLibsvmMachineSvmType_Type_NUM])
# define PyBobLearnLibsvmMachineSvmKernelType_Type (*(PyBobLearnLibsvmMachineSvmKernelType_Type_TYPE *)PyXbobLearnLibsvm_API[PyBobLearnLibsvmMachineSvmKernelType_Type_NUM])
# define PyBobLearnLibsvmMachine_Type (*(PyBobLearnLibsvmMachine_Type_TYPE *)PyXbobLearnLibsvm_API[PyBobLearnLibsvmMachine_Type_NUM])
# define PyBobLearnLibsvmMachine_Check (*(PyBobLearnLibsvmMachine_Check_RET (*)PyBobLearnLibsvmMachine_Check_PROTO) PyXbobLearnLibsvm_API[PyBobLearnLibsvmMachine_Check_NUM])
/******************************************
* Bindings for xbob.learn.libsvm.Trainer *
******************************************/
# define PyBobLearnLibsvmTrainer_Type (*(PyBobLearnLibsvmTrainer_Type_TYPE *)PyXbobLearnLibsvm_API[PyBobLearnLibsvmTrainer_Type_NUM])
# define PyBobLearnLibsvmTrainer_Check (*(PyBobLearnLibsvmTrainer_Check_RET (*)PyBobLearnLibsvmTrainer_Check_PROTO) PyXbobLearnLibsvm_API[PyBobLearnLibsvmTrainer_Check_NUM])
# if !defined(NO_IMPORT_ARRAY)
/**
......
......@@ -39,19 +39,11 @@ static PyObject* create_module (void) {
PyBobLearnLibsvmFile_Type.tp_new = PyType_GenericNew;
if (PyType_Ready(&PyBobLearnLibsvmFile_Type) < 0) return 0;
PyBobLearnLibsvmMachineSvmType_Type.tp_new = PyType_GenericNew;
if (PyType_Ready(&PyBobLearnLibsvmMachineSvmType_Type) < 0) return 0;
PyBobLearnLibsvmMachineSvmKernelType_Type.tp_new = PyType_GenericNew;
if (PyType_Ready(&PyBobLearnLibsvmMachineSvmKernelType_Type) < 0) return 0;
PyBobLearnLibsvmMachine_Type.tp_new = PyType_GenericNew;
if (PyType_Ready(&PyBobLearnLibsvmMachine_Type) < 0) return 0;
/**
PyBobLearnLibsvmTrainer_Type.tp_new = PyType_GenericNew;
if (PyType_Ready(&PyBobLearnLibsvmTrainer_Type) < 0) return 0;
**/
# if PY_VERSION_HEX >= 0x03000000
PyObject* m = PyModule_Create(&module_definition);
......@@ -69,19 +61,11 @@ static PyObject* create_module (void) {
Py_INCREF(&PyBobLearnLibsvmFile_Type);
if (PyModule_AddObject(m, "File", (PyObject *)&PyBobLearnLibsvmFile_Type) < 0) return 0;
Py_INCREF(&PyBobLearnLibsvmMachineSvmType_Type);
if (PyModule_AddObject(m, "svm_type", (PyObject *)&PyBobLearnLibsvmMachineSvmType_Type) < 0) return 0;
Py_INCREF(&PyBobLearnLibsvmMachineSvmKernelType_Type);
if (PyModule_AddObject(m, "svm_kernel_type", (PyObject *)&PyBobLearnLibsvmMachineSvmKernelType_Type) < 0) return 0;
Py_INCREF(&PyBobLearnLibsvmMachine_Type);
if (PyModule_AddObject(m, "Machine", (PyObject *)&PyBobLearnLibsvmMachine_Type) < 0) return 0;
/**
Py_INCREF(&PyBobLearnLibsvmTrainer_Type);
if (PyModule_AddObject(m, "Trainer", (PyObject *)&PyBobLearnLibsvmTrainer_Type) < 0) return 0;
**/
static void* PyXbobLearnLibsvm_API[PyXbobLearnLibsvm_API_pointers];
......@@ -113,11 +97,9 @@ static PyObject* create_module (void) {
* Bindings for xbob.learn.libsvm.Trainer *
******************************************/
/**
PyXbobLearnLibsvm_API[PyBobLearnLibsvmTrainer_Type_NUM] = (void *)&PyBobLearnLibsvmTrainer_Type;
PyXbobLearnLibsvm_API[PyBobLearnLibsvmTrainer_Check_NUM] = (void *)&PyBobLearnLibsvmTrainer_Check;
**/
#if PY_VERSION_HEX >= 0x02070000
......
/**
* @author Andre Anjos <andre.anjos@idiap.ch>
* @date Tue 14 Jan 2014 14:26:09 CET
* @Thu 27 Mar 2014 15:44:46 CET
*
* @brief Bindings for a Bob compatible LIBSVM-based Machine for SVMs
*
* Copyright (C) 2011-2013 Idiap Research Institute, Martigny, Switzerland
* Copyright (C) 2011-2014 Idiap Research Institute, Martigny, Switzerland
*/
#define XBOB_LEARN_LIBSVM_MODULE
......@@ -14,205 +14,6 @@
#include <xbob.learn.libsvm/api.h>
#include <structmember.h>
/************************************************
* Implementation of xbob.learn.libsvm.svm_type *
************************************************/
PyDoc_STRVAR(s_svm_type_str, XBOB_EXT_MODULE_PREFIX ".svm_type");
PyDoc_STRVAR(s_svm_type_doc,
"svm_type (C++ enumeration) - cannot be instantiated from Python\n\
\n\
Available values are:\n\
\n\
* C_SVC\n\
* NU_SVC\n\
* ONE_CLASS\n\
* EPSILON_SVR\n\
* NU_SVR\n\
\n\
A dictionary containing all names and values available for this\n\
enumeration is available through the attribute ``entries``.\n\
"
);
static int insert_item_string(PyObject* dict, PyObject* entries,
const char* key, Py_ssize_t value) {
auto v = make_safe(Py_BuildValue("n", value));
if (PyDict_SetItemString(dict, key, v.get()) < 0) return -1;
return PyDict_SetItemString(entries, key, v.get());
}
static PyObject* create_svm_type_enumerations() {
auto retval = PyDict_New();
if (!retval) return 0;
auto retval_ = make_safe(retval);
auto entries = PyDict_New();
if (!entries) return 0;
auto entries_ = make_safe(entries);
if (insert_item_string(retval, entries, "C_SVC",
bob::learn::libsvm::Machine::C_SVC) < 0) return 0;
if (insert_item_string(retval, entries, "NU_SVC",
bob::learn::libsvm::Machine::NU_SVC) < 0) return 0;
if (insert_item_string(retval, entries, "ONE_CLASS",
bob::learn::libsvm::Machine::ONE_CLASS) < 0) return 0;
if (insert_item_string(retval, entries, "EPSILON_SVR",
bob::learn::libsvm::Machine::EPSILON_SVR) < 0) return 0;
if (insert_item_string(retval, entries, "NU_SVR",
bob::learn::libsvm::Machine::NU_SVR) < 0) return 0;
if (PyDict_SetItemString(retval, "entries", entries) < 0) return 0;
Py_INCREF(retval);
return retval;
}
static int PyBobLearnLibsvmMachineSvmType_Init(PyObject* self, PyObject*, PyObject*) {
PyErr_Format(PyExc_NotImplementedError, "cannot initialize C++ enumeration bindings `%s' - use one of the class' attached attributes instead", Py_TYPE(self)->tp_name);
return -1;
}
PyTypeObject PyBobLearnLibsvmMachineSvmType_Type = {
PyVarObject_HEAD_INIT(0, 0)
s_svm_type_str, /* tp_name */
sizeof(PyBobLearnLibsvmMachineSvmType_Type), /* 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 */
0, /* tp_call */
0, /* tp_str*/
0, /* tp_getattro*/
0, /* tp_setattro*/
0, /* tp_as_buffer*/
Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags*/
s_svm_type_doc, /* tp_doc */
0, /* tp_traverse */
0, /* tp_clear */
0, /* tp_richcompare */
0, /* tp_weaklistoffset */
0, /* tp_iter */
0, /* tp_iternext */
0, /* tp_methods */
0, /* tp_members */
0, /* tp_getset */
0, /* tp_base */
create_svm_type_enumerations(), /* tp_dict */
0, /* tp_descr_get */
0, /* tp_descr_set */
0, /* tp_dictoffset */
PyBobLearnLibsvmMachineSvmType_Init, /* tp_init */
0, /* tp_alloc */
0, /* tp_new */
};
/*******************************************************
* Implementation of xbob.learn.libsvm.svm_kernel_type *
*******************************************************/
PyDoc_STRVAR(s_svm_kernel_type_str, XBOB_EXT_MODULE_PREFIX ".svm_kernel_type");
PyDoc_STRVAR(s_svm_kernel_type_doc,
"svm_kernel_type (C++ enumeration) - cannot be instantiated from Python\n\
\n\
Available values are:\n\
\n\
* LINEAR\n\
* POLY\n\
* RBF\n\
* SIGMOID\n\
* PRECOMPUTED\n\
\n\
A dictionary containing all names and values available for this\n\
enumeration is available through the attribute ``entries``.\n\
"
);
static PyObject* create_svm_kernel_type_enumerations() {
auto retval = PyDict_New();
if (!retval) return 0;
auto retval_ = make_safe(retval);
auto entries = PyDict_New();
if (!entries) return 0;
auto entries_ = make_safe(entries);
if (insert_item_string(retval, entries, "LINEAR",
bob::learn::libsvm::Machine::C_SVC) < 0) return 0;
if (insert_item_string(retval, entries, "POLY",
bob::learn::libsvm::Machine::NU_SVC) < 0) return 0;
if (insert_item_string(retval, entries, "RBF",
bob::learn::libsvm::Machine::ONE_CLASS) < 0) return 0;
if (insert_item_string(retval, entries, "SIGMOID",
bob::learn::libsvm::Machine::EPSILON_SVR) < 0) return 0;
if (insert_item_string(retval, entries, "PRECOMPUTED",
bob::learn::libsvm::Machine::NU_SVR) < 0) return 0;
if (PyDict_SetItemString(retval, "entries", entries) < 0) return 0;
Py_INCREF(retval);
return retval;
}
static int PyBobLearnLibsvmMachineSvmKernelType_Init(PyObject* self, PyObject*, PyObject*) {
PyErr_Format(PyExc_NotImplementedError, "cannot initialize C++ enumeration bindings `%s' - use one of the class' attached attributes instead", Py_TYPE(self)->tp_name);
return -1;
}
PyTypeObject PyBobLearnLibsvmMachineSvmKernelType_Type = {
PyVarObject_HEAD_INIT(0, 0)
s_svm_kernel_type_str, /* tp_name */
sizeof(PyBobLearnLibsvmMachineSvmKernelType_Type), /* 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 */
0, /* tp_call */
0, /* tp_str*/
0, /* tp_getattro*/
0, /* tp_setattro*/
0, /* tp_as_buffer*/
Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags*/
s_svm_kernel_type_doc, /* tp_doc */
0, /* tp_traverse */
0, /* tp_clear */
0, /* tp_richcompare */
0, /* tp_weaklistoffset */
0, /* tp_iter */
0, /* tp_iternext */
0, /* tp_methods */
0, /* tp_members */
0, /* tp_getset */
0, /* tp_base */
create_svm_kernel_type_enumerations(), /* tp_dict */
0, /* tp_descr_get */
0, /* tp_descr_set */
0, /* tp_dictoffset */
PyBobLearnLibsvmMachineSvmKernelType_Init, /* tp_init */
0, /* tp_alloc */
0, /* tp_new */
};
/*******************************************************
* Implementation of Support Vector Machine base class *
*******************************************************/
......@@ -473,8 +274,8 @@ static PyObject* PyBobLearnLibsvmMachine_getLabels
return retval;
}
PyDoc_STRVAR(s_svm_type_attr_str, "svm_type");
PyDoc_STRVAR(s_svm_type_attr_doc, "The type of SVM machine contained");
PyDoc_STRVAR(s_svm_type_str, "svm_type");
PyDoc_STRVAR(s_svm_type_doc, "The type of SVM machine contained");
static PyObject* PyBobLearnLibsvmMachine_getSvmType
(PyBobLearnLibsvmMachineObject* self, void* /*closure*/) {
......@@ -496,8 +297,8 @@ static PyObject* PyBobLearnLibsvmMachine_getSvmType
return 0;
}
PyDoc_STRVAR(s_svm_kernel_type_attr_str, "kernel_type");
PyDoc_STRVAR(s_svm_kernel_type_attr_doc,
PyDoc_STRVAR(s_svm_kernel_type_str, "kernel_type");
PyDoc_STRVAR(s_svm_kernel_type_doc,
"The type of kernel used by the support vectors in this machine");
static PyObject* PyBobLearnLibsvmMachine_getSvmKernelType
......@@ -590,17 +391,17 @@ static PyGetSetDef PyBobLearnLibsvmMachine_getseters[] = {
0
},
{
s_svm_type_attr_str,
s_svm_type_str,
(getter)PyBobLearnLibsvmMachine_getSvmType,
0,
s_svm_type_attr_doc,
s_svm_type_doc,
0
},
{
s_svm_kernel_type_attr_str,
s_svm_kernel_type_str,
(getter)PyBobLearnLibsvmMachine_getSvmKernelType,
0,
s_svm_kernel_type_attr_doc,
s_svm_kernel_type_doc,
0
},
{
......
This diff is collapsed.
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