| 270 | } |
| 271 | |
| 272 | void FitTest::testLinearNoInt2() { |
| 273 | // NIST data for NoInt2 dataset |
| 274 | QVector<int> xData = {4, 5, 6}; |
| 275 | QVector<int> yData = {3, 4, 4}; |
| 276 | |
| 277 | // data source columns |
| 278 | Column xDataColumn(QStringLiteral("x"), AbstractColumn::ColumnMode::Integer); |
| 279 | xDataColumn.replaceInteger(0, xData); |
| 280 | |
| 281 | Column yDataColumn(QStringLiteral("y"), AbstractColumn::ColumnMode::Integer); |
| 282 | yDataColumn.replaceInteger(0, yData); |
| 283 | |
| 284 | XYFitCurve fitCurve(QStringLiteral("fit")); |
| 285 | fitCurve.setXDataColumn(&xDataColumn); |
| 286 | fitCurve.setYDataColumn(&yDataColumn); |
| 287 | |
| 288 | // prepare the fit |
| 289 | XYFitCurve::FitData fitData = fitCurve.fitData(); |
| 290 | fitData.modelCategory = nsl_fit_model_custom; |
| 291 | XYFitCurve::initFitData(fitData); |
| 292 | fitData.model = QStringLiteral("c * x"); |
| 293 | fitData.paramNames << QStringLiteral("c"); |
| 294 | const int np = fitData.paramNames.size(); |
| 295 | fitData.paramStartValues << 1.; |
| 296 | fitData.paramLowerLimits << -std::numeric_limits<double>::max(); |
| 297 | fitData.paramUpperLimits << std::numeric_limits<double>::max(); |
| 298 | // fitData.eps = 1.e-15; |
| 299 | fitCurve.setFitData(fitData); |
| 300 | |
| 301 | // perform the fit |
| 302 | fitCurve.recalculate(); |
| 303 | const XYFitCurve::FitResult& fitResult = fitCurve.fitResult(); |
| 304 | |
| 305 | // check the results |
| 306 | QCOMPARE(fitResult.available, true); |
| 307 | QCOMPARE(fitResult.valid, true); |
| 308 | |
| 309 | QCOMPARE(np, 1); |
| 310 | |
| 311 | DEBUG(std::setprecision(15) << fitResult.paramValues.at(0)); // result: 0.727272727152573 |
| 312 | FuzzyCompare(fitResult.paramValues.at(0), 0.727272727272727, 1.e-9); |
| 313 | DEBUG(std::setprecision(15) << fitResult.errorValues.at(0)); // result: 0.0420827316561797 |
| 314 | FuzzyCompare(fitResult.errorValues.at(0), 0.420827318078432E-01, 1.e-8); |
| 315 | |
| 316 | QCOMPARE(fitResult.rsd, 0.369274472937998); |
| 317 | QCOMPARE(fitResult.sse, 0.272727272727273); |
| 318 | QCOMPARE(fitResult.rms, 0.136363636363636); |
| 319 | // can not detect that intercept is zero for a custom linear model |
| 320 | DEBUG(std::setprecision(15) << fitResult.rsquare); // result: 0.590909090909091 |
| 321 | // QCOMPARE(fitResult.rsquare, 0.993348115299335); |
| 322 | DEBUG(std::setprecision(15) << fitResult.fdist_F); // result: 2.88888888888889 |
| 323 | // FuzzyCompare(fitResult.fdist_F, 298.666666666667, 1.); |
| 324 | } |
| 325 | |
| 326 | void FitTest::testLinearNoInt2_2() { |
| 327 | // NIST data for NoInt2 dataset |
nothing calls this directly
no test coverage detected