plda_base.cpp 33.9 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
/**
 * @date Thu Jan 29 15:44:15 2015 +0200
 * @author Tiago de Freitas Pereira <tiago.pereira@idiap.ch>
 *
 * @brief Python API for bob::learn::em
 *
 * Copyright (C) 2011-2014 Idiap Research Institute, Martigny, Switzerland
 */

#include "main.h"

/******************************************************************/
/************ Constructor Section *********************************/
/******************************************************************/

static auto PLDABase_doc = bob::extension::ClassDoc(
  BOB_EXT_MODULE_PREFIX ".PLDABase",

  "This class is a container for the :math:`F` (between class variantion matrix), :math:`G` (within class variantion matrix) and :math:`\\Sigma` "
  "matrices and the mean vector :math:`\\mu` of a PLDA model. This also"
  "precomputes useful matrices to make the model scalable."
  "References: [ElShafey2014,PrinceElder2007,LiFu2012]",
  ""
).add_constructor(
  bob::extension::FunctionDoc(
    "__init__",

     "Constructor, builds a new PLDABase. :math:`F`, :math:`G` "
     "and :math:`\\Sigma` are initialized to the 'eye' matrix (matrix with 1's "
     "on the diagonal and 0 outside), and :math:`\\mu` is initialized to 0.",

    "",
    true
  )
  .add_prototype("dim_d,dim_f,dim_g,variance_threshold","")
  .add_prototype("other","")
  .add_prototype("hdf5","")

39
40
41
  .add_parameter("dim_d", "int", "Dimensionality of the feature vector.")
  .add_parameter("dim_f", "int", "Size of :math:`F` (between class variantion matrix).")
  .add_parameter("dim_g", "int", "Size of :math:`G` (within class variantion matrix).")
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
  .add_parameter("variance_threshold", "double", "The smallest possible value of the variance (Ignored if set to 0.)")
  
  .add_parameter("other", ":py:class:`bob.learn.em.PLDABase`", "A PLDABase object to be copied.")
  .add_parameter("hdf5", ":py:class:`bob.io.base.HDF5File`", "An HDF5 file open for reading")

);


static int PyBobLearnEMPLDABase_init_copy(PyBobLearnEMPLDABaseObject* self, PyObject* args, PyObject* kwargs) {

  char** kwlist = PLDABase_doc.kwlist(1);
  PyBobLearnEMPLDABaseObject* o;
  if (!PyArg_ParseTupleAndKeywords(args, kwargs, "O!", kwlist, &PyBobLearnEMPLDABase_Type, &o)){
    PLDABase_doc.print_usage();
    return -1;
  }

  self->cxx.reset(new bob::learn::em::PLDABase(*o->cxx));
  return 0;
}


static int PyBobLearnEMPLDABase_init_hdf5(PyBobLearnEMPLDABaseObject* self, PyObject* args, PyObject* kwargs) {

  char** kwlist = PLDABase_doc.kwlist(2);

  PyBobIoHDF5FileObject* config = 0;
  if (!PyArg_ParseTupleAndKeywords(args, kwargs, "O&", kwlist, &PyBobIoHDF5File_Converter, &config)){
    PLDABase_doc.print_usage();
    return -1;
  }
73
  auto config_ = make_safe(config);
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
  self->cxx.reset(new bob::learn::em::PLDABase(*(config->f)));

  return 0;
}


static int PyBobLearnEMPLDABase_init_dim(PyBobLearnEMPLDABaseObject* self, PyObject* args, PyObject* kwargs) {

  char** kwlist = PLDABase_doc.kwlist(0);
  
  int dim_D, dim_F, dim_G = 1;
  double variance_threshold = 0.0;

  //Here we have to select which keyword argument to read  
  if (!PyArg_ParseTupleAndKeywords(args, kwargs, "iii|d", kwlist, &dim_D, &dim_F, &dim_G, &variance_threshold)){
    PLDABase_doc.print_usage();
    return -1;
  }
  
  if(dim_D <= 0){
    PyErr_Format(PyExc_TypeError, "dim_D argument must be greater than or equal to one");
    return -1;
  }
  
  if(dim_F <= 0){
    PyErr_Format(PyExc_TypeError, "dim_F argument must be greater than or equal to one");
    return -1;
  }

  if(dim_G <= 0){
    PyErr_Format(PyExc_TypeError, "dim_G argument must be greater than or equal to one");
    return -1;
  }

  if(variance_threshold < 0){
    PyErr_Format(PyExc_TypeError, "variance_threshold argument must be greater than or equal to zero");
    return -1;
  }

  
  self->cxx.reset(new bob::learn::em::PLDABase(dim_D, dim_F, dim_G, variance_threshold));
  return 0;
}

static int PyBobLearnEMPLDABase_init(PyBobLearnEMPLDABaseObject* self, PyObject* args, PyObject* kwargs) {
  BOB_TRY

  // get the number of command line arguments
  int nargs = (args?PyTuple_Size(args):0) + (kwargs?PyDict_Size(kwargs):0);

  if(nargs==1){
    //Reading the input argument
    PyObject* arg = 0;
    if (PyTuple_Size(args))
      arg = PyTuple_GET_ITEM(args, 0);
    else {
      PyObject* tmp = PyDict_Values(kwargs);
      auto tmp_ = make_safe(tmp);
      arg = PyList_GET_ITEM(tmp, 0);
    }

    // If the constructor input is Gaussian object
    if (PyBobLearnEMPLDABase_Check(arg))
      return PyBobLearnEMPLDABase_init_copy(self, args, kwargs);
    // If the constructor input is a HDF5
    else if (PyBobIoHDF5File_Check(arg))
      return PyBobLearnEMPLDABase_init_hdf5(self, args, kwargs);
  }
  else if((nargs==3)||(nargs==4))
    return PyBobLearnEMPLDABase_init_dim(self, args, kwargs);
  else{
    PyErr_Format(PyExc_RuntimeError, "number of arguments mismatch - %s requires 1, 3 or 4 arguments, but you provided %d (see help)", Py_TYPE(self)->tp_name, nargs);
    PLDABase_doc.print_usage();
    return -1;
  }
  BOB_CATCH_MEMBER("cannot create PLDABase", 0)
  return 0;
}



static void PyBobLearnEMPLDABase_delete(PyBobLearnEMPLDABaseObject* self) {
  self->cxx.reset();
  Py_TYPE(self)->tp_free((PyObject*)self);
}

static PyObject* PyBobLearnEMPLDABase_RichCompare(PyBobLearnEMPLDABaseObject* self, PyObject* other, int op) {
  BOB_TRY

  if (!PyBobLearnEMPLDABase_Check(other)) {
    PyErr_Format(PyExc_TypeError, "cannot compare `%s' with `%s'", Py_TYPE(self)->tp_name, Py_TYPE(other)->tp_name);
    return 0;
  }
  auto other_ = reinterpret_cast<PyBobLearnEMPLDABaseObject*>(other);
  switch (op) {
    case Py_EQ:
      if (*self->cxx==*other_->cxx) Py_RETURN_TRUE; else Py_RETURN_FALSE;
    case Py_NE:
      if (*self->cxx==*other_->cxx) Py_RETURN_FALSE; else Py_RETURN_TRUE;
    default:
      Py_INCREF(Py_NotImplemented);
      return Py_NotImplemented;
  }
  BOB_CATCH_MEMBER("cannot compare PLDABase objects", 0)
}

int PyBobLearnEMPLDABase_Check(PyObject* o) {
  return PyObject_IsInstance(o, reinterpret_cast<PyObject*>(&PyBobLearnEMPLDABase_Type));
}


/******************************************************************/
/************ Variables Section ***********************************/
/******************************************************************/

/***** shape *****/
static auto shape = bob::extension::VariableDoc(
  "shape",
  "(int,int, int)",
193
  "A tuple that represents the dimensionality of the feature vector dim_d, the :math:`F` matrix and the :math:`G` matrix.",
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
  ""
);
PyObject* PyBobLearnEMPLDABase_getShape(PyBobLearnEMPLDABaseObject* self, void*) {
  BOB_TRY
  return Py_BuildValue("(i,i,i)", self->cxx->getDimD(), self->cxx->getDimF(), self->cxx->getDimG());
  BOB_CATCH_MEMBER("shape could not be read", 0)
}


/***** F *****/
static auto F = bob::extension::VariableDoc(
  "f",
  "array_like <float, 2D>",
  "Returns the :math:`F` matrix (between class variantion matrix)",
  ""
);
PyObject* PyBobLearnEMPLDABase_getF(PyBobLearnEMPLDABaseObject* self, void*){
  BOB_TRY
  return PyBlitzArrayCxx_AsConstNumpy(self->cxx->getF());
  BOB_CATCH_MEMBER("`f` could not be read", 0)
}
int PyBobLearnEMPLDABase_setF(PyBobLearnEMPLDABaseObject* self, PyObject* value, void*){
  BOB_TRY
  PyBlitzArrayObject* o;
  if (!PyBlitzArray_Converter(value, &o)){
    PyErr_Format(PyExc_RuntimeError, "%s %s expects a 2D array of floats", Py_TYPE(self)->tp_name, F.name());
    return -1;
  }
  auto o_ = make_safe(o);
  auto b = PyBlitzArrayCxx_AsBlitz<double,2>(o, "f");
  if (!b) return -1;
  self->cxx->setF(*b);
  return 0;
  BOB_CATCH_MEMBER("`f` vector could not be set", -1)
}

/***** G *****/
static auto G = bob::extension::VariableDoc(
  "g",
  "array_like <float, 2D>",
  "Returns the :math:`G` matrix (between class variantion matrix)",
  ""
);
PyObject* PyBobLearnEMPLDABase_getG(PyBobLearnEMPLDABaseObject* self, void*){
  BOB_TRY
  return PyBlitzArrayCxx_AsConstNumpy(self->cxx->getG());
  BOB_CATCH_MEMBER("`g` could not be read", 0)
}
int PyBobLearnEMPLDABase_setG(PyBobLearnEMPLDABaseObject* self, PyObject* value, void*){
  BOB_TRY
  PyBlitzArrayObject* o;
  if (!PyBlitzArray_Converter(value, &o)){
    PyErr_Format(PyExc_RuntimeError, "%s %s expects a 2D array of floats", Py_TYPE(self)->tp_name, G.name());
    return -1;
  }
  auto o_ = make_safe(o);
  auto b = PyBlitzArrayCxx_AsBlitz<double,2>(o, "g");
  if (!b) return -1;
  self->cxx->setG(*b);
  return 0;
  BOB_CATCH_MEMBER("`g` vector could not be set", -1)
}


/***** mu *****/
static auto mu = bob::extension::VariableDoc(
  "mu",
  "array_like <float, 1D>",
262
  "Gets the :math:`\\mu` mean vector of the PLDA model",
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
  ""
);
PyObject* PyBobLearnEMPLDABase_getMu(PyBobLearnEMPLDABaseObject* self, void*){
  BOB_TRY
  return PyBlitzArrayCxx_AsConstNumpy(self->cxx->getMu());
  BOB_CATCH_MEMBER("`mu` could not be read", 0)
}
int PyBobLearnEMPLDABase_setMu(PyBobLearnEMPLDABaseObject* self, PyObject* value, void*){
  BOB_TRY
  PyBlitzArrayObject* o;
  if (!PyBlitzArray_Converter(value, &o)){
    PyErr_Format(PyExc_RuntimeError, "%s %s expects a 2D array of floats", Py_TYPE(self)->tp_name, mu.name());
    return -1;
  }
  auto o_ = make_safe(o);
  auto b = PyBlitzArrayCxx_AsBlitz<double,1>(o, "mu");
  if (!b) return -1;
  self->cxx->setMu(*b);
  return 0;
  BOB_CATCH_MEMBER("`mu` vector could not be set", -1)
}


/***** __isigma__ *****/
static auto __isigma__ = bob::extension::VariableDoc(
  "__isigma__",
  "array_like <float, 1D>",
  "Gets the inverse vector/diagonal matrix of :math:`\\Sigma^{-1}`",
  ""
);
static PyObject* PyBobLearnEMPLDABase_getISigma(PyBobLearnEMPLDABaseObject* self, PyObject* args, PyObject* kwargs) {
  BOB_TRY
  return PyBlitzArrayCxx_AsConstNumpy(self->cxx->getISigma());
  BOB_CATCH_MEMBER("__isigma__ could not be read", 0)
}


/***** __alpha__ *****/
static auto __alpha__ = bob::extension::VariableDoc(
  "__alpha__",
  "array_like <float, 2D>",
  "Gets the \f$\alpha\f$ matrix."
  ":math:`\\alpha = (Id + G^T \\Sigma^{-1} G)^{-1} = \\mathcal{G}`",
  ""
);
static PyObject* PyBobLearnEMPLDABase_getAlpha(PyBobLearnEMPLDABaseObject* self, PyObject* args, PyObject* kwargs) {
  BOB_TRY
  return PyBlitzArrayCxx_AsConstNumpy(self->cxx->getAlpha());
  BOB_CATCH_MEMBER("__alpha__ could not be read", 0)
}


/***** __beta__ *****/
static auto __beta__ = bob::extension::VariableDoc(
  "__beta__",
  "array_like <float, 2D>",
  "Gets the :math:`\\beta` matrix "
  ":math:`\\beta = (\\Sigma + G G^T)^{-1} = \\mathcal{S} = \\Sigma^{-1} - \\Sigma^{-1} G \\mathcal{G} G^{T} \\Sigma^{-1}`",
  ""
);
static PyObject* PyBobLearnEMPLDABase_getBeta(PyBobLearnEMPLDABaseObject* self, PyObject* args, PyObject* kwargs) {
  BOB_TRY
  return PyBlitzArrayCxx_AsConstNumpy(self->cxx->getBeta());
  BOB_CATCH_MEMBER("__beta__ could not be read", 0)
}


/***** __ft_beta__ *****/
static auto __ft_beta__ = bob::extension::VariableDoc(
  "__ft_beta__",
  "array_like <float, 2D>",
  "Gets the :math:`F^T \\beta' matrix",
  ""
);
static PyObject* PyBobLearnEMPLDABase_getFtBeta(PyBobLearnEMPLDABaseObject* self, PyObject* args, PyObject* kwargs) {
  BOB_TRY
  return PyBlitzArrayCxx_AsConstNumpy(self->cxx->getFtBeta());
  BOB_CATCH_MEMBER("__ft_beta__ could not be read", 0)
}


/***** __gt_i_sigma__ *****/
static auto __gt_i_sigma__ = bob::extension::VariableDoc(
  "__gt_i_sigma__",
  "array_like <float, 2D>",
  "Gets the :math:`G^T \\Sigma^{-1}` matrix",
  ""
);
static PyObject* PyBobLearnEMPLDABase_getGtISigma(PyBobLearnEMPLDABaseObject* self, PyObject* args, PyObject* kwargs) {
  BOB_TRY
  return PyBlitzArrayCxx_AsConstNumpy(self->cxx->getGtISigma());
  BOB_CATCH_MEMBER("__gt_i_sigma__ could not be read", 0)
}


/***** __logdet_alpha__ *****/
static auto __logdet_alpha__ = bob::extension::VariableDoc(
  "__logdet_alpha__",
  "double",
  "Gets :math:`\\log(\\det(\\alpha))`",
  ""
);
static PyObject* PyBobLearnEMPLDABase_getLogDetAlpha(PyBobLearnEMPLDABaseObject* self, PyObject* args, PyObject* kwargs) {
  BOB_TRY
  return Py_BuildValue("d",self->cxx->getLogDetAlpha());
  BOB_CATCH_MEMBER("__logdet_alpha__ could not be read", 0)
}

/***** __logdet_sigma__ *****/
static auto __logdet_sigma__ = bob::extension::VariableDoc(
  "__logdet_sigma__",
  "double",
  "Gets :math:`\\log(\\det(\\Sigma))`",
  ""
);
static PyObject* PyBobLearnEMPLDABase_getLogDetSigma(PyBobLearnEMPLDABaseObject* self, PyObject* args, PyObject* kwargs) {
  BOB_TRY
  return Py_BuildValue("d",self->cxx->getLogDetSigma());
  BOB_CATCH_MEMBER("__logdet_sigma__ could not be read", 0)
}


/***** variance_threshold *****/
static auto variance_threshold = bob::extension::VariableDoc(
  "variance_threshold",
  "double",
  "",
  ""
);
static PyObject* PyBobLearnEMPLDABase_getVarianceThreshold(PyBobLearnEMPLDABaseObject* self, PyObject* args, PyObject* kwargs) {
  BOB_TRY
  return Py_BuildValue("d",self->cxx->getVarianceThreshold());
  BOB_CATCH_MEMBER("variance_threshold could not be read", 0)
}
int PyBobLearnEMPLDABase_setVarianceThreshold(PyBobLearnEMPLDABaseObject* self, PyObject* value, void*){
  BOB_TRY

400
  if (!PyBob_NumberCheck(value)){
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
    PyErr_Format(PyExc_RuntimeError, "%s %s expects an float", Py_TYPE(self)->tp_name, variance_threshold.name());
    return -1;
  }

  self->cxx->setVarianceThreshold(PyFloat_AS_DOUBLE(value));
  BOB_CATCH_MEMBER("variance_threshold could not be set", -1)
  return 0;
}




/***** sigma *****/
static auto sigma = bob::extension::VariableDoc(
  "sigma",
  "array_like <float, 1D>",
  "Gets the :math:`\\sigma` (diagonal) covariance matrix of the PLDA model",
  ""
);
static PyObject* PyBobLearnEMPLDABase_getSigma(PyBobLearnEMPLDABaseObject* self, PyObject* args, PyObject* kwargs) {
  BOB_TRY
  return PyBlitzArrayCxx_AsConstNumpy(self->cxx->getSigma());
  BOB_CATCH_MEMBER("sigma could not be read", 0)
}
int PyBobLearnEMPLDABase_setSigma(PyBobLearnEMPLDABaseObject* self, PyObject* value, void*){
  BOB_TRY
  PyBlitzArrayObject* o;
  if (!PyBlitzArray_Converter(value, &o)){
    PyErr_Format(PyExc_RuntimeError, "%s %s expects a 2D array of floats", Py_TYPE(self)->tp_name, sigma.name());
    return -1;
  }
  auto o_ = make_safe(o);
  auto b = PyBlitzArrayCxx_AsBlitz<double,1>(o, "sigma");
  if (!b) return -1;
  self->cxx->setSigma(*b);
  return 0;
  BOB_CATCH_MEMBER("`sigma` vector could not be set", -1)
}


static PyGetSetDef PyBobLearnEMPLDABase_getseters[] = { 
  {
   shape.name(),
   (getter)PyBobLearnEMPLDABase_getShape,
   0,
   shape.doc(),
   0
  },  
  {
   F.name(),
   (getter)PyBobLearnEMPLDABase_getF,
   (setter)PyBobLearnEMPLDABase_setF,
   F.doc(),
   0
  },
  {
   G.name(),
   (getter)PyBobLearnEMPLDABase_getG,
   (setter)PyBobLearnEMPLDABase_setG,
   G.doc(),
   0
  },
  {
   mu.name(),
   (getter)PyBobLearnEMPLDABase_getMu,
   (setter)PyBobLearnEMPLDABase_setMu,
   mu.doc(),
   0
  },
  {
   __isigma__.name(),
   (getter)PyBobLearnEMPLDABase_getISigma,
   0,
   __isigma__.doc(),
   0
  },
  {
   __alpha__.name(),
   (getter)PyBobLearnEMPLDABase_getAlpha,
   0,
   __alpha__.doc(),
   0
  },
  {
   __beta__.name(),
   (getter)PyBobLearnEMPLDABase_getBeta,
   0,
   __beta__.doc(),
   0
  },
  {
  __ft_beta__.name(),
   (getter)PyBobLearnEMPLDABase_getFtBeta,
   0,
   __ft_beta__.doc(),
   0
  },
  {
  __gt_i_sigma__.name(),
   (getter)PyBobLearnEMPLDABase_getGtISigma,
   0,
   __gt_i_sigma__.doc(),
   0
  },
  {
  __logdet_alpha__.name(),
   (getter)PyBobLearnEMPLDABase_getLogDetAlpha,
   0,
   __logdet_alpha__.doc(),
   0
  },
  {
  __logdet_sigma__.name(),
   (getter)PyBobLearnEMPLDABase_getLogDetSigma,
   0,
   __logdet_sigma__.doc(),
   0
  },
  {
   sigma.name(),
   (getter)PyBobLearnEMPLDABase_getSigma,
   (setter)PyBobLearnEMPLDABase_setSigma,
   sigma.doc(),
   0
  },
  {
   variance_threshold.name(),
   (getter)PyBobLearnEMPLDABase_getVarianceThreshold,
   (setter)PyBobLearnEMPLDABase_setVarianceThreshold,
   variance_threshold.doc(),
   0
  },
  {0}  // Sentinel
};


/******************************************************************/
/************ Functions Section ***********************************/
/******************************************************************/


/*** save ***/
static auto save = bob::extension::FunctionDoc(
  "save",
  "Save the configuration of the PLDABase to a given HDF5 file"
)
.add_prototype("hdf5")
.add_parameter("hdf5", ":py:class:`bob.io.base.HDF5File`", "An HDF5 file open for writing");
static PyObject* PyBobLearnEMPLDABase_Save(PyBobLearnEMPLDABaseObject* self,  PyObject* args, PyObject* kwargs) {

  BOB_TRY
  
  // get list of arguments
  char** kwlist = save.kwlist(0);  
  PyBobIoHDF5FileObject* hdf5;
  if (!PyArg_ParseTupleAndKeywords(args, kwargs, "O&", kwlist, PyBobIoHDF5File_Converter, &hdf5)) return 0;

  auto hdf5_ = make_safe(hdf5);
  self->cxx->save(*hdf5->f);

  BOB_CATCH_MEMBER("cannot save the data", 0)
  Py_RETURN_NONE;
}

/*** load ***/
static auto load = bob::extension::FunctionDoc(
  "load",
  "Load the configuration of the PLDABase to a given HDF5 file"
)
.add_prototype("hdf5")
.add_parameter("hdf5", ":py:class:`bob.io.base.HDF5File`", "An HDF5 file open for reading");
static PyObject* PyBobLearnEMPLDABase_Load(PyBobLearnEMPLDABaseObject* self, PyObject* args, PyObject* kwargs) {
  BOB_TRY
  
  char** kwlist = load.kwlist(0);  
  PyBobIoHDF5FileObject* hdf5;
  if (!PyArg_ParseTupleAndKeywords(args, kwargs, "O&", kwlist, PyBobIoHDF5File_Converter, &hdf5)) return 0;
  
  auto hdf5_ = make_safe(hdf5);  
  self->cxx->load(*hdf5->f);

  BOB_CATCH_MEMBER("cannot load the data", 0)
  Py_RETURN_NONE;
}


/*** is_similar_to ***/
static auto is_similar_to = bob::extension::FunctionDoc(
  "is_similar_to",
  
  "Compares this PLDABase with the ``other`` one to be approximately the same.",
  "The optional values ``r_epsilon`` and ``a_epsilon`` refer to the "
  "relative and absolute precision for the ``weights``, ``biases`` "
  "and any other values internal to this machine."
)
.add_prototype("other, [r_epsilon], [a_epsilon]","output")
.add_parameter("other", ":py:class:`bob.learn.em.PLDABase`", "A PLDABase object to be compared.")
.add_parameter("r_epsilon", "float", "Relative precision.")
.add_parameter("a_epsilon", "float", "Absolute precision.")
.add_return("output","bool","True if it is similar, otherwise false.");
static PyObject* PyBobLearnEMPLDABase_IsSimilarTo(PyBobLearnEMPLDABaseObject* self, PyObject* args, PyObject* kwds) {

  /* Parses input arguments in a single shot */
  char** kwlist = is_similar_to.kwlist(0);

  //PyObject* other = 0;
  PyBobLearnEMPLDABaseObject* other = 0;
  double r_epsilon = 1.e-5;
  double a_epsilon = 1.e-8;

  if (!PyArg_ParseTupleAndKeywords(args, kwds, "O!|dd", kwlist,
        &PyBobLearnEMPLDABase_Type, &other,
        &r_epsilon, &a_epsilon)){

        is_similar_to.print_usage(); 
        return 0;        
  }

  if (self->cxx->is_similar_to(*other->cxx, r_epsilon, a_epsilon))
    Py_RETURN_TRUE;
  else
    Py_RETURN_FALSE;
}


/*** resize ***/
static auto resize = bob::extension::FunctionDoc(
  "resize",
629
  "Resizes the dimensionality of the PLDA model. Paramaters :math:`\\mu`, :math:`F`, :math:`G` and :math:`\\Sigma` are reinitialized.",
630
631
632
  0,
  true
)
633
634
635
636
.add_prototype("dim_d,dim_f,dim_g")
.add_parameter("dim_d", "int", "Dimensionality of the feature vector.")
.add_parameter("dim_f", "int", "Size of :math:`F` (between class variantion matrix).")
.add_parameter("dim_g", "int", "Size of :math:`G` (within class variantion matrix).");
637
638
639
640
641
642
643
644
static PyObject* PyBobLearnEMPLDABase_resize(PyBobLearnEMPLDABaseObject* self, PyObject* args, PyObject* kwargs) {
  BOB_TRY

  /* Parses input arguments in a single shot */
  char** kwlist = resize.kwlist(0);

  int dim_D, dim_F, dim_G = 0;

645
  if (!PyArg_ParseTupleAndKeywords(args, kwargs, "iii", kwlist, &dim_D, &dim_F, &dim_G)) return 0;
646
647

  if(dim_D <= 0){
648
    PyErr_Format(PyExc_TypeError, "dim_d argument must be greater than or equal to one");
649
650
651
652
    Py_RETURN_NONE;
  }
  
  if(dim_F <= 0){
653
    PyErr_Format(PyExc_TypeError, "dim_f argument must be greater than or equal to one");
654
655
656
657
    Py_RETURN_NONE;
  }

  if(dim_G <= 0){
658
    PyErr_Format(PyExc_TypeError, "dim_g argument must be greater than or equal to one");
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
    Py_RETURN_NONE;
  }

  self->cxx->resize(dim_D, dim_F, dim_G);

  BOB_CATCH_MEMBER("cannot perform the resize method", 0)

  Py_RETURN_NONE;
}


/***** get_gamma *****/
static auto get_gamma = bob::extension::FunctionDoc(
  "get_gamma",
  "Gets the :math:`\\gamma_a` matrix for a given :math:`a` (number of samples). "
674
  ":math:`\\gamma_{a}=(Id + a F^T \\beta F)^{-1} = \\mathcal{F}_{a}`",
675
676
677
678
679
680
681
682
683
684
685
686
  0,
  true
)
.add_prototype("a","output")
.add_parameter("a", "int", "Index")
.add_return("output","array_like <float, 2D>","Get the :math:`\\gamma` matrix");
static PyObject* PyBobLearnEMPLDABase_getGamma(PyBobLearnEMPLDABaseObject* self, PyObject* args, PyObject* kwargs) {
  BOB_TRY
  
  char** kwlist = get_gamma.kwlist(0);

  int i = 0;
687
  if (!PyArg_ParseTupleAndKeywords(args, kwargs, "i", kwlist, &i)) return 0;
688
689
690
691
692
693
694
695
696

  return PyBlitzArrayCxx_AsConstNumpy(self->cxx->getGamma(i));
  BOB_CATCH_MEMBER("`get_gamma` could not be read", 0)
}


/***** has_gamma *****/
static auto has_gamma = bob::extension::FunctionDoc(
  "has_gamma",
697
698
  "Tells if the :math:`\\gamma_a` matrix for a given a (number of samples) exists. "
  ":math:`\\gamma_a=(Id + aF^T \\beta F)^{-1}`",
699
700
701
702
703
704
705
706
707
708
709
  0,
  true
)
.add_prototype("a","output")
.add_parameter("a", "int", "Index")
.add_return("output","bool","");
static PyObject* PyBobLearnEMPLDABase_hasGamma(PyBobLearnEMPLDABaseObject* self, PyObject* args, PyObject* kwargs) {
  BOB_TRY
  
  char** kwlist = has_gamma.kwlist(0);
  int i = 0;
710
  if (!PyArg_ParseTupleAndKeywords(args, kwargs, "i", kwlist, &i)) return 0;
711
712
713
714
715
716
717
718
719
720
721
722

  if(self->cxx->hasGamma(i))
    Py_RETURN_TRUE;
  else
    Py_RETURN_FALSE;
 BOB_CATCH_MEMBER("`has_gamma` could not be read", 0)    
}


/***** compute_gamma *****/
static auto compute_gamma = bob::extension::FunctionDoc(
  "compute_gamma",
723
724
  "Tells if the :math:`\\gamma_a` matrix for a given a (number of samples) exists."
  " :math:`\\gamma_a=(Id + a F^T \\beta F)^{-1}`",
725
726
727
728
729
730
731
732
733
734
735
736
  0,
  true
)
.add_prototype("a,res","")
.add_parameter("a", "int", "Index")
.add_parameter("res", "array_like <float, 2D>", "Input data");
static PyObject* PyBobLearnEMPLDABase_computeGamma(PyBobLearnEMPLDABaseObject* self, PyObject* args, PyObject* kwargs) {
  BOB_TRY
  
  char** kwlist = compute_gamma.kwlist(0);
  int i = 0;
  PyBlitzArrayObject* res = 0;  
737
  if (!PyArg_ParseTupleAndKeywords(args, kwargs, "iO&", kwlist, &i, &PyBlitzArray_Converter, &res)) return 0;
738
739
740
741
742
743
744
745
746
747
748
749

  auto res_ = make_safe(res);  

  self->cxx->computeGamma(i,*PyBlitzArrayCxx_AsBlitz<double,2>(res));
  Py_RETURN_NONE;
  BOB_CATCH_MEMBER("`compute_gamma` could not be read", 0)    
}

/***** get_add_gamma *****/
static auto get_add_gamma = bob::extension::FunctionDoc(
  "get_add_gamma",
   "Gets the :math:`gamma_a` matrix for a given :math:`f_a` (number of samples)."
750
   " :math:`\\gamma_a=(Id + a F^T \\beta F)^{-1} =\\mathcal{F}_{a}`."
751
752
753
754
755
756
757
758
759
760
761
762
763
   "Tries to find it from the base machine and then from this machine.",
  0,
  true
)
.add_prototype("a","output")
.add_parameter("a", "int", "Index")
.add_return("output","array_like <float, 2D>","");
static PyObject* PyBobLearnEMPLDABase_getAddGamma(PyBobLearnEMPLDABaseObject* self, PyObject* args, PyObject* kwargs) {
  BOB_TRY
  
  char** kwlist = get_add_gamma.kwlist(0);

  int i = 0;
764
  if (!PyArg_ParseTupleAndKeywords(args, kwargs, "i", kwlist, &i)) return 0;
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786

  return PyBlitzArrayCxx_AsConstNumpy(self->cxx->getAddGamma(i));
  BOB_CATCH_MEMBER("`get_add_gamma` could not be read", 0)
}


/***** has_log_like_const_term *****/
static auto has_log_like_const_term = bob::extension::FunctionDoc(
  "has_log_like_const_term",
   "Tells if the log likelihood constant term for a given :math:`a` (number of samples) exists in this machine (does not check the base machine). "
   ":math:`l_{a}=\\frac{a}{2} ( -D log(2\\pi) -log|\\Sigma| +log|\\alpha| +log|\\gamma_a|)`",
  0,
  true
)
.add_prototype("a","output")
.add_parameter("a", "int", "Index")
.add_return("output","bool","");
static PyObject* PyBobLearnEMPLDABase_hasLogLikeConstTerm(PyBobLearnEMPLDABaseObject* self, PyObject* args, PyObject* kwargs) {
  BOB_TRY
  
  char** kwlist = has_log_like_const_term.kwlist(0);
  int i = 0;
787
  if (!PyArg_ParseTupleAndKeywords(args, kwargs, "i", kwlist, &i)) return 0;
788
789
790
791
792
793
794
795
796
797
798
799

  if(self->cxx->hasLogLikeConstTerm(i))
    Py_RETURN_TRUE;
  else
    Py_RETURN_FALSE;
 BOB_CATCH_MEMBER("`has_log_like_const_term` could not be read", 0)    
}


/***** compute_log_like_const_term" *****/
static auto compute_log_like_const_term = bob::extension::FunctionDoc(
  "compute_log_like_const_term",
800
  "Computes the log likelihood constant term for a given :math:`a` (number of samples), given the provided :math:`\\gamma_a` matrix. "
801
802
803
804
805
806
807
808
809
810
811
812
813
814
  ":math:`l_{a} = \\frac{a}{2} ( -D log(2\\pi) -log|\\Sigma| +log|\\alpha| +log|\\gamma_a|)`",

  0,
  true
)
.add_prototype("a,res","")
.add_parameter("a", "int", "Index")
.add_parameter("res", "array_like <float, 2D>", "Input data");
static PyObject* PyBobLearnEMPLDABase_computeLogLikeConstTerm(PyBobLearnEMPLDABaseObject* self, PyObject* args, PyObject* kwargs) {
  BOB_TRY
  
  char** kwlist = compute_log_like_const_term.kwlist(0);
  int i = 0;
  PyBlitzArrayObject* res = 0;  
815
  if (!PyArg_ParseTupleAndKeywords(args, kwargs, "iO&", kwlist, &i, &PyBlitzArray_Converter, &res)) return 0;
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841

  auto res_ = make_safe(res);  

  self->cxx->computeLogLikeConstTerm(i,*PyBlitzArrayCxx_AsBlitz<double,2>(res));
  Py_RETURN_NONE;
  BOB_CATCH_MEMBER("`compute_gamma` could not be read", 0)    
}


/***** get_add_log_like_const_term *****/
static auto get_add_log_like_const_term = bob::extension::FunctionDoc(
  "get_add_log_like_const_term",

   "Gets the log likelihood constant term for a given :math:`a` (number of samples). "
   ":math:`l_{a} = \\frac{a}{2} ( -D log(2\\pi) -log|\\Sigma| +log|\\alpha| +log|\\gamma_a|)`",
  0,
  true
)
.add_prototype("a","output")
.add_parameter("a", "int", "Index")
.add_return("output","double","");
static PyObject* PyBobLearnEMPLDABase_getAddLogLikeConstTerm(PyBobLearnEMPLDABaseObject* self, PyObject* args, PyObject* kwargs) {
  BOB_TRY
  
  char** kwlist = get_add_log_like_const_term.kwlist(0);
  int i = 0;
842
  if (!PyArg_ParseTupleAndKeywords(args, kwargs, "i", kwlist, &i)) return 0;
843
844
845
846
847
848
849
850
851
852
853

  return Py_BuildValue("d",self->cxx->getAddLogLikeConstTerm(i));

  BOB_CATCH_MEMBER("`get_add_log_like_const_term` could not be read", 0)    
}


/***** get_log_like_const_term *****/
static auto get_log_like_const_term = bob::extension::FunctionDoc(
  "get_log_like_const_term",
   "Gets the log likelihood constant term for a given :math:`a` (number of samples). "
854
    ":math:`l_{a}=\\frac{a}{2} ( -D log(2\\pi) -log|\\Sigma| +log|\\alpha| +log|\\gamma_a|)`",
855
856
857
858
859
860
861
862
863
864
865
  0,
  true
)
.add_prototype("a","output")
.add_parameter("a", "int", "Index")
.add_return("output","double","");
static PyObject* PyBobLearnEMPLDABase_getLogLikeConstTerm(PyBobLearnEMPLDABaseObject* self, PyObject* args, PyObject* kwargs) {
  BOB_TRY
  
  char** kwlist = get_log_like_const_term.kwlist(0);
  int i = 0;
866
  if (!PyArg_ParseTupleAndKeywords(args, kwargs, "i", kwlist, &i)) return 0;
867
868
869
870
871
872
873
874
875

  return Py_BuildValue("d",self->cxx->getLogLikeConstTerm(i));

  BOB_CATCH_MEMBER("`get_log_like_const_term` could not be read", 0)    
}

/***** clear_maps *****/
static auto clear_maps = bob::extension::FunctionDoc(
  "clear_maps",
876
  "Clears the maps (:math:`\\gamma_a` and loglike_constterm_a).",
877
878
  0,
  true
879
880
)
.add_prototype("","");
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
static PyObject* PyBobLearnEMPLDABase_clearMaps(PyBobLearnEMPLDABaseObject* self, PyObject* args, PyObject* kwargs) {
  BOB_TRY
  
  self->cxx->clearMaps();
  Py_RETURN_NONE;

  BOB_CATCH_MEMBER("`clear_maps` could not be read", 0)    
}


/***** compute_log_likelihood_point_estimate *****/
static auto compute_log_likelihood_point_estimate = bob::extension::FunctionDoc(
  "compute_log_likelihood_point_estimate",
   "Gets the log-likelihood of an observation, given the current model and the latent variables (point estimate)."
   "This will basically compute :math:`p(x_{ij} | h_{i}, w_{ij}, \\Theta)`, given by "
   ":math:`\\mathcal{N}(x_{ij}|[\\mu + F h_{i} + G w_{ij} + \\epsilon_{ij}, \\Sigma])`, which is in logarithm, "
   ":math:`\\frac{D}{2} log(2\\pi) -\\frac{1}{2} log(det(\\Sigma)) -\\frac{1}{2} {(x_{ij}-(\\mu+F h_{i}+G w_{ij}))^{T}\\Sigma^{-1}(x_{ij}-(\\mu+F h_{i}+G w_{ij}))}`",
  0,
  true
)
.add_prototype("xij,hi,wij","output")
.add_parameter("xij", "array_like <float, 1D>", "")
.add_parameter("hi", "array_like <float, 1D>", "")
.add_parameter("wij", "array_like <float, 1D>", "")
.add_return("output", "double", "");
static PyObject* PyBobLearnEMPLDABase_computeLogLikelihoodPointEstimate(PyBobLearnEMPLDABaseObject* self, PyObject* args, PyObject* kwargs) {
  BOB_TRY
  
  char** kwlist = compute_log_likelihood_point_estimate.kwlist(0);
  PyBlitzArrayObject* xij, *hi, *wij;  
  if (!PyArg_ParseTupleAndKeywords(args, kwargs, "O&O&O&", kwlist, &PyBlitzArray_Converter, &xij,
                                                               &PyBlitzArray_Converter, &hi,
                                                               &PyBlitzArray_Converter, &wij)) return 0;

  auto xij_ = make_safe(xij);
  auto hi_ = make_safe(hi);
  auto wij_ = make_safe(wij);  

  return Py_BuildValue("d", self->cxx->computeLogLikelihoodPointEstimate(*PyBlitzArrayCxx_AsBlitz<double,1>(xij), *PyBlitzArrayCxx_AsBlitz<double,1>(hi), *PyBlitzArrayCxx_AsBlitz<double,1>(wij)));
  
  BOB_CATCH_MEMBER("`compute_log_likelihood_point_estimate` could not be read", 0)    
}

/***** __precompute__ *****/
static auto __precompute__ = bob::extension::FunctionDoc(
  "__precompute__",
  "Precomputes useful values for the log likelihood "
  ":math:`\\log(\\det(\\alpha))` and :math:`\\log(\\det(\\Sigma))`.",
  0,
  true
);
static PyObject* PyBobLearnEMPLDABase_precompute(PyBobLearnEMPLDABaseObject* self, PyObject* args, PyObject* kwargs) {
  BOB_TRY
  
  self->cxx->precompute();
  Py_RETURN_NONE;

  BOB_CATCH_MEMBER("`precompute` could not be read", 0)    
}


/***** __precompute_log_like__ *****/
static auto __precompute_log_like__ = bob::extension::FunctionDoc(
  "__precompute_log_like__",

  "Precomputes useful values for the log likelihood "
  ":math:`\\log(\\det(\\alpha))` and :math:`\\log(\\det(\\Sigma))`.",

  0,
  true
);
static PyObject* PyBobLearnEMPLDABase_precomputeLogLike(PyBobLearnEMPLDABaseObject* self, PyObject* args, PyObject* kwargs) {
  BOB_TRY
  
  self->cxx->precomputeLogLike();
  Py_RETURN_NONE;

  BOB_CATCH_MEMBER("`__precompute_log_like__` could not be read", 0)    
}


static PyMethodDef PyBobLearnEMPLDABase_methods[] = {
  {
    save.name(),
    (PyCFunction)PyBobLearnEMPLDABase_Save,
    METH_VARARGS|METH_KEYWORDS,
    save.doc()
  },
  {
    load.name(),
    (PyCFunction)PyBobLearnEMPLDABase_Load,
    METH_VARARGS|METH_KEYWORDS,
    load.doc()
  },
  {
    is_similar_to.name(),
    (PyCFunction)PyBobLearnEMPLDABase_IsSimilarTo,
    METH_VARARGS|METH_KEYWORDS,
    is_similar_to.doc()
  },
  {
    resize.name(),
    (PyCFunction)PyBobLearnEMPLDABase_resize,
    METH_VARARGS|METH_KEYWORDS,
    resize.doc()
  },
  {
    get_gamma.name(),
    (PyCFunction)PyBobLearnEMPLDABase_getGamma,
    METH_VARARGS|METH_KEYWORDS,
    get_gamma.doc()
  },
  {
    has_gamma.name(),
    (PyCFunction)PyBobLearnEMPLDABase_hasGamma,
    METH_VARARGS|METH_KEYWORDS,
    has_gamma.doc()
  },
  {
    compute_gamma.name(),
    (PyCFunction)PyBobLearnEMPLDABase_computeGamma,
    METH_VARARGS|METH_KEYWORDS,
    compute_gamma.doc()
  },
  {
    get_add_gamma.name(),
    (PyCFunction)PyBobLearnEMPLDABase_getAddGamma,
    METH_VARARGS|METH_KEYWORDS,
    get_add_gamma.doc()
  },
  {
    has_log_like_const_term.name(),
    (PyCFunction)PyBobLearnEMPLDABase_hasLogLikeConstTerm,
    METH_VARARGS|METH_KEYWORDS,
    has_log_like_const_term.doc()
  },  
  {
    compute_log_like_const_term.name(),
    (PyCFunction)PyBobLearnEMPLDABase_computeLogLikeConstTerm,
    METH_VARARGS|METH_KEYWORDS,
    compute_log_like_const_term.doc()
  },  
  {
    get_add_log_like_const_term.name(),
    (PyCFunction)PyBobLearnEMPLDABase_getAddLogLikeConstTerm,
    METH_VARARGS|METH_KEYWORDS,
    get_add_log_like_const_term.doc()
  },  
  {
    get_log_like_const_term.name(),
    (PyCFunction)PyBobLearnEMPLDABase_getLogLikeConstTerm,
    METH_VARARGS|METH_KEYWORDS,
    get_log_like_const_term.doc()
  },  
  {
    clear_maps.name(),
    (PyCFunction)PyBobLearnEMPLDABase_clearMaps,
    METH_NOARGS,
    clear_maps.doc()
  },
  {
    compute_log_likelihood_point_estimate.name(),
    (PyCFunction)PyBobLearnEMPLDABase_computeLogLikelihoodPointEstimate,
    METH_VARARGS|METH_KEYWORDS,
    compute_log_likelihood_point_estimate.doc()
  },
  {
    __precompute__.name(),
    (PyCFunction)PyBobLearnEMPLDABase_precompute,
    METH_NOARGS,
    __precompute__.doc()
  },   
  {
    __precompute_log_like__.name(),
    (PyCFunction)PyBobLearnEMPLDABase_precomputeLogLike,
    METH_NOARGS,
    __precompute_log_like__.doc()
  },     
  {0} /* Sentinel */
};


/******************************************************************/
/************ Module Section **************************************/
/******************************************************************/

// Define the JFA type struct; will be initialized later
PyTypeObject PyBobLearnEMPLDABase_Type = {
  PyVarObject_HEAD_INIT(0,0)
  0
};

bool init_BobLearnEMPLDABase(PyObject* module)
{
  // initialize the type struct
  PyBobLearnEMPLDABase_Type.tp_name      = PLDABase_doc.name();
  PyBobLearnEMPLDABase_Type.tp_basicsize = sizeof(PyBobLearnEMPLDABaseObject);
  PyBobLearnEMPLDABase_Type.tp_flags     = Py_TPFLAGS_DEFAULT;
  PyBobLearnEMPLDABase_Type.tp_doc       = PLDABase_doc.doc();

  // set the functions
  PyBobLearnEMPLDABase_Type.tp_new         = PyType_GenericNew;
  PyBobLearnEMPLDABase_Type.tp_init        = reinterpret_cast<initproc>(PyBobLearnEMPLDABase_init);
  PyBobLearnEMPLDABase_Type.tp_dealloc     = reinterpret_cast<destructor>(PyBobLearnEMPLDABase_delete);
  PyBobLearnEMPLDABase_Type.tp_richcompare = reinterpret_cast<richcmpfunc>(PyBobLearnEMPLDABase_RichCompare);
  PyBobLearnEMPLDABase_Type.tp_methods     = PyBobLearnEMPLDABase_methods;
  PyBobLearnEMPLDABase_Type.tp_getset      = PyBobLearnEMPLDABase_getseters;
  //PyBobLearnEMPLDABase_Type.tp_call = reinterpret_cast<ternaryfunc>(PyBobLearnEMPLDABase_forward);


  // check that everything is fine
  if (PyType_Ready(&PyBobLearnEMPLDABase_Type) < 0) return false;

  // add the type to the module
  Py_INCREF(&PyBobLearnEMPLDABase_Type);
  return PyModule_AddObject(module, "PLDABase", (PyObject*)&PyBobLearnEMPLDABase_Type) >= 0;
}