Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
bob.learn.em
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
bob
bob.learn.em
Commits
da50cddd
Commit
da50cddd
authored
10 years ago
by
Tiago de Freitas Pereira
Browse files
Options
Downloads
Patches
Plain Diff
Fixed some documentation issues and changed the bind of operators. Now is more clean.
parent
b6d15ad4
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
bob/learn/misc/gmm_stats.cpp
+58
-80
58 additions, 80 deletions
bob/learn/misc/gmm_stats.cpp
with
58 additions
and
80 deletions
bob/learn/misc/gmm_stats.cpp
+
58
−
80
View file @
da50cddd
...
...
@@ -33,18 +33,32 @@ static auto GMMStats_doc = bob::extension::ClassDoc(
.
add_prototype
(
"hdf5"
)
.
add_prototype
(
""
)
//.add_parameter("mean", "array_like<double, 1D>", "Mean of the Gaussian")
.
add_parameter
(
"n_gaussians"
,
"int"
,
"Number of gaussians"
)
.
add_parameter
(
"n_inputs"
,
"int"
,
"Dimension of the feature vector"
)
.
add_parameter
(
"other"
,
":py:class:`bob.learn.misc.GMMStats`"
,
"A GMMStats object to be copied."
)
.
add_parameter
(
"hdf5"
,
":py:class:`bob.io.base.HDF5File`"
,
"An HDF5 file open for reading"
)
);
static
int
PyBobLearnMiscGMMStats_init_number
(
PyBobLearnMiscGMMStatsObject
*
self
,
PyObject
*
args
,
PyObject
*
kwargs
)
{
char
**
kwlist
=
GMMStats_doc
.
kwlist
(
0
);
size_
t
n_inputs
=
1
;
size_
t
n_gaussians
=
1
;
in
t
n_inputs
=
1
;
in
t
n_gaussians
=
1
;
//Parsing the input argments
if
(
!
PyArg_ParseTupleAndKeywords
(
args
,
kwargs
,
"II"
,
kwlist
,
&
n_gaussians
,
&
n_inputs
))
if
(
!
PyArg_ParseTupleAndKeywords
(
args
,
kwargs
,
"ii"
,
kwlist
,
&
n_gaussians
,
&
n_inputs
))
return
-
1
;
if
(
n_gaussians
<
0
){
PyErr_Format
(
PyExc_TypeError
,
"gaussians argument must be greater than or equal to zero"
);
return
-
1
;
}
if
(
n_inputs
<
0
){
PyErr_Format
(
PyExc_TypeError
,
"input argument must be greater than or equal to zero"
);
return
-
1
;
}
self
->
cxx
.
reset
(
new
bob
::
learn
::
misc
::
GMMStats
(
n_gaussians
,
n_inputs
));
return
0
;
...
...
@@ -55,7 +69,7 @@ static int PyBobLearnMiscGMMStats_init_copy(PyBobLearnMiscGMMStatsObject* self,
char
**
kwlist
=
GMMStats_doc
.
kwlist
(
1
);
PyBobLearnMiscGMMStatsObject
*
tt
;
if
(
!
PyArg_ParseTupleAndKeywords
(
args
,
kwargs
,
"O
&
"
,
kwlist
,
&
PyBobLearnMiscGMMStats_Type
,
&
tt
))
return
-
1
;
if
(
!
PyArg_ParseTupleAndKeywords
(
args
,
kwargs
,
"O
!
"
,
kwlist
,
&
PyBobLearnMiscGMMStats_Type
,
&
tt
))
return
-
1
;
self
->
cxx
.
reset
(
new
bob
::
learn
::
misc
::
GMMStats
(
*
tt
->
cxx
));
return
0
;
...
...
@@ -67,7 +81,7 @@ static int PyBobLearnMiscGMMStats_init_hdf5(PyBobLearnMiscGMMStatsObject* self,
char
**
kwlist
=
GMMStats_doc
.
kwlist
(
2
);
PyBobIoHDF5FileObject
*
config
=
0
;
if
(
!
PyArg_ParseTupleAndKeywords
(
args
,
kwargs
,
"O&"
,
kwlist
,
&
PyBobIoHDF5File_Converter
,
&
config
))
if
(
!
PyArg_ParseTupleAndKeywords
(
args
,
kwargs
,
"O&"
,
kwlist
,
&
PyBobIoHDF5File_Converter
,
&
config
))
return
-
1
;
try
{
...
...
@@ -99,7 +113,6 @@ static int PyBobLearnMiscGMMStats_init(PyBobLearnMiscGMMStatsObject* self, PyObj
self
->
cxx
.
reset
(
new
bob
::
learn
::
misc
::
GMMStats
());
case
1
:{
//Reading the input argument
PyObject
*
arg
=
0
;
if
(
PyTuple_Size
(
args
))
...
...
@@ -115,7 +128,7 @@ static int PyBobLearnMiscGMMStats_init(PyBobLearnMiscGMMStatsObject* self, PyObj
return
PyBobLearnMiscGMMStats_init_copy
(
self
,
args
,
kwargs
);
/**If the constructor input is a HDF5**/
else
if
(
PyBobIoHDF5File_Check
(
arg
))
return
PyBobLearnMiscGMMStats_init_hdf5
(
self
,
args
,
kwargs
);
return
PyBobLearnMiscGMMStats_init_hdf5
(
self
,
args
,
kwargs
);
}
case
2
:
return
PyBobLearnMiscGMMStats_init_number
(
self
,
args
,
kwargs
);
...
...
@@ -166,8 +179,9 @@ int PyBobLearnMiscGMMStats_Check(PyObject* o) {
/***** n *****/
static
auto
n
=
bob
::
extension
::
VariableDoc
(
"n"
,
"array_like <double, 1D>"
,
"For each Gaussian, the accumulated sum of responsibilities, i.e. the sum of P(gaussian_i|x)"
"array_like <double, 1D> "
"For each Gaussian, the accumulated sum of responsibilities, i.e. the sum of P(gaussian_i|x)"
,
""
);
PyObject
*
PyBobLearnMiscGMMStats_getN
(
PyBobLearnMiscGMMStatsObject
*
self
,
void
*
){
BOB_TRY
...
...
@@ -193,8 +207,9 @@ int PyBobLearnMiscGMMStats_setN(PyBobLearnMiscGMMStatsObject* self, PyObject* va
/***** sum_px *****/
static
auto
sum_px
=
bob
::
extension
::
VariableDoc
(
"sum_px"
,
"array_like <double, 2D>"
,
"For each Gaussian, the accumulated sum of responsibility times the sample"
"array_like <double, 2D> "
"For each Gaussian, the accumulated sum of responsibility times the sample"
,
""
);
PyObject
*
PyBobLearnMiscGMMStats_getSum_px
(
PyBobLearnMiscGMMStatsObject
*
self
,
void
*
){
BOB_TRY
...
...
@@ -220,8 +235,9 @@ int PyBobLearnMiscGMMStats_setSum_px(PyBobLearnMiscGMMStatsObject* self, PyObjec
/***** sum_pxx *****/
static
auto
sum_pxx
=
bob
::
extension
::
VariableDoc
(
"sum_pxx"
,
"array_like <double, 2D>"
,
"For each Gaussian, the accumulated sum of responsibility times the sample squared"
"array_like <double, 2D> "
"For each Gaussian, the accumulated sum of responsibility times the sample squared"
,
""
);
PyObject
*
PyBobLearnMiscGMMStats_getSum_pxx
(
PyBobLearnMiscGMMStatsObject
*
self
,
void
*
){
BOB_TRY
...
...
@@ -247,8 +263,9 @@ int PyBobLearnMiscGMMStats_setSum_pxx(PyBobLearnMiscGMMStatsObject* self, PyObje
/***** t *****/
static
auto
t
=
bob
::
extension
::
VariableDoc
(
"t"
,
"size_t"
,
"The accumulated log likelihood of all samples"
"int "
"The accumulated log likelihood of all samples"
,
""
);
PyObject
*
PyBobLearnMiscGMMStats_getT
(
PyBobLearnMiscGMMStatsObject
*
self
,
void
*
){
BOB_TRY
...
...
@@ -277,8 +294,9 @@ int PyBobLearnMiscGMMStats_setT(PyBobLearnMiscGMMStatsObject* self, PyObject* va
/***** log_likelihood *****/
static
auto
log_likelihood
=
bob
::
extension
::
VariableDoc
(
"log_likelihood"
,
"double"
,
"The accumulated log likelihood of all samples"
"double "
"The accumulated log likelihood of all samples"
,
""
);
PyObject
*
PyBobLearnMiscGMMStats_getLog_likelihood
(
PyBobLearnMiscGMMStatsObject
*
self
,
void
*
){
BOB_TRY
...
...
@@ -387,7 +405,9 @@ static auto load = bob::extension::FunctionDoc(
" Load the configuration of the GMMStats to a given HDF5 file"
,
0
,
true
);
)
.
add_prototype
(
"hdf5"
)
.
add_parameter
(
"hdf5"
,
":py:class:`bob.io.base.HDF5File`"
,
"An HDF5 file open for reading"
);
static
PyObject
*
PyBobLearnMiscGMMStats_Load
(
PyBobLearnMiscGMMStatsObject
*
self
,
PyObject
*
f
)
{
if
(
!
PyBobIoHDF5File_Check
(
f
))
{
...
...
@@ -425,7 +445,7 @@ static auto is_similar_to = bob::extension::FunctionDoc(
true
)
.
add_prototype
(
"other, [r_epsilon], [a_epsilon]"
,
"bool"
)
.
add_parameter
(
"other"
,
":py:class:`bob.learn.misc.GMMStats`"
,
"A
gaussian
to be compared."
)
.
add_parameter
(
"other"
,
":py:class:`bob.learn.misc.GMMStats`"
,
"A
GMMStats object
to be compared."
)
.
add_parameter
(
"[r_epsilon]"
,
"float"
,
"Relative precision."
)
.
add_parameter
(
"[a_epsilon]"
,
"float"
,
"Absolute precision."
)
.
add_return
(
"bool"
,
""
,
""
);
...
...
@@ -454,21 +474,22 @@ static PyObject* PyBobLearnMiscGMMStats_IsSimilarTo(PyBobLearnMiscGMMStatsObject
/*** resize ***/
static
auto
resize
=
bob
::
extension
::
FunctionDoc
(
"resize"
,
"
(size_t,size_t)"
"
Allocates space for the statistics and resets to zero.
"
"
Allocates space for the statistics and resets to zero."
,
""
)
.
add_prototype
(
"n_gaussians,n_inputs"
)
.
add_parameter
(
"n_gaussians,n_inputs"
,
"(size_t, size_t)"
,
"Tuple with the new shape"
);
.
add_prototype
(
"n_gaussians,n_inputs"
,
""
)
.
add_parameter
(
"n_gaussians"
,
"int"
,
"Number of gaussians"
)
.
add_parameter
(
"n_inputs"
,
"int"
,
"Dimensionality of the feature vector"
);
static
PyObject
*
PyBobLearnMiscGMMStats_resize
(
PyBobLearnMiscGMMStatsObject
*
self
,
PyObject
*
args
,
PyObject
*
kwargs
)
{
BOB_TRY
/* Parses input arguments in a single shot */
char
**
kwlist
=
resize
.
kwlist
(
0
);
Py_ssize_
t
n_gaussians
=
0
;
Py_ssize_
t
n_inputs
=
0
;
in
t
n_gaussians
=
0
;
in
t
n_inputs
=
0
;
if
(
!
PyArg_ParseTupleAndKeywords
(
args
,
kwargs
,
"
nn
"
,
kwlist
,
&
n_gaussians
,
&
n_inputs
))
Py_RETURN_NONE
;
if
(
!
PyArg_ParseTupleAndKeywords
(
args
,
kwargs
,
"
ii
"
,
kwlist
,
&
n_gaussians
,
&
n_inputs
))
Py_RETURN_NONE
;
self
->
cxx
->
resize
(
n_gaussians
,
n_inputs
);
BOB_CATCH_MEMBER
(
"cannot perform the resize method"
,
0
)
...
...
@@ -480,9 +501,10 @@ static PyObject* PyBobLearnMiscGMMStats_resize(PyBobLearnMiscGMMStatsObject* sel
/*** init ***/
static
auto
init
=
bob
::
extension
::
FunctionDoc
(
"init"
,
" Resets statistics to zero."
,
""
" Resets statistics to zero."
);
)
.
add_prototype
(
""
,
""
);
static
PyObject
*
PyBobLearnMiscGMMStats_init_method
(
PyBobLearnMiscGMMStatsObject
*
self
)
{
BOB_TRY
...
...
@@ -505,7 +527,7 @@ static PyMethodDef PyBobLearnMiscGMMStats_methods[] = {
{
load
.
name
(),
(
PyCFunction
)
PyBobLearnMiscGMMStats_Load
,
METH_
VARARGS
|
METH_KEYWORDS
,
METH_
O
,
load
.
doc
()
},
{
...
...
@@ -523,7 +545,7 @@ static PyMethodDef PyBobLearnMiscGMMStats_methods[] = {
{
init
.
name
(),
(
PyCFunction
)
PyBobLearnMiscGMMStats_init_method
,
METH_
VARARGS
|
METH_KEYWORD
S
,
METH_
NOARG
S
,
init
.
doc
()
},
...
...
@@ -554,54 +576,7 @@ static PyObject* PyBobLearnMiscGMMStats_inplaceadd(PyObject* self, PyObject* oth
return
self
;
}
static
PyNumberMethods
PyBobLearnMiscGMMStats_operators
[]
=
{{
0
,
// nb_add;
0
,
// nb_subtract;
0
,
// nb_multiply;
0
,
// nb_divide;
0
,
// nb_remainder;
0
,
// nb_divmod;
0
,
// nb_power;
0
,
// nb_negative;
0
,
// nb_positive;
0
,
// nb_absolute;
0
,
// nb_nonzero; /* Used by PyObject_IsTrue */
0
,
// nb_invert;
0
,
// nb_lshift;
0
,
// nb_rshift;
0
,
// nb_and;
0
,
// nb_xor;
0
,
// nb_or;
0
,
// nb_coerce; /* Used by the coerce() function */
0
,
// nb_int;
0
,
// nb_long;
0
,
// nb_float;
0
,
// nb_oct;
0
,
// nb_hex;
/* Added in release 2.0 */
PyBobLearnMiscGMMStats_inplaceadd
,
// nb_inplace_add;
0
,
// nb_inplace_subtract;
0
,
// nb_inplace_multiply;
0
,
// nb_inplace_divide;
0
,
// nb_inplace_remainder;
0
,
// nb_inplace_power;
0
,
// nb_inplace_lshift;
0
,
// nb_inplace_rshift;
0
,
// nb_inplace_and;
0
,
// nb_inplace_xor;
0
,
// nb_inplace_or;
/* Added in release 2.2 */
0
,
// nb_floor_divide;
0
,
// nb_true_divide;
0
,
// nb_inplace_floor_divide;
0
,
// nb_inplace_true_divide;
/* Added in release 2.5 */
0
,
// nb_index
}};
static
PyNumberMethods
PyBobLearnMiscGMMStats_operators
=
{
0
};
/******************************************************************/
/************ Module Section **************************************/
...
...
@@ -629,7 +604,10 @@ bool init_BobLearnMiscGMMStats(PyObject* module)
PyBobLearnMiscGMMStats_Type
.
tp_methods
=
PyBobLearnMiscGMMStats_methods
;
PyBobLearnMiscGMMStats_Type
.
tp_getset
=
PyBobLearnMiscGMMStats_getseters
;
//PyBobLearnMiscGMMStats_Type.tp_call = reinterpret_cast<ternaryfunc>(PyBobLearnMiscGMMStats_loglikelihood);
PyBobLearnMiscGMMStats_Type
.
tp_as_number
=
PyBobLearnMiscGMMStats_operators
;
PyBobLearnMiscGMMStats_Type
.
tp_as_number
=
&
PyBobLearnMiscGMMStats_operators
;
//set operators
PyBobLearnMiscGMMStats_operators
.
nb_inplace_add
=
PyBobLearnMiscGMMStats_inplaceadd
;
// check that everything is fine
if
(
PyType_Ready
(
&
PyBobLearnMiscGMMStats_Type
)
<
0
)
return
false
;
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment