MCPcopy Create free account
hub / github.com/KDE/labplot / testLinearWampler2_custom

Method testLinearWampler2_custom

tests/analysis/fit/FitTest.cpp:650–710  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

648}
649
650void FitTest::testLinearWampler2_custom() {
651 // NIST data for Wampler2 dataset
652 QVector<int> xData = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20};
653 QVector<double> yData = {1.00000, 1.11111, 1.24992, 1.42753, 1.65984, 1.96875, 2.38336, 2.94117, 3.68928, 4.68559, 6.00000,
654 7.71561, 9.92992, 12.75603, 16.32384, 20.78125, 26.29536, 33.05367, 41.26528, 51.16209, 63.00000};
655
656 // data source columns
657 Column xDataColumn(QStringLiteral("x"), AbstractColumn::ColumnMode::Integer);
658 xDataColumn.replaceInteger(0, xData);
659
660 Column yDataColumn(QStringLiteral("y"), AbstractColumn::ColumnMode::Double);
661 yDataColumn.replaceValues(0, yData);
662
663 XYFitCurve fitCurve(QStringLiteral("fit"));
664 fitCurve.setXDataColumn(&xDataColumn);
665 fitCurve.setYDataColumn(&yDataColumn);
666
667 // prepare the fit
668 XYFitCurve::FitData fitData = fitCurve.fitData();
669 fitData.modelCategory = nsl_fit_model_custom;
670 XYFitCurve::initFitData(fitData);
671 fitData.model = QStringLiteral("B0+B1*x+B2*x^2+B3*x^3+B4*x^4+B5*x^5");
672 fitData.paramNames << QStringLiteral("B0") << QStringLiteral("B1") << QStringLiteral("B2") << QStringLiteral("B3") << QStringLiteral("B4")
673 << QStringLiteral("B5");
674 // fitData.eps = 1.e-12;
675 const int np = fitData.paramNames.size();
676 // start values
677 fitData.paramStartValues << 1. << 0.1 << 1.e-2 << 1.e-3 << 1.e-4 << 1.e-5;
678 for (int i = 0; i < np; i++) {
679 fitData.paramLowerLimits << -std::numeric_limits<double>::max();
680 fitData.paramUpperLimits << std::numeric_limits<double>::max();
681 }
682 fitCurve.setFitData(fitData);
683
684 // perform the fit
685 fitCurve.recalculate();
686 const XYFitCurve::FitResult& fitResult = fitCurve.fitResult();
687
688 // check the results
689 QCOMPARE(fitResult.available, true);
690 QCOMPARE(fitResult.valid, true);
691
692 QCOMPARE(np, 6);
693
694 for (int i = 0; i < np; i++)
695 printAndCheck(fitResult.errorValues.at(i), 0., 5.e-15);
696 printAndCheck(fitResult.paramValues.at(0), 1.0, 1.e-15);
697 printAndCheck(fitResult.paramValues.at(1), 0.1, 5.e-14);
698 printAndCheck(fitResult.paramValues.at(2), 1.e-2, 2.e-13);
699 printAndCheck(fitResult.paramValues.at(3), 1.e-3, 5.e-13);
700 printAndCheck(fitResult.paramValues.at(4), 1.e-4, 2.e-13);
701 printAndCheck(fitResult.paramValues.at(5), 1.e-5, 5.e-14);
702
703 printAndCheck(fitResult.rsd, 0., 5.e-15);
704 QCOMPARE(fitResult.rsquare, 1.);
705 DEBUG(std::setprecision(15) << fitResult.sse); // result:
706 QCOMPARE(fitResult.sse, 0.);
707 DEBUG(std::setprecision(15) << fitResult.rms); // result:

Callers

nothing calls this directly

Calls 7

setXDataColumnMethod · 0.80
setYDataColumnMethod · 0.80
replaceIntegerMethod · 0.45
replaceValuesMethod · 0.45
sizeMethod · 0.45
setFitDataMethod · 0.45
recalculateMethod · 0.45

Tested by

no test coverage detected