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

📄 math_02.cc

📁 这是一个从音频信号里提取特征参量的程序
💻 CC
📖 第 1 页 / 共 5 页
字号:
  }    // test Y = [ {X1* X2 + log(X3)} / exp(X4)]  //  if (level_a > Integral::BRIEF) {    Console::put(L"\n\ttesting for Y = [ {X1* X2 + log(X3)} / exp(X4)]:\n");  }  math6.setWeight(L"1.0, 1.0, 1.0, 1.0");  values_op(0).assign((long)ASSIGN);  values_op(1).assign((long)MULTIPLY);  values_op(2).assign((long)ADD);  values_op(3).assign((long)DIVIDE);  math6.setOperation(values_op);    input(0).makeVectorFloat().assign(L"1.1, 4.0");  input(1).makeVectorFloat().assign(L"1.5, 2.3");  input(2).makeVectorFloat().assign(L"1.0, 1.0");  input(3).makeVectorFloat().assign(L"0.0, 0.0");  math6.compute(output, input);  result.assign(L"1.65, 9.2");  if (!result.almostEqual(output.getVectorFloat())) {    output.debug(L"output");    return Error::handle(name(), L"compute", Error::TEST,                         __FILE__, __LINE__);  }  // test Y = square(X1) + 2.0 * sqrt(X2) + 3.0  //  if (level_a > Integral::BRIEF) {    Console::put(L"\n\ttesting for Y = [square(X1) + 2.0 * sqrt(X2) + 3.0]:\n");  }  values.setLength(2);  values(0).assign((long)SQUARE);  values(1).assign((long)SQRT);  math6.setNumOperands(2);  math6.setWeight(L"1.0, 2.0");  str.assign(L"ASSIGN, ADD");  math6.setOperation(str);  math6.setFunction(values);  math6.setConstant(3.0);  input.setLength(2);  input(0).makeVectorFloat().assign(L"1.1, 4.0, 1.5, 2.3");  input(1).makeVectorFloat().assign(L"4.0, 1.21, 4.0, 9.0");  math6.compute(output, input);  result.assign(L"8.21, 21.2, 9.25, 14.29");  if (!result.almostEqual(output.getVectorFloat())) {    output.debug(L"output");    return Error::handle(name(), L"compute", Error::TEST,                         __FILE__, __LINE__);  }  // test Y = 2.0 * X1^2 + 3.0 * X2 + 3.0  //  if (level_a > Integral::BRIEF) {    Console::put(L"\n\ttesting for Y = [2.0 * X1^2 + 3.0 * X2 + 3.0]:\n");  }  values.setLength(2);  values(0).assign((long)SQUARE);  values(1).assign((long)IDENTITY);  math6.setNumOperands(2);  math6.setWeight(L"2.0, 3.0");  str.assign(L"ASSIGN, ADD");  math6.setOperation(str);  math6.setFunction(values);  input(0).makeVectorFloat().assign(L"1.1, 4.0, 1.5, 1.1");  input(1).makeVectorFloat().assign(L"4.0, 0.5, 4.0, 9.0");   math6.compute(output, input);  result.assign(L"17.42, 36.5, 19.5, 32.42");  if (!result.almostEqual(output.getVectorFloat())) {    output.debug(L"output");    return Error::handle(name(), L"compute", Error::TEST,                         __FILE__, __LINE__);  }    // test Y = X1 * X2 (vector * matrix)  //  if (level_a > Integral::BRIEF) {    Console::put(L"\n\ttesting for Y = [X1 * X2 (vector * matrix)]:\n");  }    input(0).makeVectorFloat().assign(L"1.1, 2.0, 3.0");  input(1).makeMatrixFloat().assign(3, 3, L"1.0, 0.0, 5.0, 1.2, 2.4, 3.6, 1.8, 2.1, 9.8");  values(0).assign((long)IDENTITY);  values(1).assign((long)IDENTITY);  values_op.setLength(2);  values_op(0).assign((long)ASSIGN);  values_op(1).assign((long)MULTIPLY);  math6.setOperation(values_op);  math6.setFunction(values);  math6.setWeight(L"1.0, 1.0");  math6.setConstant(0.0);  math6.compute(output, input);    result.assign(L"8.9, 11.1, 42.1");    if (!(result).almostEqual(output.getVectorFloat())) {    output.debug(L"output");    return Error::handle(name(), L"apply", Error::TEST,			 __FILE__, __LINE__);  }  // test Y = X1 * X2 (vector * inv(matrix))  //    values(0).assign((long)IDENTITY);  values(1).assign((long)INVERSE);  values_op.setLength(2);  values_op(0).assign((long)ASSIGN);  values_op(1).assign((long)MULTIPLY);  math6.setOperation(values_op);  math6.setFunction(values);  math6.setWeight(L"1.0, 1.0");  math6.setConstant(0.0);  math6.compute(output, input);    result.assign(L"0.2293, 0.9842, -0.1724");    if (!(result).almostEqual(output.getVectorFloat())) {    output.debug(L"output");    return Error::handle(name(), L"apply", Error::TEST,			 __FILE__, __LINE__);  }  // test Y = X1 * X2 (vector * matrix) with vector of  zeros and constants  //  if (level_a > Integral::BRIEF) {    Console::put(L"\n\ttesting for Y = [X1 * X2 (vector * matrix)] with vector of zeros and constants:\n");  }    // test vector of zeros  //  input(0).makeVectorFloat().assign(L"0.0, 0.0, 0.0");  input(1).makeMatrixFloat().assign(3, 3, L"1.0, 0.0, 5.0, 1.2, 2.4, 3.6, 1.8, 2.1, 9.8");  values(0).assign((long)IDENTITY);  values(1).assign((long)IDENTITY);  values_op.setLength(2);  values_op(0).assign((long)ASSIGN);  values_op(1).assign((long)MULTIPLY);  math6.setOperation(values_op);  math6.setFunction(values);  math6.setWeight(L"1.0, 1.0");  math6.setConstant(0.0);  math6.compute(output, input);    result.assign(L"0.0, 0.0, 0.0");    if (!(result).almostEqual(output.getVectorFloat())) {    output.debug(L"output");    return Error::handle(name(), L"apply", Error::TEST,                         __FILE__, __LINE__);  }  //test matrix of zeros  //  input(0).makeVectorFloat().assign(L"1.0, 1.0, 1.0");  input(1).makeMatrixFloat().assign(3, 3, L"0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0");  values(0).assign((long)IDENTITY);  values(1).assign((long)IDENTITY);  values_op.setLength(2);  values_op(0).assign((long)ASSIGN);  values_op(1).assign((long)MULTIPLY);  math6.setOperation(values_op);  math6.setFunction(values);  math6.setWeight(L"1.0, 1.0");  math6.setConstant(0.0);  math6.compute(output, input);    result.assign(L"0.0, 0.0, 0.0");    if (!(result).almostEqual(output.getVectorFloat())) {    output.debug(L"output");    return Error::handle(name(), L"apply", Error::TEST,                         __FILE__, __LINE__);  }    // test Y = X1 + X2 * X3' + inv(x4)  //  (matrix + matrix * trans(matrix) + inv(matrix))  //  if (level_a > Integral::BRIEF) {    Console::put(L"\n\ttesting for Y = [X1 + X2 * X3' + inv(x4)] (matrix + matrix * trans(matrix) + inv(matrix)):\n");  }  values.setLength(4);  values_op.setLength(4);  values(0).assign((long)IDENTITY);  values(1).assign((long)IDENTITY);  values(2).assign((long)TRANSPOSE);  values(3).assign((long)INVERSE);    values_op(0).assign((long)ASSIGN);  values_op(1).assign((long)ADD);  values_op(2).assign((long)MULTIPLY);  values_op(3).assign((long)ADD);  math6.setNumOperands(4);  math6.setOperation(values_op);  math6.setFunction(values);  math6.setWeight(L"1.0, 1.0, 1.0, 1.0");  math6.setConstant(0.0);  input.setLength(4);  input(0).makeMatrixFloat().assign(3, 3, L"1.0, 0.0, 5.0, 1.2, 2.4, 3.6, 1.8, 2.1, 9.8");  input(1).makeMatrixFloat().assign(3, 3, L"2.0, 2.1, 3.2, 1.1, 2.1, 3.2, 4.2, 5.1, 1.1");  input(2).makeMatrixFloat().assign(3, 3, L"1, 2, 3, 3, 2, 1, 2, 1, 1");  input(3).makeMatrixFloat().assign(3, 3, L"5.1, 2.1, 2.2, 1.0, 1.0, 2.2, 2.1, 1.1, 2.1");  MatrixFloat result_mat;  math6.compute(output, input);    result_mat.assign(3, 3, L"31.5808, 20.0370, 17.9575, 33.4260, 26.8712, 9.7219, 52.4151, 42.4781, 32.1548");    if (!(result_mat).almostEqual(output.getMatrixFloat())) {    output.debug(L"output");    result_mat.debug(L"result");    return Error::handle(name(), L"apply", Error::TEST,                         __FILE__, __LINE__);  }    // test scalar addition  //  if (level_a > Integral::BRIEF) {    Console::put(L"\n\ttesting  scalar addition (1):\n");  }  input.setLength(2);  input(0).makeVectorFloat().assign(L"4.0");  input(1).makeVectorFloat().assign(L"1.0, 2.0, 3.0, 4.0");  Math math7;  values.setLength(2);  values(0).assign((long)IDENTITY);  values(1).assign((long)IDENTITY);  values_op.setLength(2);  values_op(0).assign((long)ASSIGN);  values_op(1).assign((long)ADD);  math7.setFunction(values);  math7.setOperation(values_op);  math7.compute(output, input);  VectorFloat expected(L"5.0, 6.0, 7.0, 8.0");  if (!output.getVectorFloat().almostEqual(expected)) {    output.debug(L"output");    expected.debug(L"expected result");    return Error::handle(name(), L"compute", Error::TEST, __FILE__, __LINE__);  }  if (level_a > Integral::BRIEF) {    Console::put(L"\n\ttesting  scalar addition (2):\n");  }  input(0).makeVectorFloat().assign(L"1.0, 2.0, 3.0, 4.0");  input(1).makeVectorFloat().assign(L"4.0");  math7.compute(output, input);  expected.assign(L"5.0, 6.0, 7.0, 8.0");  if (!output.getVectorFloat().almostEqual(expected)) {    output.debug(L"output");    expected.debug(L"expected result");    return Error::handle(name(), L"compute", Error::TEST, __FILE__, __LINE__);  }  if (level_a > Integral::BRIEF) {    Console::put(L"\n\ttesting  scalar addition (3):\n");  }    MatrixFloat a(3, 3);  a.setDiagonal(4);  MatrixFloat b(3, 3);  b.assign(7);  b.setDiagonal(11);  input(0).makeVectorFloat().assign(L"7.0");  input(1).makeMatrixFloat().assign(a);    math7.compute(output, input);  if (!output.getMatrixFloat().almostEqual(b)) {    return Error::handle(name(), L"compute", Error::TEST, __FILE__, __LINE__);  }    if (level_a > Integral::BRIEF) {    Console::put(L"\n\ttesting  scalar addition (4):\n");  }      input(0).makeMatrixFloat().assign(a);  input(1).makeVectorFloat().assign(L"7.0");      math7.compute(output, input);  if (!output.getMatrixFloat().almostEqual(b)) {    return Error::handle(name(), L"compute", Error::TEST, __FILE__, __LINE__);  }    // test scalar subtraction  //  if (level_a > Integral::BRIEF) {    Console::put(L"\n\ttesting  scalar subtraction (1):\n");  }    input.setLength(2);  input(0).makeVectorFloat().assign(L"4.0");  input(1).makeVectorFloat().assign(L"1.0, 2.0, 3.0, 4.0");  values.setLength(2);  values(0).assign((long)IDENTITY);  values(1).assign((long)IDENTITY);  math7.setFunction(values);    values_op.setLength(2);  values_op(0).assign((long)ASSIGN);  values_op(1).assign((long)SUBTRACT);  math7.setOperation(values_op);    math7.compute(output, input);  expected.assign(L"3.0, 2.0, 1.0, 0.0");  if (!output.getVectorFloat().almostEqual(expected)) {    output.debug(L"output");    return Error::handle(name(), L"compute", Error::TEST, __FILE__, __LINE__);  }    input(0).makeVectorFloat().assign(L"1.0, 2.0, 3.0, 4.0");  input(1).makeVectorFloat().assign(L"4.0");  math7.compute(output, input);  expected.assign(L"-3.0, -2.0, -1.0, 0.0");  if (!output.getVectorFloat().almostEqual(expected)) {    return Error::handle(name(), L"compute", Error::TEST, __FILE__, __LINE__);  }  if (level_a > Integral::BRIEF) {    Console::put(L"\n\ttesting  scalar subtraction (2):\n");  }    a.clear(Integral::RETAIN);  a.setDiagonal(4);  b.clear(Integral::RETAIN);  b.assign(7);  b.setDiagonal(11);  input(0).makeVectorFloat().assign(L"7.0");  input(1).makeMatrixFloat().assign(a);  math7.compute(output, input);  b.assign(7);  b.setDiagonal(3.0);    if (!output.getMatrixFloat().almostEqual(b)) {    output.debug(L"output");    b.debug(L"b");    return Error::handle(name(), L"compute", Error::TEST, __FILE__, __LINE__);  }  if (level_a > Integral::BRIEF) {    Console::put(L"\n\ttesting  scalar subtraction (3):\n");  }    input(0).makeMatrixFloat().assign(a);  input(1).makeVectorFloat().assign(L"7.0");  b.assign(-7.0);  b.setDiagonal(-3.0);  math7.compute(output, input);  if (!output.getMatrixFloat().almostEqual(b)) {    output.debug(L"output");    b.debug(L"b");    return Error::handle(name(), L"compute", Error::TEST, __FILE__, __LINE__);  }  // test scalar multiplication  //  if (level_a > Integral::BRIEF) {    Console::put(L"\n\ttesting  scalar multiplication (1):\n");  }    values_op(1).assign((long)MULTIPLY);  math7.setOperation(values_op);  input(0).makeVectorFloat().assign(L"3.0");  input(1).makeVectorFloat().assign(L"2.0, 3.0, 4.0");  expected.assign(L"6.0, 9.0, 12.0");  math7.compute(output, input);  if (!output.getVectorFloat().almostEqual(expected)) {    output.debug(L"output");    return Error::handle(name(), L"compute", Error::TEST, __FILE__, __LINE__);  }  if (level_a > Integral::BRIEF) {    Console::put(L"\n\ttesting  scalar multiplication (2):\n");  }    input(0).makeVectorFloat().assign(L"2.0, 3.0, 4.0");  input(1).makeVectorFloat().assign(L"3.0");  expected.assign(L"6.0, 9.0, 12.0");  math7.compute(output, input);  if (!output.getVectorFloat().almostEqual(expected)) {    output.debug(L"output");    return Error::handle(name(), L"compute", Error::TEST, __FILE__, __LINE__);  }  if (level_a > Integral::BRIEF) {    Console::put(L"\n\ttesting  scalar multiplication (2):\n");  }    a.clear(Integral::RETAIN);  a.setDiagonal(3.0);    input(0).makeMatrixFloat().assign(a);  input(1).makeVectorFloat().assign(L"3.0");  b.clear(Integral::RETAIN);  b.setDiagonal(9.0);  math7.compute(output, input);  if (!output.getMatrixFloat().almostEqual(b)) {    output.debug(L"output");    return Error::handle(name(), L"compute", Error::TEST, __FILE__, __LINE__);  }  if (level_a > Integral::BRIEF) {    Console::put(L"\n\ttesting  scalar multiplication (3):\n");  }    input(0).makeVectorFloat().assign(L"3.0");  input(1).makeMatrixFloat().assign(a);  

⌨️ 快捷键说明

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