| 2704 | } |
| 2705 | |
| 2706 | void FitTest::testNonLinearHahn1_2() { |
| 2707 | Spreadsheet spreadsheet(QStringLiteral("test"), false); |
| 2708 | AsciiFilter filter; |
| 2709 | |
| 2710 | // NIST data for Hahn1 dataset |
| 2711 | const QString& fileName = QFINDTESTDATA(QLatin1String("data/NIST/non-linear/Hahn1_data.dat")); |
| 2712 | |
| 2713 | auto properties = filter.properties(); |
| 2714 | properties.headerEnabled = false; |
| 2715 | properties.simplifyWhitespaces = true; |
| 2716 | properties.skipEmptyParts = true; |
| 2717 | filter.setProperties(properties); |
| 2718 | filter.readDataFromFile(fileName, &spreadsheet, AbstractFileFilter::ImportMode::Replace); |
| 2719 | |
| 2720 | QCOMPARE(spreadsheet.rowCount(), 236); |
| 2721 | QCOMPARE(spreadsheet.columnCount(), 2); |
| 2722 | |
| 2723 | XYFitCurve fitCurve(QStringLiteral("fit")); |
| 2724 | fitCurve.setXDataColumn(spreadsheet.column(1)); |
| 2725 | fitCurve.setYDataColumn(spreadsheet.column(0)); |
| 2726 | |
| 2727 | // prepare the fit |
| 2728 | XYFitCurve::FitData fitData = fitCurve.fitData(); |
| 2729 | fitData.modelCategory = nsl_fit_model_custom; |
| 2730 | XYFitCurve::initFitData(fitData); |
| 2731 | fitData.model = QStringLiteral("(b1+b2*x+b3*x^2+b4*x^3) / (1+b5*x+b6*x^2+b7*x^3)"); |
| 2732 | fitData.paramNames << QStringLiteral("b1") << QStringLiteral("b2") << QStringLiteral("b3") << QStringLiteral("b4") << QStringLiteral("b5") |
| 2733 | << QStringLiteral("b6") << QStringLiteral("b7"); |
| 2734 | // fitData.eps = 1.e-12; |
| 2735 | const int np = fitData.paramNames.size(); |
| 2736 | // second start values |
| 2737 | fitData.paramStartValues << 1. << -0.1 << 0.005 << -0.000001 << -0.005 << 0.0001 << -0.0000001; |
| 2738 | for (int i = 0; i < np; i++) { |
| 2739 | fitData.paramLowerLimits << -std::numeric_limits<double>::max(); |
| 2740 | fitData.paramUpperLimits << std::numeric_limits<double>::max(); |
| 2741 | } |
| 2742 | fitCurve.setFitData(fitData); |
| 2743 | |
| 2744 | // perform the fit |
| 2745 | fitCurve.recalculate(); |
| 2746 | const XYFitCurve::FitResult& fitResult = fitCurve.fitResult(); |
| 2747 | |
| 2748 | // check the results |
| 2749 | QCOMPARE(fitResult.available, true); |
| 2750 | QCOMPARE(fitResult.valid, true); |
| 2751 | |
| 2752 | QCOMPARE(np, 7); |
| 2753 | |
| 2754 | printAndCheck(fitResult.paramValues.at(0), 1.0776351733E+00, 1.e-2); |
| 2755 | printAndCheck(fitResult.errorValues.at(0), 1.7070154742E-01, 2.e-2); |
| 2756 | |
| 2757 | printAndCheck(fitResult.paramValues.at(1), -1.2269296921E-01, 1.e-2); |
| 2758 | printAndCheck(fitResult.errorValues.at(1), 1.2000289189E-02, 2.e-2); |
| 2759 | |
| 2760 | printAndCheck(fitResult.paramValues.at(2), 4.0863750610E-03, 2.e-3); |
| 2761 | printAndCheck(fitResult.errorValues.at(2), 2.2508314937E-04, 1.e-3); |
| 2762 | |
| 2763 | printAndCheck(fitResult.paramValues.at(3), -1.4262662514E-06, 1.e-3); |
nothing calls this directly
no test coverage detected