00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
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
00065 #include "alizeString.h"
00066
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
00080
00081
00082
00083
00084
00085
00086
00087
00088 MixtureGF::MixtureGF(const MixtureGF& m)
00089 :Mixture(m._id, m.getDistribCount(), m._vectSize)
00090 {
00091
00092
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
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
00107
00108
00109
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
00129
00130
00131
00132
00133
00134 Mixture& MixtureGF::clone(DuplDistrib d) const
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
00156
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
00168
00169 return *this;
00170 }
00171
00172 DistribGF& MixtureGF::getDistrib(unsigned long i) const
00173 {
00174 return static_cast<DistribGF&>(Mixture::getDistrib(i));
00175
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