| 530 | } |
| 531 | |
| 532 | void FitTest::testLinearWampler1_custom() { |
| 533 | // NIST data for Wampler1 dataset |
| 534 | QVector<int> xData = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20}; |
| 535 | QVector<int> yData = {1, 6, 63, 364, 1365, 3906, 9331, 19608, 37449, 66430, 111111, |
| 536 | 177156, 271453, 402234, 579195, 813616, 1118481, 1508598, 2000719, 2613660, 3368421}; |
| 537 | |
| 538 | // data source columns |
| 539 | Column xDataColumn(QStringLiteral("x"), AbstractColumn::ColumnMode::Integer); |
| 540 | xDataColumn.replaceInteger(0, xData); |
| 541 | |
| 542 | Column yDataColumn(QStringLiteral("y"), AbstractColumn::ColumnMode::Integer); |
| 543 | yDataColumn.replaceInteger(0, yData); |
| 544 | |
| 545 | XYFitCurve fitCurve(QStringLiteral("fit")); |
| 546 | fitCurve.setXDataColumn(&xDataColumn); |
| 547 | fitCurve.setYDataColumn(&yDataColumn); |
| 548 | |
| 549 | // prepare the fit |
| 550 | XYFitCurve::FitData fitData = fitCurve.fitData(); |
| 551 | fitData.modelCategory = nsl_fit_model_custom; |
| 552 | XYFitCurve::initFitData(fitData); |
| 553 | fitData.model = QStringLiteral("B0+B1*x+B2*x^2+B3*x^3+B4*x^4+B5*x^5"); |
| 554 | fitData.paramNames << QStringLiteral("B0") << QStringLiteral("B1") << QStringLiteral("B2") << QStringLiteral("B3") << QStringLiteral("B4") |
| 555 | << QStringLiteral("B5"); |
| 556 | // fitData.eps = 1.e-12; |
| 557 | const int np = fitData.paramNames.size(); |
| 558 | // start values |
| 559 | fitData.paramStartValues << 1. << 1. << 1. << 1. << 1. << 1.; |
| 560 | for (int i = 0; i < np; i++) { |
| 561 | fitData.paramLowerLimits << -std::numeric_limits<double>::max(); |
| 562 | fitData.paramUpperLimits << std::numeric_limits<double>::max(); |
| 563 | } |
| 564 | fitCurve.setFitData(fitData); |
| 565 | |
| 566 | // perform the fit |
| 567 | fitCurve.recalculate(); |
| 568 | const XYFitCurve::FitResult& fitResult = fitCurve.fitResult(); |
| 569 | |
| 570 | // check the results |
| 571 | QCOMPARE(fitResult.available, true); |
| 572 | QCOMPARE(fitResult.valid, true); |
| 573 | |
| 574 | QCOMPARE(np, 6); |
| 575 | |
| 576 | for (int i = 0; i < np; i++) { |
| 577 | const double paramValue = fitResult.paramValues.at(i); |
| 578 | const double errorValue = fitResult.errorValues.at(i); |
| 579 | DEBUG(std::setprecision(15) << paramValue << ' ' << paramValue - 1.0); |
| 580 | FuzzyCompare(paramValue, 1.0, 2.e-12); |
| 581 | DEBUG(std::setprecision(15) << errorValue); |
| 582 | FuzzyCompare(errorValue, 0.0, 5.e-12); |
| 583 | } |
| 584 | |
| 585 | DEBUG(std::setprecision(15) << fitResult.rsd); |
| 586 | FuzzyCompare(fitResult.rsd, 0.0, 5.e-12); |
| 587 | QCOMPARE(fitResult.rsquare, 1.0); |
| 588 | QCOMPARE(fitResult.sse, 0.0); |
| 589 | QCOMPARE(fitResult.rms, 0.0); |
nothing calls this directly
no test coverage detected