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

Method testLinearFilip

tests/analysis/fit/FitTest.cpp:375–480  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

373}
374
375void FitTest::testLinearFilip() {
376 // NIST data for Filip dataset
377 QVector<double> xData = {-6.860120914, -4.324130045, -4.358625055, -4.358426747, -6.955852379, -6.661145254, -6.355462942, -6.118102026, -7.115148017,
378 -6.815308569, -6.519993057, -6.204119983, -5.853871964, -6.109523091, -5.79832982, -5.482672118, -5.171791386, -4.851705903,
379 -4.517126416, -4.143573228, -3.709075441, -3.499489089, -6.300769497, -5.953504836, -5.642065153, -5.031376979, -4.680685696,
380 -4.329846955, -3.928486195, -8.56735134, -8.363211311, -8.107682739, -7.823908741, -7.522878745, -7.218819279, -6.920818754,
381 -6.628932138, -6.323946875, -5.991399828, -8.781464495, -8.663140179, -8.473531488, -8.247337057, -7.971428747, -7.676129393,
382 -7.352812702, -7.072065318, -6.774174009, -6.478861916, -6.159517513, -6.835647144, -6.53165267, -6.224098421, -5.910094889,
383 -5.598599459, -5.290645224, -4.974284616, -4.64454848, -4.290560426, -3.885055584, -3.408378962, -3.13200249, -8.726767166,
384 -8.66695597, -8.511026475, -8.165388579, -7.886056648, -7.588043762, -7.283412422, -6.995678626, -6.691862621, -6.392544977,
385 -6.067374056, -6.684029655, -6.378719832, -6.065855188, -5.752272167, -5.132414673, -4.811352704, -4.098269308, -3.66174277,
386 -3.2644011};
387 QVector<double> yData = {0.8116, 0.9072, 0.9052, 0.9039, 0.8053, 0.8377, 0.8667, 0.8809, 0.7975, 0.8162, 0.8515, 0.8766, 0.8885, 0.8859,
388 0.8959, 0.8913, 0.8959, 0.8971, 0.9021, 0.909, 0.9139, 0.9199, 0.8692, 0.8872, 0.89, 0.891, 0.8977, 0.9035,
389 0.9078, 0.7675, 0.7705, 0.7713, 0.7736, 0.7775, 0.7841, 0.7971, 0.8329, 0.8641, 0.8804, 0.7668, 0.7633, 0.7678,
390 0.7697, 0.77, 0.7749, 0.7796, 0.7897, 0.8131, 0.8498, 0.8741, 0.8061, 0.846, 0.8751, 0.8856, 0.8919, 0.8934,
391 0.894, 0.8957, 0.9047, 0.9129, 0.9209, 0.9219, 0.7739, 0.7681, 0.7665, 0.7703, 0.7702, 0.7761, 0.7809, 0.7961,
392 0.8253, 0.8602, 0.8809, 0.8301, 0.8664, 0.8834, 0.8898, 0.8964, 0.8963, 0.9074, 0.9119, 0.9228};
393
394 // data source columns
395 Column xDataColumn(QStringLiteral("x"), AbstractColumn::ColumnMode::Double);
396 xDataColumn.replaceValues(0, xData);
397
398 Column yDataColumn(QStringLiteral("y"), AbstractColumn::ColumnMode::Double);
399 yDataColumn.replaceValues(0, yData);
400
401 XYFitCurve fitCurve(QStringLiteral("fit"));
402 fitCurve.setXDataColumn(&xDataColumn);
403 fitCurve.setYDataColumn(&yDataColumn);
404
405 // prepare the fit
406 XYFitCurve::FitData fitData = fitCurve.fitData();
407 fitData.modelCategory = nsl_fit_model_basic;
408 fitData.modelType = nsl_fit_model_polynomial;
409 fitData.degree = 10;
410 fitData.eps = 1.e-8;
411 XYFitCurve::initFitData(fitData);
412 const int np = fitData.paramNames.size();
413 fitCurve.setFitData(fitData);
414
415 // perform the fit
416 fitCurve.recalculate();
417 const XYFitCurve::FitResult& fitResult = fitCurve.fitResult();
418
419 // check the results
420 QCOMPARE(fitResult.available, true);
421 QCOMPARE(fitResult.valid, true);
422
423 QCOMPARE(np, 11);
424
425 DEBUG(std::setprecision(15) << fitResult.paramValues.at(0)); // result: -1467.48962615175
426 FuzzyCompare(fitResult.paramValues.at(0), -1467.48961422980, 2.e-5);
427 DEBUG(std::setprecision(15) << fitResult.errorValues.at(0)); // result: 298.084524514884
428 FuzzyCompare(fitResult.errorValues.at(0), 298.084530995537, 1.e-7);
429 DEBUG(std::setprecision(15) << fitResult.paramValues.at(1)); // result: -2772.1796150428
430 FuzzyCompare(fitResult.paramValues.at(1), -2772.17959193342, 2.e-5);
431 DEBUG(std::setprecision(15) << fitResult.errorValues.at(1)); // result: 559.779853249694
432 FuzzyCompare(fitResult.errorValues.at(1), 559.779865474950, 1.e-7);

Callers

nothing calls this directly

Calls 6

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

Tested by

no test coverage detected