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