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_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
00065 #include "alizeString.h"
00066
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
00081
00082
00083
00084
00085
00086
00087
00088
00089 MixtureGD::MixtureGD(const MixtureGD& m)
00090 :Mixture(m._id, m.getDistribCount(), m._vectSize)
00091 {
00092
00093
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
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
00108
00109
00110
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
00130
00131
00132
00133
00134
00135 Mixture& MixtureGD::clone(DuplDistrib d) const
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
00157
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
00169
00170 return *this;
00171 }
00172
00173 DistribGD& MixtureGD::getDistrib(unsigned long i) const
00174 {
00175 return static_cast<DistribGD&>(Mixture::getDistrib(i));
00176
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