diff --git a/bob/learn/em/cpp/ZTNorm.cpp b/bob/learn/em/cpp/ZTNorm.cpp deleted file mode 100644 index 0319d0402532d135c7e169681a71ecd2ac60bd24..0000000000000000000000000000000000000000 --- a/bob/learn/em/cpp/ZTNorm.cpp +++ /dev/null @@ -1,181 +0,0 @@ -/** - * @date Tue Jul 19 15:33:20 2011 +0200 - * @author Francois Moulin <Francois.Moulin@idiap.ch> - * @author Laurent El Shafey <Laurent.El-Shafey@idiap.ch> - * - * Copyright (C) Idiap Research Institute, Martigny, Switzerland - */ - -#include <bob.learn.em/ZTNorm.h> -#include <bob.core/assert.h> -#include <limits> - - -static void _ztNorm(const blitz::Array<double,2>& rawscores_probes_vs_models, - const blitz::Array<double,2>* rawscores_zprobes_vs_models, - const blitz::Array<double,2>* rawscores_probes_vs_tmodels, - const blitz::Array<double,2>* rawscores_zprobes_vs_tmodels, - const blitz::Array<bool,2>* mask_zprobes_vs_tmodels_istruetrial, - blitz::Array<double,2>& scores) -{ - // Rename variables - const blitz::Array<double,2>& A = rawscores_probes_vs_models; - const blitz::Array<double,2>* B = rawscores_zprobes_vs_models; - const blitz::Array<double,2>* C = rawscores_probes_vs_tmodels; - const blitz::Array<double,2>* D = rawscores_zprobes_vs_tmodels; - - // Compute the sizes - int size_eval = A.extent(0); - int size_enroll = A.extent(1); - int size_tnorm = (C ? C->extent(0) : 0); - int size_znorm = (B ? B->extent(1) : 0); - - // Check the inputs - bob::core::array::assertSameDimensionLength(A.extent(0), size_eval); - bob::core::array::assertSameDimensionLength(A.extent(1), size_enroll); - - if (B) { - bob::core::array::assertSameDimensionLength(B->extent(1), size_znorm); - if (size_znorm > 0) - bob::core::array::assertSameDimensionLength(B->extent(0), size_eval); - } - - if (C) { - bob::core::array::assertSameDimensionLength(C->extent(0), size_tnorm); - if (size_tnorm > 0) - bob::core::array::assertSameDimensionLength(C->extent(1), size_enroll); - } - - if (D && size_znorm > 0 && size_tnorm > 0) { - bob::core::array::assertSameDimensionLength(D->extent(0), size_tnorm); - bob::core::array::assertSameDimensionLength(D->extent(1), size_znorm); - } - - if (mask_zprobes_vs_tmodels_istruetrial) { - bob::core::array::assertSameDimensionLength(mask_zprobes_vs_tmodels_istruetrial->extent(0), size_tnorm); - bob::core::array::assertSameDimensionLength(mask_zprobes_vs_tmodels_istruetrial->extent(1), size_znorm); - } - - bob::core::array::assertSameDimensionLength(scores.extent(0), size_eval); - bob::core::array::assertSameDimensionLength(scores.extent(1), size_enroll); - - // Declare needed IndexPlaceholder - blitz::firstIndex ii; - blitz::secondIndex jj; - - // Constant to check if the std is close to 0. - const double eps = std::numeric_limits<double>::min(); - - // zA - blitz::Array<double,2> zA(A.shape()); - if (B && size_znorm > 0) { - // Znorm --> zA = (A - mean(B) ) / std(B) [znorm on oringinal scores] - // mean(B) - blitz::Array<double,1> mean_B(blitz::mean(*B, jj)); - // std(B) - blitz::Array<double,2> B2n(B->shape()); - B2n = blitz::pow2((*B)(ii, jj) - mean_B(ii)); - blitz::Array<double,1> std_B(B->extent(0)); - if(size_znorm>1) - std_B = blitz::sqrt(blitz::sum(B2n, jj) / (size_znorm - 1)); - else // 1 single value -> std = 0 - std_B = 0; - std_B = blitz::where( std_B <= eps, 1., std_B); - - zA = (A(ii, jj) - mean_B(ii)) / std_B(ii); - } - else - zA = A; - - blitz::Array<double,2> zC(size_tnorm, size_enroll); - if (D && size_tnorm > 0 && size_znorm > 0) { - blitz::Array<double,1> mean_Dimp(size_tnorm); - blitz::Array<double,1> std_Dimp(size_tnorm); - - // Compute mean_Dimp and std_Dimp = D only with impostors - for (int i = 0; i < size_tnorm; ++i) { - double sum = 0; - double sumsq = 0; - double count = 0; - for (int j = 0; j < size_znorm; ++j) { - bool keep; - // The second part is never executed if mask_zprobes_vs_tmodels_istruetrial==NULL - keep = (mask_zprobes_vs_tmodels_istruetrial == NULL) || !(*mask_zprobes_vs_tmodels_istruetrial)(i, j); //tnorm_models_spk_ids(i) != znorm_tests_spk_ids(j); - - double value = keep * (*D)(i, j); - sum += value; - sumsq += value*value; - count += keep; - } - - double mean = sum / count; - mean_Dimp(i) = mean; - if (count > 1) - std_Dimp(i) = sqrt((sumsq - count * mean * mean) / (count -1)); - else // 1 single value -> std = 0 - std_Dimp(i) = 0; - } - - // zC = (C - mean(D)) / std(D) [znorm the tnorm scores] - std_Dimp = blitz::where( std_Dimp <= eps, 1., std_Dimp); - zC = ((*C)(ii, jj) - mean_Dimp(ii)) / std_Dimp(ii); - } - else if (C && size_tnorm > 0) - zC = *C; - - if (C && size_tnorm > 0) - { - blitz::Array<double,1> mean_zC(size_enroll); - blitz::Array<double,1> std_zC(size_enroll); - - // ztA = (zA - mean(zC)) / std(zC) [ztnorm on eval scores] - mean_zC = blitz::mean(zC(jj, ii), jj); - if (size_tnorm > 1) - std_zC = sqrt(blitz::sum(pow(zC(jj, ii) - mean_zC(ii), 2) , jj) / (size_tnorm - 1)); - else // 1 single value -> std = 0 - std_zC = 0; - std_zC = blitz::where( std_zC <= eps, 1., std_zC); - - // Normalised scores - scores = (zA(ii, jj) - mean_zC(jj)) / std_zC(jj); - } - else - scores = zA; -} - -void bob::learn::em::ztNorm(const blitz::Array<double,2>& rawscores_probes_vs_models, - const blitz::Array<double,2>& rawscores_zprobes_vs_models, - const blitz::Array<double,2>& rawscores_probes_vs_tmodels, - const blitz::Array<double,2>& rawscores_zprobes_vs_tmodels, - const blitz::Array<bool,2>& mask_zprobes_vs_tmodels_istruetrial, - blitz::Array<double,2>& scores) -{ - _ztNorm(rawscores_probes_vs_models, &rawscores_zprobes_vs_models, &rawscores_probes_vs_tmodels, - &rawscores_zprobes_vs_tmodels, &mask_zprobes_vs_tmodels_istruetrial, scores); -} - -void bob::learn::em::ztNorm(const blitz::Array<double,2>& rawscores_probes_vs_models, - const blitz::Array<double,2>& rawscores_zprobes_vs_models, - const blitz::Array<double,2>& rawscores_probes_vs_tmodels, - const blitz::Array<double,2>& rawscores_zprobes_vs_tmodels, - blitz::Array<double,2>& scores) -{ - _ztNorm(rawscores_probes_vs_models, &rawscores_zprobes_vs_models, &rawscores_probes_vs_tmodels, - &rawscores_zprobes_vs_tmodels, NULL, scores); -} - -void bob::learn::em::tNorm(const blitz::Array<double,2>& rawscores_probes_vs_models, - const blitz::Array<double,2>& rawscores_probes_vs_tmodels, - blitz::Array<double,2>& scores) -{ - _ztNorm(rawscores_probes_vs_models, NULL, &rawscores_probes_vs_tmodels, - NULL, NULL, scores); -} - -void bob::learn::em::zNorm(const blitz::Array<double,2>& rawscores_probes_vs_models, - const blitz::Array<double,2>& rawscores_zprobes_vs_models, - blitz::Array<double,2>& scores) -{ - _ztNorm(rawscores_probes_vs_models, &rawscores_zprobes_vs_models, NULL, - NULL, NULL, scores); -} diff --git a/bob/learn/em/include/bob.learn.em/ZTNorm.h b/bob/learn/em/include/bob.learn.em/ZTNorm.h deleted file mode 100644 index d8e953d3b7d44ec66fd60e5acd652479e6733410..0000000000000000000000000000000000000000 --- a/bob/learn/em/include/bob.learn.em/ZTNorm.h +++ /dev/null @@ -1,89 +0,0 @@ -/** - * @date Tue Jul 19 15:33:20 2011 +0200 - * @author Francois Moulin <Francois.Moulin@idiap.ch> - * @author Laurent El Shafey <Laurent.El-Shafey@idiap.ch> - * - * Copyright (C) Idiap Research Institute, Martigny, Switzerland - */ - -#ifndef BOB_LEARN_EM_ZTNORM_H -#define BOB_LEARN_EM_ZTNORM_H - -#include <blitz/array.h> - -namespace bob { namespace learn { namespace em { - -/** - * Normalise raw scores with ZT-Norm - * - * @exception std::runtime_error matrix sizes are not consistent - * - * @param rawscores_probes_vs_models - * @param rawscores_zprobes_vs_models - * @param rawscores_probes_vs_tmodels - * @param rawscores_zprobes_vs_tmodels - * @param mask_zprobes_vs_tmodels_istruetrial - * @param[out] normalizedscores normalized scores - * @warning The destination score array should have the correct size - * (Same size as rawscores_probes_vs_models) - */ -void ztNorm(const blitz::Array<double, 2>& rawscores_probes_vs_models, - const blitz::Array<double, 2>& rawscores_zprobes_vs_models, - const blitz::Array<double, 2>& rawscores_probes_vs_tmodels, - const blitz::Array<double, 2>& rawscores_zprobes_vs_tmodels, - const blitz::Array<bool, 2>& mask_zprobes_vs_tmodels_istruetrial, - blitz::Array<double, 2>& normalizedscores); - -/** - * Normalise raw scores with ZT-Norm. - * Assume that znorm and tnorm have no common subject id. - * - * @exception std::runtime_error matrix sizes are not consistent - * - * @param rawscores_probes_vs_models - * @param rawscores_zprobes_vs_models - * @param rawscores_probes_vs_tmodels - * @param rawscores_zprobes_vs_tmodels - * @param[out] normalizedscores normalized scores - * @warning The destination score array should have the correct size - * (Same size as rawscores_probes_vs_models) - */ -void ztNorm(const blitz::Array<double,2>& rawscores_probes_vs_models, - const blitz::Array<double,2>& rawscores_zprobes_vs_models, - const blitz::Array<double,2>& rawscores_probes_vs_tmodels, - const blitz::Array<double,2>& rawscores_zprobes_vs_tmodels, - blitz::Array<double,2>& normalizedscores); - -/** - * Normalise raw scores with T-Norm. - * - * @exception std::runtime_error matrix sizes are not consistent - * - * @param rawscores_probes_vs_models - * @param rawscores_probes_vs_tmodels - * @param[out] normalizedscores normalized scores - * @warning The destination score array should have the correct size - * (Same size as rawscores_probes_vs_models) - */ -void tNorm(const blitz::Array<double,2>& rawscores_probes_vs_models, - const blitz::Array<double,2>& rawscores_probes_vs_tmodels, - blitz::Array<double,2>& normalizedscores); - -/** - * Normalise raw scores with Z-Norm. - * - * @exception std::runtime_error matrix sizes are not consistent - * - * @param rawscores_probes_vs_models - * @param rawscores_zprobes_vs_models - * @param[out] normalizedscores normalized scores - * @warning The destination score array should have the correct size - * (Same size as rawscores_probes_vs_models) - */ -void zNorm(const blitz::Array<double,2>& rawscores_probes_vs_models, - const blitz::Array<double,2>& rawscores_zprobes_vs_models, - blitz::Array<double,2>& normalizedscores); - -} } } // namespaces - -#endif /* BOB_LEARN_EM_ZTNORM_H */ diff --git a/bob/learn/em/main.cpp b/bob/learn/em/main.cpp index dc413e8c130d53d74bfce658567bdc232f9464cf..c2e7211f47fb44321375a2ffd56640c29c31f97c 100644 --- a/bob/learn/em/main.cpp +++ b/bob/learn/em/main.cpp @@ -11,24 +11,6 @@ #include "main.h" static PyMethodDef module_methods[] = { - { - zt_norm.name(), - (PyCFunction)PyBobLearnEM_ztNorm, - METH_VARARGS|METH_KEYWORDS, - zt_norm.doc() - }, - { - t_norm.name(), - (PyCFunction)PyBobLearnEM_tNorm, - METH_VARARGS|METH_KEYWORDS, - t_norm.doc() - }, - { - z_norm.name(), - (PyCFunction)PyBobLearnEM_zNorm, - METH_VARARGS|METH_KEYWORDS, - z_norm.doc() - }, { linear_scoring1.name(), (PyCFunction)PyBobLearnEM_linear_scoring, diff --git a/bob/learn/em/main.h b/bob/learn/em/main.h index 1d61e87055b1fbadba14565cf233aa6656059860..7d2cb43eca159beb3b16bc03430a5c8dc9039584 100644 --- a/bob/learn/em/main.h +++ b/bob/learn/em/main.h @@ -49,7 +49,6 @@ #include <bob.learn.em/PLDAMachine.h> #include <bob.learn.em/PLDATrainer.h> -#include <bob.learn.em/ZTNorm.h> /// inserts the given key, value pair into the given dictionaries static inline int insert_item_string(PyObject* dict, PyObject* entries, const char* key, Py_ssize_t value){ @@ -265,16 +264,6 @@ bool init_BobLearnEMEMPCATrainer(PyObject* module); int PyBobLearnEMEMPCATrainer_Check(PyObject* o); -//ZT Normalization -PyObject* PyBobLearnEM_ztNorm(PyObject*, PyObject* args, PyObject* kwargs); -extern bob::extension::FunctionDoc zt_norm; - -PyObject* PyBobLearnEM_tNorm(PyObject*, PyObject* args, PyObject* kwargs); -extern bob::extension::FunctionDoc t_norm; - -PyObject* PyBobLearnEM_zNorm(PyObject*, PyObject* args, PyObject* kwargs); -extern bob::extension::FunctionDoc z_norm; - //Linear scoring PyObject* PyBobLearnEM_linear_scoring(PyObject*, PyObject* args, PyObject* kwargs); diff --git a/bob/learn/em/test/test_ztnorm.py b/bob/learn/em/test/test_ztnorm.py deleted file mode 100644 index 4599d1a8e14b0187daa076910b0acc029e7ac98a..0000000000000000000000000000000000000000 --- a/bob/learn/em/test/test_ztnorm.py +++ /dev/null @@ -1,122 +0,0 @@ -#!/usr/bin/env python -# vim: set fileencoding=utf-8 : -# Francois Moulin <Francois.Moulin@idiap.ch> -# Laurent El Shafey <Laurent.El-Shafey@idiap.ch> -# Tue Jul 19 15:33:20 2011 +0200 -# -# Copyright (C) 2011-2014 Idiap Research Institute, Martigny, Switzerland - -"""Tests on the ZTNorm function -""" - -import numpy - -from bob.io.base.test_utils import datafile -import bob.io.base - -#from . import znorm, tnorm, ztnorm -import bob.learn.em - -def sameValue(vect_A, vect_B): - sameMatrix = numpy.zeros((vect_A.shape[0], vect_B.shape[0]), 'bool') - - for j in range(vect_A.shape[0]): - for i in range(vect_B.shape[0]): - sameMatrix[j, i] = (vect_A[j] == vect_B[i]) - - return sameMatrix - -def tnorm(A, C): - Cmean = numpy.mean(C, axis=0) - if C.shape[1] > 1: - Cstd = numpy.sqrt(numpy.sum((C - numpy.tile(Cmean.reshape(1,C.shape[1]), (C.shape[0],1))) ** 2, axis=0) / (C.shape[0]-1)) - else: - Cstd = numpy.ones(shape=(C.shape[1],), dtype=numpy.float64) - return (A - numpy.tile(Cmean.reshape(1,C.shape[1]), (A.shape[0],1))) / numpy.tile(Cstd.reshape(1,C.shape[1]), (A.shape[0],1)) - -def znorm(A, B): - Bmean = numpy.mean(B, axis=1) - if B.shape[1] > 1: - Bstd = numpy.sqrt(numpy.sum((B - numpy.tile(Bmean.reshape(B.shape[0],1), (1,B.shape[1]))) ** 2, axis=1) / (B.shape[1]-1)) - else: - Bstd = numpy.ones(shape=(B.shape[0],), dtype=numpy.float64) - - return (A - numpy.tile(Bmean.reshape(B.shape[0],1), (1,A.shape[1]))) / numpy.tile(Bstd.reshape(B.shape[0],1), (1,A.shape[1])) - - -def test_ztnorm_simple(): - # 3x5 - my_A = numpy.array([[1, 2, 3, 4, 5], - [6, 7, 8, 9, 8], - [7, 6, 5, 4, 3]],'float64') - # 3x4 - my_B = numpy.array([[5, 4, 7, 8],[9, 8, 7, 4],[5, 6, 3, 2]],'float64') - # 2x5 - my_C = numpy.array([[5, 4, 3, 2, 1],[2, 1, 2, 3, 4]],'float64') - # 2x4 - my_D = numpy.array([[8, 6, 4, 2],[0, 2, 4, 6]],'float64') - - # 4x1 - znorm_id = numpy.array([1, 2, 3, 4],'uint32') - # 2x1 - tnorm_id = numpy.array([1, 5],'uint32') - - scores = bob.learn.em.ztnorm(my_A, my_B, my_C, my_D, - sameValue(tnorm_id, znorm_id)) - - ref_scores = numpy.array([[-4.45473107e+00, -3.29289322e+00, -1.50519101e+01, -8.42086557e-01, 6.46544511e-03], [-8.27619927e-01, 7.07106781e-01, 1.13757710e+01, 2.01641412e+00, 7.63765080e-01], [ 2.52913570e+00, 2.70710678e+00, 1.24400233e+01, 7.07106781e-01, 6.46544511e-03]], 'float64') - - assert (abs(scores - ref_scores) < 1e-7).all() - -def test_ztnorm_big(): - my_A = bob.io.base.load(datafile("ztnorm_eval_eval.hdf5", __name__, path="../data/")) - my_B = bob.io.base.load(datafile("ztnorm_znorm_eval.hdf5", __name__, path="../data/")) - my_C = bob.io.base.load(datafile("ztnorm_eval_tnorm.hdf5", __name__, path="../data/")) - my_D = bob.io.base.load(datafile("ztnorm_znorm_tnorm.hdf5", __name__, path="../data/")) - - # ZT-Norm - ref_scores = bob.io.base.load(datafile("ztnorm_result.hdf5", __name__, path="../data/")) - scores = bob.learn.em.ztnorm(my_A, my_B, my_C, my_D) - assert (abs(scores - ref_scores) < 1e-7).all() - - # T-Norm - scores = bob.learn.em.tnorm(my_A, my_C) - scores_py = tnorm(my_A, my_C) - assert (abs(scores - scores_py) < 1e-7).all() - - # Z-Norm - scores = bob.learn.em.znorm(my_A, my_B) - scores_py = znorm(my_A, my_B) - assert (abs(scores - scores_py) < 1e-7).all() - -def test_tnorm_simple(): - # 3x5 - my_A = numpy.array([[1, 2, 3, 4, 5], - [6, 7, 8, 9, 8], - [7, 6, 5, 4, 3]],'float64') - # 2x5 - my_C = numpy.array([[5, 4, 3, 2, 1],[2, 1, 2, 3, 4]],'float64') - - zC = bob.learn.em.tnorm(my_A, my_C) - zC_py = tnorm(my_A, my_C) - assert (abs(zC - zC_py) < 1e-7).all() - - empty = numpy.zeros(shape=(0,0), dtype=numpy.float64) - zC = bob.learn.em.ztnorm(my_A, empty, my_C, empty) - assert (abs(zC - zC_py) < 1e-7).all() - -def test_znorm_simple(): - # 3x5 - my_A = numpy.array([[1, 2, 3, 4, 5], - [6, 7, 8, 9, 8], - [7, 6, 5, 4, 3]], numpy.float64) - # 3x4 - my_B = numpy.array([[5, 4, 7, 8],[9, 8, 7, 4],[5, 6, 3, 2]], numpy.float64) - - zA = bob.learn.em.znorm(my_A, my_B) - zA_py = znorm(my_A, my_B) - assert (abs(zA - zA_py) < 1e-7).all() - - empty = numpy.zeros(shape=(0,0), dtype=numpy.float64) - zA = bob.learn.em.ztnorm(my_A, my_B, empty, empty) - assert (abs(zA - zA_py) < 1e-7).all() diff --git a/bob/learn/em/ztnorm.cpp b/bob/learn/em/ztnorm.cpp deleted file mode 100644 index 6b1c9c03cc5a80ba6cf497a3a617ea56a9d42d04..0000000000000000000000000000000000000000 --- a/bob/learn/em/ztnorm.cpp +++ /dev/null @@ -1,144 +0,0 @@ -/** - * @author Tiago de Freitas Pereira <tiago.pereira@idiap.ch> - * @date Sat 31 Jan 02:46:48 2015 - * - * @brief Python API for bob::learn::em - * - * Copyright (C) 2011-2014 Idiap Research Institute, Martigny, Switzerland - */ - -#include "main.h" - -/*** zt_norm ***/ -bob::extension::FunctionDoc zt_norm = bob::extension::FunctionDoc( - "ztnorm", - "Normalise raw scores with :ref:`ZT-Norm <ztnorm>`." - "Assume that znorm and tnorm have no common subject id.", - 0, - true -) -.add_prototype("rawscores_probes_vs_models,rawscores_zprobes_vs_models,rawscores_probes_vs_tmodels,rawscores_zprobes_vs_tmodels,mask_zprobes_vs_tmodels_istruetrial", "output") -.add_parameter("rawscores_probes_vs_models", "array_like <float, 2D>", "Raw set of scores") -.add_parameter("rawscores_zprobes_vs_models", "array_like <float, 2D>", "Z-Scores (raw scores of the Z probes against the models)") -.add_parameter("rawscores_probes_vs_tmodels", "array_like <float, 2D>", "T-Scores (raw scores of the T probes against the models)") -.add_parameter("rawscores_zprobes_vs_tmodels", "array_like <float, 2D>", "ZT-Scores (raw scores of the Z probes against the T-models)") -.add_parameter("mask_zprobes_vs_tmodels_istruetrial", "array_like <float, 2D>", "") -.add_return("output","array_like <float, 2D>","The scores ZT Normalized"); -PyObject* PyBobLearnEM_ztNorm(PyObject*, PyObject* args, PyObject* kwargs) { - - char** kwlist = zt_norm.kwlist(0); - - PyBlitzArrayObject *rawscores_probes_vs_models_o, *rawscores_zprobes_vs_models_o, *rawscores_probes_vs_tmodels_o, - *rawscores_zprobes_vs_tmodels_o, *mask_zprobes_vs_tmodels_istruetrial_o=0; - - if (!PyArg_ParseTupleAndKeywords(args, kwargs, "O&O&O&O&|O&", kwlist, &PyBlitzArray_Converter, &rawscores_probes_vs_models_o, - &PyBlitzArray_Converter, &rawscores_zprobes_vs_models_o, - &PyBlitzArray_Converter, &rawscores_probes_vs_tmodels_o, - &PyBlitzArray_Converter, &rawscores_zprobes_vs_tmodels_o, - &PyBlitzArray_Converter, &mask_zprobes_vs_tmodels_istruetrial_o)){ - zt_norm.print_usage(); - return 0; - } - - // get the number of command line arguments - auto rawscores_probes_vs_models_ = make_safe(rawscores_probes_vs_models_o); - auto rawscores_zprobes_vs_models_ = make_safe(rawscores_zprobes_vs_models_o); - auto rawscores_probes_vs_tmodels_ = make_safe(rawscores_probes_vs_tmodels_o); - auto rawscores_zprobes_vs_tmodels_ = make_safe(rawscores_zprobes_vs_tmodels_o); - auto mask_zprobes_vs_tmodels_istruetrial_ = make_xsafe(mask_zprobes_vs_tmodels_istruetrial_o); - - blitz::Array<double,2> rawscores_probes_vs_models = *PyBlitzArrayCxx_AsBlitz<double,2>(rawscores_probes_vs_models_o); - blitz::Array<double,2> normalized_scores = blitz::Array<double,2>(rawscores_probes_vs_models.extent(0), rawscores_probes_vs_models.extent(1)); - - if(!mask_zprobes_vs_tmodels_istruetrial_o) - bob::learn::em::ztNorm(*PyBlitzArrayCxx_AsBlitz<double,2>(rawscores_probes_vs_models_o), - *PyBlitzArrayCxx_AsBlitz<double,2>(rawscores_zprobes_vs_models_o), - *PyBlitzArrayCxx_AsBlitz<double,2>(rawscores_probes_vs_tmodels_o), - *PyBlitzArrayCxx_AsBlitz<double,2>(rawscores_zprobes_vs_tmodels_o), - normalized_scores); - else - bob::learn::em::ztNorm(*PyBlitzArrayCxx_AsBlitz<double,2>(rawscores_probes_vs_models_o), - *PyBlitzArrayCxx_AsBlitz<double,2>(rawscores_zprobes_vs_models_o), - *PyBlitzArrayCxx_AsBlitz<double,2>(rawscores_probes_vs_tmodels_o), - *PyBlitzArrayCxx_AsBlitz<double,2>(rawscores_zprobes_vs_tmodels_o), - *PyBlitzArrayCxx_AsBlitz<bool,2>(mask_zprobes_vs_tmodels_istruetrial_o), - normalized_scores); - - return PyBlitzArrayCxx_AsConstNumpy(normalized_scores); -} - - - -/*** t_norm ***/ -bob::extension::FunctionDoc t_norm = bob::extension::FunctionDoc( - "tnorm", - "Normalise raw scores with :ref:`T-Norm <tnorm>`", - 0, - true -) -.add_prototype("rawscores_probes_vs_models,rawscores_probes_vs_tmodels", "output") -.add_parameter("rawscores_probes_vs_models", "array_like <float, 2D>", "Raw set of scores") -.add_parameter("rawscores_probes_vs_tmodels", "array_like <float, 2D>", "T-Scores (raw scores of the T probes against the models)") -.add_return("output","array_like <float, 2D>","The scores T Normalized"); -PyObject* PyBobLearnEM_tNorm(PyObject*, PyObject* args, PyObject* kwargs) { - - char** kwlist = t_norm.kwlist(0); - - PyBlitzArrayObject *rawscores_probes_vs_models_o, *rawscores_probes_vs_tmodels_o; - - if (!PyArg_ParseTupleAndKeywords(args, kwargs, "O&O&", kwlist, &PyBlitzArray_Converter, &rawscores_probes_vs_models_o, - &PyBlitzArray_Converter, &rawscores_probes_vs_tmodels_o)){ - t_norm.print_usage(); - return 0; - } - - auto rawscores_probes_vs_models_ = make_safe(rawscores_probes_vs_models_o); - auto rawscores_probes_vs_tmodels_ = make_safe(rawscores_probes_vs_tmodels_o); - - blitz::Array<double,2> rawscores_probes_vs_models = *PyBlitzArrayCxx_AsBlitz<double,2>(rawscores_probes_vs_models_o); - blitz::Array<double,2> normalized_scores = blitz::Array<double,2>(rawscores_probes_vs_models.extent(0), rawscores_probes_vs_models.extent(1)); - - bob::learn::em::tNorm(*PyBlitzArrayCxx_AsBlitz<double,2>(rawscores_probes_vs_models_o), - *PyBlitzArrayCxx_AsBlitz<double,2>(rawscores_probes_vs_tmodels_o), - normalized_scores); - - return PyBlitzArrayCxx_AsConstNumpy(normalized_scores); -} - - -/*** z_norm ***/ -bob::extension::FunctionDoc z_norm = bob::extension::FunctionDoc( - "znorm", - "Normalise raw scores with :ref:`Z-Norm <znorm>`", - 0, - true -) -.add_prototype("rawscores_probes_vs_models,rawscores_zprobes_vs_models", "output") -.add_parameter("rawscores_probes_vs_models", "array_like <float, 2D>", "Raw set of scores") -.add_parameter("rawscores_zprobes_vs_models", "array_like <float, 2D>", "Z-Scores (raw scores of the Z probes against the models)") -.add_return("output","array_like <float, 2D>","The scores Z Normalized"); -PyObject* PyBobLearnEM_zNorm(PyObject*, PyObject* args, PyObject* kwargs) { - - char** kwlist = z_norm.kwlist(0); - - PyBlitzArrayObject *rawscores_probes_vs_models_o, *rawscores_zprobes_vs_models_o; - - if (!PyArg_ParseTupleAndKeywords(args, kwargs, "O&O&", kwlist, &PyBlitzArray_Converter, &rawscores_probes_vs_models_o, - &PyBlitzArray_Converter, &rawscores_zprobes_vs_models_o)){ - z_norm.print_usage(); - return 0; - } - - auto rawscores_probes_vs_models_ = make_safe(rawscores_probes_vs_models_o); - auto rawscores_zprobes_vs_models_ = make_safe(rawscores_zprobes_vs_models_o); - - blitz::Array<double,2> rawscores_probes_vs_models = *PyBlitzArrayCxx_AsBlitz<double,2>(rawscores_probes_vs_models_o); - blitz::Array<double,2> normalized_scores = blitz::Array<double,2>(rawscores_probes_vs_models.extent(0), rawscores_probes_vs_models.extent(1)); - - bob::learn::em::zNorm(*PyBlitzArrayCxx_AsBlitz<double,2>(rawscores_probes_vs_models_o), - *PyBlitzArrayCxx_AsBlitz<double,2>(rawscores_zprobes_vs_models_o), - normalized_scores); - - return PyBlitzArrayCxx_AsConstNumpy(normalized_scores); -} - diff --git a/setup.py b/setup.py index 2d1961c436466a540601453ef6067ebfb6d3502b..3528a1dcc0624d904f58acbb179f938642fa315f 100644 --- a/setup.py +++ b/setup.py @@ -59,7 +59,6 @@ setup( "bob/learn/em/cpp/KMeansMachine.cpp", "bob/learn/em/cpp/LinearScoring.cpp", "bob/learn/em/cpp/PLDAMachine.cpp", - "bob/learn/em/cpp/ZTNorm.cpp", "bob/learn/em/cpp/FABase.cpp", "bob/learn/em/cpp/JFABase.cpp", @@ -114,8 +113,6 @@ setup( "bob/learn/em/plda_trainer.cpp", - "bob/learn/em/ztnorm.cpp", - "bob/learn/em/linear_scoring.cpp", "bob/learn/em/main.cpp",