FrameAccGD.cpp

Go to the documentation of this file.
00001 /*
00002         This file is part of ALIZE which is an open-source tool for 
00003         speaker recognition.
00004 
00005     ALIZE is free software: you can redistribute it and/or modify
00006     it under the terms of the GNU Lesser General Public License as 
00007     published by the Free Software Foundation, either version 3 of 
00008     the License, or any later version.
00009 
00010     ALIZE is distributed in the hope that it will be useful,
00011     but WITHOUT ANY WARRANTY; without even the implied warranty of
00012     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013     GNU Lesser General Public License for more details.
00014 
00015     You should have received a copy of the GNU Lesser General Public 
00016     License along with ALIZE.
00017     If not, see <http://www.gnu.org/licenses/>.
00018         
00019         ALIZE is a development project initiated by the ELISA consortium
00020         [alize.univ-avignon.fr/] and funded by the French Research 
00021         Ministry in the framework of the TECHNOLANGUE program 
00022         [www.technolangue.net]
00023 
00024         The ALIZE project team wants to highlight the limits of voice
00025         authentication in a forensic context.
00026         The "Person  Authentification by Voice: A Need of Caution" paper 
00027         proposes a good overview of this point (cf. "Person  
00028         Authentification by Voice: A Need of Caution", Bonastre J.F., 
00029         Bimbot F., Boe L.J., Campbell J.P., Douglas D.A., Magrin-
00030         chagnolleau I., Eurospeech 2003, Genova].
00031         The conclusion of the paper of the paper is proposed bellow:
00032         [Currently, it is not possible to completely determine whether the 
00033         similarity between two recordings is due to the speaker or to other 
00034         factors, especially when: (a) the speaker does not cooperate, (b) there 
00035         is no control over recording equipment, (c) recording conditions are not 
00036         known, (d) one does not know whether the voice was disguised and, to a 
00037         lesser extent, (e) the linguistic content of the message is not 
00038         controlled. Caution and judgment must be exercised when applying speaker 
00039         recognition techniques, whether human or automatic, to account for these 
00040         uncontrolled factors. Under more constrained or calibrated situations, 
00041         or as an aid for investigative purposes, judicious application of these 
00042         techniques may be suitable, provided they are not considered as infallible.
00043         At the present time, there is no scientific process that enables one to 
00044         uniquely characterize a person=92s voice or to identify with absolute 
00045         certainty an individual from his or her voice.]
00046         Contact Jean-Francois Bonastre for more information about the licence or
00047         the use of ALIZE
00048 
00049         Copyright (C) 2003-2010
00050         Laboratoire d'informatique d'Avignon [lia.univ-avignon.fr]
00051         ALIZE admin [alize@univ-avignon.fr]
00052         Jean-Francois Bonastre [jean-francois.bonastre@univ-avignon.fr]
00053 */
00054 
00055 #if !defined(ALIZE_FrameAccGD_cpp)
00056 #define ALIZE_FrameAccGD_cpp
00057 
00058 #include "FrameAccGD.h"
00059 #include "Exception.h"
00060 #include "Feature.h"
00061 #include <new>
00062 #include <cmath>
00063 
00064 using namespace alize;
00065 typedef FrameAccGD A;
00066 
00067 //-------------------------------------------------------------------------
00068 A::FrameAccGD()
00069 :FrameAcc() {}
00070 //-------------------------------------------------------------------------
00071 FrameAccGD& A::create()
00072 {
00073   A* p = new (std::nothrow) A();
00074   assertMemoryIsAllocated(p, __FILE__, __LINE__);
00075   return *p;
00076 }
00077 //-------------------------------------------------------------------------
00078 A::FrameAccGD(const FrameAccGD& a)
00079 :FrameAcc() { copy(a); }
00080 //-------------------------------------------------------------------------
00081 const FrameAccGD& A::operator=(const FrameAccGD& a)
00082 { copy(a); return *this; }
00083 //-------------------------------------------------------------------------
00084 void A::copy(const FrameAccGD& a) // private
00085 {
00086   _vectSize = a._vectSize;
00087   _vectSizeDefined = a._vectSizeDefined;
00088   _count = a._count;
00089   _computed = a._computed;
00090   _stdComputed = a._stdComputed;
00091   _accVect = a._accVect;
00092   _meanVect = a._meanVect;
00093   _covVect = a._covVect;
00094   _stdVect = a._stdVect;
00095   _xaccVect = a._xaccVect;
00096 }
00097 //-------------------------------------------------------------------------
00098 const DoubleVector& A::getCovVect()
00099 {
00100   if (!_computed)
00101     computeAll();
00102   return _covVect;
00103 }
00104 //-------------------------------------------------------------------------
00105 const DoubleVector& A::getStdVect()
00106 {
00107   if (!_stdComputed)
00108   {
00109     if (!_computed)
00110       computeAll();
00111     _stdVect.setSize(_vectSize);
00112     double* stdVect = _stdVect.getArray();
00113     const double* covVect = _covVect.getArray();
00114     for (unsigned long i=0; i<_vectSize; i++)
00115       stdVect[i] = sqrt(covVect[i]);
00116     _stdComputed = true;
00117   }
00118   return _stdVect;
00119 }
00120 //-------------------------------------------------------------------------
00121 const DoubleVector& A::getxAccVect() const { return _xaccVect; }
00122 //-------------------------------------------------------------------------
00123 void A::accumulate(const Feature& f)
00124 {
00125   const unsigned long vectSize = f.getVectSize();
00126   if (!_vectSizeDefined)
00127   {
00128     _vectSize = vectSize;
00129     _accVect.setSize(_vectSize);
00130     _accVect.setAllValues(0.0);
00131     _xaccVect.setSize(_vectSize);
00132     _xaccVect.setAllValues(0.0);
00133     _vectSizeDefined = true;
00134   }
00135   else if (vectSize != _vectSize)
00136     throw Exception("Incompatible vectSize ("
00137           + String::valueOf(vectSize) + "/"
00138           + String::valueOf(_vectSize) + ")", __FILE__, __LINE__);
00139   const double* dataVect = f.getDataVector();
00140   for (unsigned long i=0; i<_vectSize; i++)
00141   {
00142     const double v = dataVect[i];
00143     _accVect[i] += v;
00144     _xaccVect[i] += v*v;
00145   }
00146   _count++;
00147   _computed = false;
00148   _stdComputed = false;
00149 }
00150 //-------------------------------------------------------------------------
00151 void A::add(const FrameAccGD& f)
00152 {
00153   const unsigned long vectSize = f.getVectSize();
00154   if (!_vectSizeDefined)
00155   {
00156     _vectSize = vectSize;
00157     _accVect.setSize(_vectSize);
00158     _accVect.setAllValues(0.0);
00159     _xaccVect.setSize(_vectSize);
00160     _xaccVect.setAllValues(0.0);
00161     _vectSizeDefined = true;
00162   }
00163   else if (vectSize != _vectSize)
00164     throw Exception("Incompatible vectSize ("
00165           + String::valueOf(vectSize) + "/"
00166           + String::valueOf(_vectSize) + ")", __FILE__, __LINE__);
00167 
00168   const DoubleVector& accVect =  f.getAccVect();
00169   const DoubleVector& xAccVect = f.getxAccVect();
00170 
00171   for(unsigned long i = 0; i<_vectSize; i++)
00172   {
00173     _accVect[i] += accVect[i];
00174     _xaccVect[i] += xAccVect[i];
00175   }
00176   _count += f.getCount();
00177   _computed = false;
00178   _stdComputed = false;
00179 }
00180 //-------------------------------------------------------------------------
00181 void A::deaccumulate(const Feature& f)
00182 {
00183   const unsigned long vectSize = f.getVectSize();
00184   if (!_vectSizeDefined)
00185   {
00186         return;
00187   }
00188   else if (vectSize != _vectSize)
00189     throw Exception("Incompatible vectSize ("
00190           + String::valueOf(vectSize) + "/"
00191           + String::valueOf(_vectSize) + ")", __FILE__, __LINE__);
00192 
00193   const double* dataVect = f.getDataVector();
00194 
00195   for (unsigned long i=0; i<_vectSize; i++)
00196   {
00197     const double v = dataVect[i];
00198     _accVect[i] -= v;
00199     _xaccVect[i] -= v*v;
00200   }
00201   _count--;
00202   _computed = false;
00203   _stdComputed = false;
00204 
00205 }
00206 //-------------------------------------------------------------------------
00207 void A::computeAll()
00208 {
00209   if (_count == 0)
00210     throw Exception("No frame accumulated", __FILE__, __LINE__);
00211   const double invCount = 1.0/(double)_count;
00212   const unsigned long vectSize = getVectSize();
00213   unsigned long i;  
00214   _meanVect.setSize(_vectSize);
00215   _covVect.setSize(vectSize);
00216   _stdVect.setSize(vectSize);
00217   const double* accVect = _accVect.getArray();
00218   const double* xaccVect = _xaccVect.getArray();
00219   double* meanVect = _meanVect.getArray();
00220   double* covVect = _covVect.getArray();
00221   for (i=0; i<vectSize; i++)
00222   {
00223     const double mean = accVect[i]*invCount;
00224     meanVect[i] = mean;
00225     covVect[i] = xaccVect[i]*invCount - mean*mean;
00226   }
00227 
00228    // compute det --------------------------------
00229 
00230   _det = 1.0;
00231   for (i=0; i< _vectSize; i++)
00232   {
00233      _det *= covVect[i];
00234   }
00235 
00236   // compute cst -------------------------------
00237 
00238   if (_det > EPS_LK)
00239     _cst = 1.0 / ( pow(_det, 0.5) * pow( PI2 , _vectSize/2.0 ) );
00240   else
00241     _cst = 1.0 / ( pow(EPS_LK, 0.5) * pow( PI2 , _vectSize/2.0 ) );
00242 
00243   _computed = true;
00244 }
00245 //-------------------------------------------------------------------------
00246 String A::getClassName() const { return "FrameAccGD"; }
00247 //-------------------------------------------------------------------------
00248 A::~FrameAccGD() {}
00249 //-------------------------------------------------------------------------
00250 
00251 #endif // !defined(ALIZE_FrameAccGD_cpp)
00252