// find the lowest energy component...
unsigned long findMinEnergyDistrib(MixtureGD &mixt)
{
  unsigned long distribCount = mixt.getDistribCount();
  unsigned long cmpMin=0;
  for (unsigned long c=1; c<distribCount; c++)
    if (mixt.getDistrib(c).getMean(0)<mixt.getDistrib(cmpMin).getMean(0))
      cmpMin=c;
  if (verbose) cout << "Lowest component["<<cmpMin<<"] Mean["<<mixt.getDistrib(cmpMin).getMean(0)<<
		 "] Cov["<<mixt.getDistrib(cmpMin).getCov(0)<<"] Weight["<<mixt.weight(cmpMin)<<"]"<<endl;
  return cmpMin; 
}	
//-------------------------------------------------------------------------
void W::writeMixtureGDRaw(const MixtureGD& m)
{
  unsigned long i;
  writeString("GD");
  writeUInt4(m.getId().length());
  writeString(m.getId());
  writeUInt4(m.getDistribCount());

  for (i=0; i< m.getDistribCount(); i++)
  {
    DistribGD& d = m.getDistrib(i);

    writeUInt4(d.dictIndex(K::k));
    writeDouble(m.weight(i));
  }
}
//-------------------------------------------------------------------------
void W::writeMixtureGDXml(const MixtureGD& m)
{
  unsigned long i;
  writeString("\n\t<MixtureGD");
  writeAttribute("id", m.getId());
  writeAttribute("distribCount", m.getDistribCount());
  writeString(">");

  for (i=0; i< m.getDistribCount(); i++)
  {
    DistribGD& d = m.getDistrib(i);
    writeString("\n\t\t<DistribGD");
    writeAttribute("i", i);
    writeAttribute("dictIdx", d.dictIndex(K::k));
    writeAttribute("weight", m.weight(i));
    writeString("/>");
  }
  writeString("\n\t</MixtureGD>");
}