Skip to content

Commit

Permalink
Added more tests with blitz arrays
Browse files Browse the repository at this point in the history
  • Loading branch information
tiagofrepereira2012 committed Mar 4, 2015
1 parent d95e400 commit 2601b11
Show file tree
Hide file tree
Showing 10 changed files with 23 additions and 21 deletions.
4 changes: 2 additions & 2 deletions bob/learn/em/MAP_gmm_trainer.cpp
Expand Up @@ -185,7 +185,7 @@ PyObject* PyBobLearnEMMAPGMMTrainer_getRelevanceFactor(PyBobLearnEMMAPGMMTrainer
int PyBobLearnEMMAPGMMTrainer_setRelevanceFactor(PyBobLearnEMMAPGMMTrainerObject* self, PyObject* value, void*){
BOB_TRY

if(!PyNumber_Check(value)){
if(!PyBob_NumberCheck(value)){
PyErr_Format(PyExc_RuntimeError, "%s %s expects a double", Py_TYPE(self)->tp_name, relevance_factor.name());
return -1;
}
Expand All @@ -211,7 +211,7 @@ PyObject* PyBobLearnEMMAPGMMTrainer_getAlpha(PyBobLearnEMMAPGMMTrainerObject* se
int PyBobLearnEMMAPGMMTrainer_setAlpha(PyBobLearnEMMAPGMMTrainerObject* self, PyObject* value, void*){
BOB_TRY

if(!PyNumber_Check(value)){
if(!PyBob_NumberCheck(value)){
PyErr_Format(PyExc_RuntimeError, "%s %s expects a double", Py_TYPE(self)->tp_name, alpha.name());
return -1;
}
Expand Down
4 changes: 4 additions & 0 deletions bob/learn/em/cpp/MAP_GMMTrainer.cpp
Expand Up @@ -75,6 +75,10 @@ void bob::learn::em::MAP_GMMTrainer::mStep(bob::learn::em::GMMMachine& gmm)
{
// Read options and variables
double n_gaussians = gmm.getNGaussians();

//Checking if it is necessary to resize the cache
if((size_t)m_cache_alpha.extent(0) != n_gaussians)
initialize(gmm); //If it is different for some reason, there is no way, you have to initialize

// Check that the prior GMM has been specified
if (!m_prior_gmm)
Expand Down
13 changes: 4 additions & 9 deletions bob/learn/em/cpp/ML_GMMTrainer.cpp
Expand Up @@ -41,6 +41,10 @@ void bob::learn::em::ML_GMMTrainer::mStep(bob::learn::em::GMMMachine& gmm)
// Read options and variables
const size_t n_gaussians = gmm.getNGaussians();

//Checking if it is necessary to resize the cache
if((size_t)m_cache_ss_n_thresholded.extent(0) != n_gaussians)
initialize(gmm); //If it is different for some reason, there is no way, you have to initialize

// - Update weights if requested
// Equation 9.26 of Bishop, "Pattern recognition and machine learning", 2006
if (m_gmm_base_trainer.getUpdateWeights()) {
Expand Down Expand Up @@ -101,12 +105,3 @@ bool bob::learn::em::ML_GMMTrainer::operator!=
{
return !(this->operator==(other));
}

/*
bool bob::learn::em::ML_GMMTrainer::is_similar_to
(const bob::learn::em::ML_GMMTrainer &other, const double r_epsilon,
const double a_epsilon) const
{
return m_gmm_base_trainer.is_similar_to(other, r_epsilon, a_epsilon);
}
*/
2 changes: 1 addition & 1 deletion bob/learn/em/gaussian.cpp
Expand Up @@ -105,7 +105,7 @@ static int PyBobLearnEMGaussian_init(PyBobLearnEMGaussianObject* self, PyObject*
}

/**If the constructor input is a number**/
if (PyNumber_Check(arg))
if (PyBob_NumberCheck(arg))
return PyBobLearnEMGaussian_init_number(self, args, kwargs);
/**If the constructor input is Gaussian object**/
else if (PyBobLearnEMGaussian_Check(arg))
Expand Down
2 changes: 1 addition & 1 deletion bob/learn/em/gmm_stats.cpp
Expand Up @@ -350,7 +350,7 @@ PyObject* PyBobLearnEMGMMStats_getLog_likelihood(PyBobLearnEMGMMStatsObject* sel
int PyBobLearnEMGMMStats_setLog_likelihood(PyBobLearnEMGMMStatsObject* self, PyObject* value, void*){
BOB_TRY

if (!PyNumber_Check(value)){
if (!PyBob_NumberCheck(value)){
PyErr_Format(PyExc_RuntimeError, "%s %s expects an double", Py_TYPE(self)->tp_name, t.name());
return -1;
}
Expand Down
2 changes: 1 addition & 1 deletion bob/learn/em/ivector_machine.cpp
Expand Up @@ -270,7 +270,7 @@ PyObject* PyBobLearnEMIVectorMachine_getVarianceThreshold(PyBobLearnEMIVectorMac
int PyBobLearnEMIVectorMachine_setVarianceThreshold(PyBobLearnEMIVectorMachineObject* self, PyObject* value, void*){
BOB_TRY

if (!PyNumber_Check(value)){
if (!PyBob_NumberCheck(value)){
PyErr_Format(PyExc_RuntimeError, "%s %s expects an double", Py_TYPE(self)->tp_name, variance_threshold.name());
return -1;
}
Expand Down
9 changes: 6 additions & 3 deletions bob/learn/em/kmeans_trainer.cpp
Expand Up @@ -49,7 +49,7 @@ static auto KMeansTrainer_doc = bob::extension::ClassDoc(
.add_prototype("other","")
.add_prototype("","")

.add_parameter("initialization_method", "str", "The initialization method of the means")
.add_parameter("initialization_method", "str", "The initialization method of the means.\nPossible values are: 'RANDOM', 'RANDOM_NO_DUPLICATE', 'KMEANS_PLUS_PLUS' ")
.add_parameter("other", ":py:class:`bob.learn.em.KMeansTrainer`", "A KMeansTrainer object to be copied.")

);
Expand Down Expand Up @@ -162,7 +162,10 @@ static auto initialization_method = bob::extension::VariableDoc(
"initialization_method",
"str",
"Initialization method.",
""
"Possible values:\n"
" `RANDOM`: Random initialization \n\n"
" `RANDOM_NO_DUPLICATE`: Random initialization without repetition \n\n"
" `KMEANS_PLUS_PLUS`: Apply the kmeans++ initialization http://en.wikipedia.org/wiki/K-means%2B%2B \n\n"
);
PyObject* PyBobLearnEMKMeansTrainer_getInitializationMethod(PyBobLearnEMKMeansTrainerObject* self, void*) {
BOB_TRY
Expand Down Expand Up @@ -254,7 +257,7 @@ PyObject* PyBobLearnEMKMeansTrainer_getAverageMinDistance(PyBobLearnEMKMeansTrai
int PyBobLearnEMKMeansTrainer_setAverageMinDistance(PyBobLearnEMKMeansTrainerObject* self, PyObject* value, void*) {
BOB_TRY

if (!PyNumber_Check(value)){
if (!PyBob_NumberCheck(value)){
PyErr_Format(PyExc_RuntimeError, "%s %s expects an double", Py_TYPE(self)->tp_name, average_min_distance.name());
return -1;
}
Expand Down
2 changes: 1 addition & 1 deletion bob/learn/em/plda_base.cpp
Expand Up @@ -397,7 +397,7 @@ static PyObject* PyBobLearnEMPLDABase_getVarianceThreshold(PyBobLearnEMPLDABaseO
int PyBobLearnEMPLDABase_setVarianceThreshold(PyBobLearnEMPLDABaseObject* self, PyObject* value, void*){
BOB_TRY

if (!PyNumber_Check(value)){
if (!PyBob_NumberCheck(value)){
PyErr_Format(PyExc_RuntimeError, "%s %s expects an float", Py_TYPE(self)->tp_name, variance_threshold.name());
return -1;
}
Expand Down
4 changes: 2 additions & 2 deletions bob/learn/em/plda_machine.cpp
Expand Up @@ -220,7 +220,7 @@ static PyObject* PyBobLearnEMPLDAMachine_getWSumXitBetaXi(PyBobLearnEMPLDAMachin
int PyBobLearnEMPLDAMachine_setWSumXitBetaXi(PyBobLearnEMPLDAMachineObject* self, PyObject* value, void*){
BOB_TRY

if (!PyNumber_Check(value)){
if (!PyBob_NumberCheck(value)){
PyErr_Format(PyExc_RuntimeError, "%s %s expects an float", Py_TYPE(self)->tp_name, w_sum_xit_beta_xi.name());
return -1;
}
Expand Down Expand Up @@ -312,7 +312,7 @@ static PyObject* PyBobLearnEMPLDAMachine_getLogLikelihood(PyBobLearnEMPLDAMachin
int PyBobLearnEMPLDAMachine_setLogLikelihood(PyBobLearnEMPLDAMachineObject* self, PyObject* value, void*){
BOB_TRY

if (!PyNumber_Check(value)){
if (!PyBob_NumberCheck(value)){
PyErr_Format(PyExc_RuntimeError, "%s %s expects an double", Py_TYPE(self)->tp_name, log_likelihood.name());
return -1;
}
Expand Down
2 changes: 1 addition & 1 deletion version.txt
@@ -1 +1 @@
2.0.0b3
2.0.0b6

0 comments on commit 2601b11

Please sign in to comment.