sm_02.cc

来自「这是一个从音频信号里提取特征参量的程序」· CC 代码 · 共 486 行 · 第 1/2 页

CC
486 行
字号
// file: $isip/class/stat/StatisticalModel/sm_02.cc// version: $Id: sm_02.cc,v 1.8 2002/10/26 19:45:52 jelinek Exp $//// isip include files//#include "StatisticalModel.h"#include <Console.h>#include <GaussianModel.h>#include <MixtureModel.h>#include <SupportVectorModel.h>// method: diagnose//// arguments://  Integral::DEBUG level: (input) debug level for diagnostics//// return: a boolean value indicating status//// this is the diagnose method//boolean StatisticalModel::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 for testing of Gaussian model  //  VectorFloat test_mean(L"1, 2, 3");  MatrixFloat test_covar(3, 3, L"1, 2, 3", Integral::DIAGONAL);  // create data for testing of support vector model  //  Vector<VectorFloat> support_vectors(3);  support_vectors(0) = (L"1, 2, 3");  support_vectors(1) = (L"4, 5, 6");  support_vectors(2) = (L"7, 8, 9");  VectorFloat alphas(L"0.4, 0.1, 0.5");  VectorFloat kernel_constants(L"0.3");  Kernel::ALGORITHM kernel_algorithm = Kernel::RBF;    // test constructors  //  StatisticalModel stat0(GAUSSIAN_MODEL);  GaussianModel gaus0;  gaus0.setMean(test_mean);  gaus0.setCovariance(test_covar);  StatisticalModel stat00(SUPPORT_VECTOR_MODEL);  SupportVectorModel svm0;  svm0.setNumSupportVectors(3);  for (long i = 0; i < 3; i++) {    svm0.getSupportVector(i) = support_vectors(i);    svm0.getAlpha(i) = alphas(i);  }  svm0.getKernel(0).setAlgorithm(kernel_algorithm);  svm0.getKernel(0).setConstants(kernel_constants);    // test the interface assign method  //  stat0.assign(gaus0);  stat00.assign(svm0);  // test the interface eq method  //  if (!stat0.eq(gaus0)) {    return Error::handle(name(), L"assign/eq gauss", Error::TEST, __FILE__,			 __LINE__);  }  if (!stat00.eq(svm0)) {    return Error::handle(name(), L"assign/eq svm", Error::TEST, __FILE__,			 __LINE__);  }    // test the copy constructor and the required eq method  //  StatisticalModel stat1(stat0);  if (!stat1.eq(gaus0) || !stat1.eq(stat0)) {    return Error::handle(name(), L"copy constructor gauss",			 Error::TEST, __FILE__, __LINE__);  }  StatisticalModel stat11(stat00);  if (!stat11.eq(svm0) || !stat11.eq(stat00)) {    return Error::handle(name(), L"copy constructor",			 Error::TEST, __FILE__, __LINE__);  }    // test the setDebug method  //  setDebug(debug_level_d);  // test the clear method  //  stat1.clear();  if (stat1.virtual_model_d != (StatisticalModelBase*)&NO_STAT_MODEL) {    return Error::handle(name(), L"clear - gauss", Error::TEST, __FILE__,			 __LINE__);  }  stat11.clear();  if (stat11.virtual_model_d != (StatisticalModelBase*)&NO_STAT_MODEL) {    return Error::handle(name(), L"clear - svm", Error::TEST, __FILE__,			 __LINE__);  }    // test the operator= method  //  stat1 = stat0;  if (!stat1.eq(gaus0) || !stat1.eq(stat0)) {    return Error::handle(name(), L"operator= gauss", Error::TEST, __FILE__,			 __LINE__);  }  stat11 = stat00;  if (!stat11.eq(svm0) || !stat11.eq(stat00)) {    return Error::handle(name(), L"operator= svm", Error::TEST, __FILE__,			 __LINE__);  }    // test the memory management methods  //  StatisticalModel::setGrowSize(5);  StatisticalModel* stat_ptr0 = new StatisticalModel[10];  StatisticalModel* stat_ptr1 = new StatisticalModel(GAUSSIAN_MODEL);  StatisticalModel* stat_ptr2 = new StatisticalModel(SUPPORT_VECTOR_MODEL);  StatisticalModel* stat_ptr3 = new StatisticalModel[10](GAUSSIAN_MODEL);  StatisticalModel* stat_ptr4 = new StatisticalModel[10](SUPPORT_VECTOR_MODEL);  delete [] stat_ptr0;  delete stat_ptr1;  delete stat_ptr2;  delete [] stat_ptr3;  delete [] stat_ptr4;  // test the i/o methods  //  StatisticalModel write_gauss(GAUSSIAN_MODEL);  write_gauss.assign(gaus0);  StatisticalModel write_svm(GAUSSIAN_MODEL); // it works anyway  write_svm.assign(svm0);  // create two models to read with  //  StatisticalModel read_text;  StatisticalModel read_bin;  StatisticalModel read_text_svm;  StatisticalModel read_bin_svm;  // we need binary and text sof files  //  String tmp_filename0;  Integral::makeTemp(tmp_filename0);  String tmp_filename1;  Integral::makeTemp(tmp_filename1);  String tmp_filename2;  Integral::makeTemp(tmp_filename2);  String tmp_filename3;  Integral::makeTemp(tmp_filename3);  // 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);  Sof tmp_file2;  tmp_file2.open(tmp_filename2, File::WRITE_ONLY, File::TEXT);  Sof tmp_file3;  tmp_file3.open(tmp_filename3, File::WRITE_ONLY, File::BINARY);  write_gauss.write(tmp_file0, 0);  write_gauss.write(tmp_file1, 0);  write_svm.write(tmp_file2, 0);  write_svm.write(tmp_file3, 0);    // close the files  //  tmp_file0.close();  tmp_file1.close();  tmp_file2.close();  tmp_file3.close();  // open the files in read mode  //  tmp_file0.open(tmp_filename0);  tmp_file1.open(tmp_filename1);  tmp_file2.open(tmp_filename2);  tmp_file3.open(tmp_filename3);  // read the value back  //  read_text.read(tmp_file0, 0);  if (!read_text.eq(write_gauss)) {    read_text.debug(L"read_text");    write_gauss.debug(L"write_gauss");    return Error::handle(name(), L"read", Error::TEST, __FILE__, __LINE__);  }  read_bin.read(tmp_file1, 0);  if (!read_bin.eq(write_gauss)) {    read_bin.debug(L"read_bin");    write_gauss.debug(L"write_gauss");    return Error::handle(name(), L"read", Error::TEST, __FILE__, __LINE__);  }  read_text_svm.read(tmp_file2, 0);  if (!read_text_svm.eq(write_svm)) {    read_text.debug(L"read_text_svm");    write_svm.debug(L"write_svm");    return Error::handle(name(), L"read", Error::TEST, __FILE__, __LINE__);  }  read_bin_svm.read(tmp_file3, 0);  if (!read_bin_svm.eq(write_svm)) {    read_bin_svm.debug(L"read_bin_svm");    write_svm.debug(L"write_svm");    return Error::handle(name(), L"read", Error::TEST, __FILE__, __LINE__);  }

⌨️ 快捷键说明

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