⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 mm_02.cc

📁 这是一个从音频信号里提取特征参量的程序
💻 CC
📖 第 1 页 / 共 2 页
字号:
// file: $isip/class/stats/MixtureModel/mm_02.cc// version: $Id: mm_02.cc,v 1.5 2002/07/05 21:16:25 parihar Exp $//// isip include files//#include "MixtureModel.h"#include <Console.h>#include <GaussianModel.h>// method: diagnose//// arguments://  Integral::DEBUG level: (input) debug level for diagnostics//// return: a boolean value indicating status//// this is the diagnose method//boolean MixtureModel::diagnose(Integral::DEBUG level_a) {  //---------------------------------------------------------------------------  //  // 0. preliminaries  //  //---------------------------------------------------------------------------  // output the class name  //  if (level_a > Integral::NONE) {    SysString output(L"diagnosing class ");    output.concat(CLASS_NAME);    output.concat(L": ");    Console::put(output);    Console::increaseIndention();  }    //--------------------------------------------------------------------------  //  // 1. required public methods  //  //--------------------------------------------------------------------------  // set indentation  //  if (level_a > Integral::NONE) {    Console::put(L"testing required public methods...\n");    Console::increaseIndention();  }  // create data to test with  //  VectorFloat mean0(L"1, 2, 3");  VectorFloat mean1(L"7, 8, 9");  MatrixFloat covar0(3, 3, L"4, 5, 6", Integral::DIAGONAL);  MatrixFloat covar1(3, 3, L"10, 11, 12", Integral::DIAGONAL);    GaussianModel gauss0;  GaussianModel gauss1;  gauss0.setMean(mean0);  gauss0.setCovariance(covar0);  gauss1.setMean(mean1);  gauss1.setCovariance(covar1);  VectorFloat mix_weights(L"2, 4");    // do a quick test of constructors, destructors, and memory management  // methods  //  MixtureModel::setGrowSize(5);  MixtureModel* mix0 = new MixtureModel(NONE);  MixtureModel* mix1 = new MixtureModel(*mix0);  MixtureModel* mix2 = new MixtureModel[10];      // clear the pointers  //  delete mix0;  delete mix1;  delete [] mix2;  // set the internal data of a mixture model  //  mix0 = new MixtureModel(NONE);  mix0->add(gauss0);  mix0->add(gauss1);    mix0->setWeights(mix_weights);  mix1 = new MixtureModel(*mix0);  // test the eq method  //  if (!mix1->eq(*mix0)) {    mix0->debug(L"expected model");    mix1->debug(L"actual model");    return Error::handle(name(), L"eq", Error::TEST, __FILE__, __LINE__);  }  // test the clear method  //  mix0->clear();  if (mix1->eq(*mix0)) {    mix0->debug(L"mix0 not clear");    return Error::handle(name(), L"clear", Error::TEST, __FILE__, __LINE__);  }    // test the operator= method  //  *mix0 = *mix1;  if (!mix1->eq(*mix0)) {    mix1->debug(L"expected model");    mix0->debug(L"actual model");    return Error::handle(name(), L"operator=", Error::TEST, __FILE__,			 __LINE__);  }    // clear the pointers  //  delete mix0;  delete mix1;  // test the i/o methods  //  MixtureModel mix3;  MixtureModel mix4;  MixtureModel mix5;  MixtureModel mix6;  mix3.setMode(NONE);  mix6.setMode(NONE);  mix3.add(gauss0);  mix3.add(gauss1);  mix3.setWeights(mix_weights);    mix4.add(gauss0);  mix4.add(gauss1);  mix4.setWeights(mix_weights);    // we need binary and text sof files  //  String tmp_filename0;  Integral::makeTemp(tmp_filename0);  String tmp_filename1;  Integral::makeTemp(tmp_filename1);  // open files in write mode  //  Sof tmp_file0;  tmp_file0.open(tmp_filename0, File::WRITE_ONLY, File::TEXT);  Sof tmp_file1;  tmp_file1.open(tmp_filename1, File::WRITE_ONLY, File::BINARY);  if (!mix3.write(tmp_file0, (long)0)) {    return Error::handle(name(), L"write", Error::TEST, __FILE__, __LINE__);  };    if (!mix4.write(tmp_file0, (long)1)) {    return Error::handle(name(), L"write", Error::TEST, __FILE__, __LINE__);  };    if (!mix3.write(tmp_file1, (long)0)) {    return Error::handle(name(), L"write", Error::TEST, __FILE__, __LINE__);  };    if (!mix4.write(tmp_file1, (long)1)) {    return Error::handle(name(), L"write", Error::TEST, __FILE__, __LINE__);  };    // close the files  //  tmp_file0.close();  tmp_file1.close();  // open the files in read mode  //  tmp_file0.open(tmp_filename0);  tmp_file1.open(tmp_filename1);  // read the model written in PRE_COMPUTE mode back in  //  mix5.read(tmp_file0, (long)0);  mix6.read(tmp_file0, (long)0);  if (!mix5.eq(mix3) || !mix6.eq(mix3)) {    mix3.debug(L"expected Mixture");    mix5.debug(L"mix5 actual");    mix6.debug(L"mix6 actual");    return Error::handle(name(), L"read", Error::TEST, __FILE__, __LINE__);  }  // read the model written in NONE mode back in  //  mix5.clear();  mix6.clear();  mix5.read(tmp_file0, (long)1);  mix6.read(tmp_file0, (long)1);  if (!mix5.eq(mix4) || !mix6.eq(mix4)) {    mix4.debug(L"expected Mixture");    mix5.debug(L"mix5 actual");    mix6.debug(L"mix6 actual");    return Error::handle(name(), L"read", Error::TEST, __FILE__, __LINE__);  }  // now read the binary files for NONE mode  //  mix5.clear();  mix6.clear();  mix5.read(tmp_file1, (long)0);  mix6.read(tmp_file1, (long)0);  if (!mix5.eq(mix3) || !mix6.eq(mix3)) {    mix3.debug(L"expected Mixture");    mix5.debug(L"mix5 actual");    mix6.debug(L"mix6 actual");    return Error::handle(name(), L"read", Error::TEST, __FILE__, __LINE__);  }  // and read the PRE_COMPUTE model from the binary file  //  mix5.clear();  mix6.clear();  mix5.read(tmp_file1, (long)1);  mix6.read(tmp_file1, (long)1);  if (!mix5.eq(mix4) || !mix6.eq(mix4)) {    mix4.debug(L"expected Mixture");    mix5.debug(L"mix5 actual");    mix6.debug(L"mix6 actual");    return Error::handle(name(), L"read", Error::TEST, __FILE__, __LINE__);  }  // close and  delete the temporary files  //  tmp_file0.close();  tmp_file1.close();    // reset indentation  //  if (level_a > Integral::NONE) {    Console::decreaseIndention();  }  //---------------------------------------------------------------------------  //  // 2. class-specific public methods:  //     extensions to required methods       //  //---------------------------------------------------------------------------  // set indentation  //  if (level_a > Integral::NONE) {    Console::put(L"testing class-specific public methods: extensions to required methods...\n");    Console::increaseIndention();  }  // test the virtual eq and assign methods  //  MixtureModel mix7;  mix7.assign((StatisticalModelBase&)mix3);  if (!mix7.eq((StatisticalModelBase&)mix3)) {    mix3.debug(L"expected mixture");    mix7.debug(L"actual mixture");    return Error::handle(name(), L"assign/eq", Error::TEST, __FILE__,			 __LINE__);  }

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -