| 2973 | } |
| 2974 | |
| 2975 | void FitTest::testNonLinearBennett5_3() { |
| 2976 | Spreadsheet spreadsheet(QStringLiteral("test"), false); |
| 2977 | AsciiFilter filter; |
| 2978 | |
| 2979 | // NIST data for Hahn1 dataset |
| 2980 | const QString& fileName = QFINDTESTDATA(QLatin1String("data/NIST/non-linear/Bennett5_data.dat")); |
| 2981 | |
| 2982 | auto properties = filter.properties(); |
| 2983 | properties.headerEnabled = false; |
| 2984 | properties.simplifyWhitespaces = true; |
| 2985 | properties.skipEmptyParts = true; |
| 2986 | filter.setProperties(properties); |
| 2987 | filter.readDataFromFile(fileName, &spreadsheet, AbstractFileFilter::ImportMode::Replace); |
| 2988 | |
| 2989 | QCOMPARE(spreadsheet.rowCount(), 154); |
| 2990 | QCOMPARE(spreadsheet.columnCount(), 2); |
| 2991 | |
| 2992 | XYFitCurve fitCurve(QStringLiteral("fit")); |
| 2993 | fitCurve.setXDataColumn(spreadsheet.column(1)); |
| 2994 | fitCurve.setYDataColumn(spreadsheet.column(0)); |
| 2995 | |
| 2996 | // prepare the fit |
| 2997 | XYFitCurve::FitData fitData = fitCurve.fitData(); |
| 2998 | fitData.modelCategory = nsl_fit_model_custom; |
| 2999 | XYFitCurve::initFitData(fitData); |
| 3000 | fitData.model = QStringLiteral("b1 * (b2+x)^(-1./b3)"); |
| 3001 | fitData.paramNames << QStringLiteral("b1") << QStringLiteral("b2") << QStringLiteral("b3"); |
| 3002 | fitData.eps = 1.e-8; |
| 3003 | fitData.maxIterations = 1000; |
| 3004 | const int np = fitData.paramNames.size(); |
| 3005 | // exact start values |
| 3006 | fitData.paramStartValues << -2.5235058043E+03 << 4.6736564644E+01 << 9.3218483193E-01; |
| 3007 | for (int i = 0; i < np; i++) { |
| 3008 | fitData.paramLowerLimits << -std::numeric_limits<double>::max(); |
| 3009 | fitData.paramUpperLimits << std::numeric_limits<double>::max(); |
| 3010 | } |
| 3011 | fitCurve.setFitData(fitData); |
| 3012 | |
| 3013 | // perform the fit |
| 3014 | fitCurve.recalculate(); |
| 3015 | const XYFitCurve::FitResult& fitResult = fitCurve.fitResult(); |
| 3016 | |
| 3017 | // check the results |
| 3018 | QCOMPARE(fitResult.available, true); |
| 3019 | QCOMPARE(fitResult.valid, true); |
| 3020 | |
| 3021 | QCOMPARE(np, 3); |
| 3022 | |
| 3023 | printAndCheck(fitResult.paramValues.at(0), -2.5235058043E+03, 2.e-2); |
| 3024 | printAndCheck(fitResult.errorValues.at(0), 2.9715175411E+02, 2.e-2); |
| 3025 | |
| 3026 | printAndCheck(fitResult.paramValues.at(1), 4.6736564644E+01, 5.e-3); |
| 3027 | printAndCheck(fitResult.errorValues.at(1), 1.2448871856E+00, 2.e-2); |
| 3028 | |
| 3029 | printAndCheck(fitResult.paramValues.at(2), 9.3218483193E-01, 3.e-3); |
| 3030 | printAndCheck(fitResult.errorValues.at(2), 2.0272299378E-02, 1.e-2); |
| 3031 | |
| 3032 | printAndCheck(fitResult.rsd, 1.8629312528E-03, 1.e-4); |
nothing calls this directly
no test coverage detected