MixtureGD.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_MixtureGD_cpp)
00056 #define ALIZE_MixtureGD_cpp
00057 
00058 #include <new>
00059 #include "MixtureGD.h"
00060 #include "DistribGD.h"
00061 #include "Exception.h"
00062 #include "MixtureStat.h"
00063 #include "MixtureGDStat.h"
00064 //#include "Config.h"
00065 #include "alizeString.h"
00066 //#include <iostream>
00067 #include "StatServer.h"
00068 
00069 using namespace alize;
00070 
00071 //-------------------------------------------------------------------------
00072 MixtureGD::MixtureGD(const String& id, unsigned long vs, unsigned long dc)
00073 :Mixture(id, dc, vs)
00074 {
00075   for (unsigned long c=0; c<dc; c++)
00076   { Mixture::addDistrib(K::k, DistribGD::create(K::k, _vectSize)); }
00077   equalizeWeights();
00078 }
00079 //-------------------------------------------------------------------------
00080 /*MixtureGD::MixtureGD(const Config& c)
00081 :Mixture("", c.getParam_mixtureDistribCount()),
00082  _vectSize(c.getParam_vectSize())
00083 {
00084   for (unsigned long i=0; i<c.getParam_mixtureDistribCount(); i++)
00085     Mixture::addDistrib(DistribGD::create(c));
00086   equalizeWeights();
00087 }*/
00088 //-------------------------------------------------------------------------
00089 MixtureGD::MixtureGD(const MixtureGD& m)
00090 :Mixture(m._id, m.getDistribCount(), m._vectSize)
00091 {
00092   // Attention : les distributions ne sont pas copiees, la copie pointe sur
00093   // les mêmes distributions que l'original <FRANCAIS>
00094   unsigned long n = m.getDistribCount();
00095   for (unsigned long i=0; i< n; i++)
00096   { Mixture::addDistrib(K::k, m.getDistrib(i), m.weight(i)); }
00097 }
00098 //-------------------------------------------------------------------------
00099 bool MixtureGD::operator==(const Mixture& m) const
00100 {
00101   // ** ne compare pas les id qui sont propres a chaque mixture **
00102   if (dynamic_cast<const MixtureGD*>(&m) == NULL)
00103     return false;
00104   const unsigned long n = getDistribCount();
00105   if (n != m.getDistribCount())
00106     return false;
00107   /*for (unsigned j=0; j<n; j++)
00108   {
00109     std::cout << getDistrib(j).toString() << std::endl;
00110     std::cout << m.getDistrib(j).toString() << std::endl;
00111   }*/
00112       
00113   for (unsigned i=0; i<n; i++)
00114   {
00115     if (weight(i) != m.weight(i) || getDistrib(i) != m.getDistrib(i))
00116       return false;
00117   }
00118   return true;
00119 }
00120 //-------------------------------------------------------------------------
00121 MixtureGD& MixtureGD::create(const K&, const String& id,
00122             unsigned long vectSize, unsigned long distribCount)
00123 {
00124   MixtureGD* p = new (std::nothrow) MixtureGD(id, vectSize, distribCount);
00125   assertMemoryIsAllocated(p, __FILE__, __LINE__);
00126   return *p;
00127 }
00128 //-------------------------------------------------------------------------
00129 /*MixtureGD& MixtureGD::create(const Config& c)
00130 {
00131   return create("", c.getParam_mixtureDistribCount(),
00132             c.getParam_vectSize());
00133 }*/
00134 //-------------------------------------------------------------------------
00135 Mixture& MixtureGD::clone(DuplDistrib d) const // private
00136 {
00137   MixtureGD* p = new (std::nothrow) MixtureGD(*this);
00138   assertMemoryIsAllocated(p, __FILE__, __LINE__);
00139   if (d == DUPL_DISTRIB)
00140   {
00141     const unsigned long n = getDistribCount();
00142     for (unsigned long c=0; c<n; c++)
00143     { p->setDistrib(K::k, getDistrib(c).duplicate(K::k), c); }
00144   }
00145   return *p;
00146 }
00147 //-------------------------------------------------------------------------
00148 MixtureGD& MixtureGD::duplicate(const K&, DuplDistrib d) const
00149 {
00150   return static_cast<MixtureGD&>(clone(d));
00151 }
00152 //-------------------------------------------------------------------------
00153 MixtureGD& MixtureGD::operator=(const MixtureGD& m)
00154 {
00155   assign(m);
00156   // assign can throw Exception if the number of distributions is
00157   // different or if the vectSize is different
00158   return *this;
00159 }
00160 //-------------------------------------------------------------------------
00161 Mixture& MixtureGD::operator=(const Mixture& m)
00162 {
00163   const MixtureGD* p = dynamic_cast<const MixtureGD*>(&m);
00164   if (p == NULL)
00165     throw Exception("the mixture source is not a mixture GD",
00166             __FILE__, __LINE__);
00167   assign(m);
00168   // assign can throw Exception if the number of distributions is
00169   // different or if the vectSize is different
00170   return *this;
00171 }
00172 //-------------------------------------------------------------------------
00173 DistribGD& MixtureGD::getDistrib(unsigned long i) const
00174 {
00175   return static_cast<DistribGD&>(Mixture::getDistrib(i));
00176   // can throw IndexOutOfBoundsException
00177 }
00178 //-------------------------------------------------------------------------
00179 void MixtureGD::setDistrib(const K&, DistribGD& d, unsigned long i)
00180 {
00181   if (d.getVectSize() != _vectSize)
00182     throw Exception("mixture vectSize (" + String::valueOf(_vectSize)
00183             + ") <> distrib vectSize ("
00184             + String::valueOf(d.getVectSize()) + ")",
00185             __FILE__, __LINE__);
00186   Mixture::setDistrib(K::k, d, i);
00187 }
00188 //-------------------------------------------------------------------------
00189 void MixtureGD::setDistrib(const K&, Distrib& d, unsigned long i)
00190 {
00191   DistribGD* p = dynamic_cast<DistribGD*>(&d);
00192   if (p == NULL)
00193     throw Exception("incompatibility mixture type / distribution type",
00194             __FILE__, __LINE__);
00195   MixtureGD::setDistrib(K::k, *p, i);
00196 }
00197 //-------------------------------------------------------------------------
00198 void MixtureGD::addDistrib(const K&, DistribGD& d, weight_t w)
00199 {
00200   if (d.getVectSize() != _vectSize)
00201     throw Exception("mixture vectSize (" + String::valueOf(_vectSize)
00202             + ") <> distrib vectSize ("
00203             + String::valueOf(d.getVectSize()) + ")",
00204             __FILE__, __LINE__);
00205   Mixture::addDistrib(K::k, d, w);
00206 }
00207 //-------------------------------------------------------------------------
00208 void MixtureGD::addDistrib(const K&, Distrib& d, weight_t w)
00209 {
00210   DistribGD* p = dynamic_cast<DistribGD*>(&d);
00211   if (p == NULL)
00212     throw Exception("incompatibility mixture/distribution",
00213             __FILE__, __LINE__);
00214   MixtureGD::addDistrib(K::k, *p, w);
00215 }
00216 //-------------------------------------------------------------------------
00217 MixtureStat& MixtureGD::createNewMixtureStatObject(const K&,
00218                                     StatServer& ss, const Config& c) const
00219 { return MixtureGDStat::create(K::k, ss, *this, c); }
00220 //-------------------------------------------------------------------------
00221 DistribType MixtureGD::getType() const { return DistribType_GD; }
00222 //-------------------------------------------------------------------------
00223 String MixtureGD::getClassName() const { return "MixtureGD"; }
00224 //-------------------------------------------------------------------------
00225 String MixtureGD::toString() const
00226 {
00227   String s = Object::toString()
00228     + "\n  id      = '" + _id + "'"
00229     + "\n  distribCount  = " + String::valueOf(getDistribCount())
00230     + "\n  vectSize    = " + String::valueOf(_vectSize);
00231   for (unsigned long i=0; i<getDistribCount(); i++)
00232   {
00233     s += "\n  weight[" + String::valueOf(i) + "] = "
00234       + String::valueOf(weight(i))
00235       + "  distrib[" + String::valueOf(i) + "] = [ "
00236       + getDistrib(i).getClassName()
00237       + " " + getDistrib(i).getAddress() + " ]";
00238   }
00239   return s;
00240 }
00241 //-------------------------------------------------------------------------
00242 MixtureGD::~MixtureGD() {}
00243 //-------------------------------------------------------------------------
00244 
00245 #endif // !defined(ALIZE_MixtureGD_cpp)
00246