| 169 | } |
| 170 | |
| 171 | void FitTest::testLinearNoInt1() { |
| 172 | // NIST data for NoInt1 dataset |
| 173 | QVector<int> xData = {60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70}; |
| 174 | QVector<int> yData = {130, 131, 132, 133, 134, 135, 136, 137, 138, 139, 140}; |
| 175 | |
| 176 | // data source columns |
| 177 | Column xDataColumn(QStringLiteral("x"), AbstractColumn::ColumnMode::Integer); |
| 178 | xDataColumn.replaceInteger(0, xData); |
| 179 | |
| 180 | Column yDataColumn(QStringLiteral("y"), AbstractColumn::ColumnMode::Integer); |
| 181 | yDataColumn.replaceInteger(0, yData); |
| 182 | |
| 183 | XYFitCurve fitCurve(QStringLiteral("fit")); |
| 184 | fitCurve.setXDataColumn(&xDataColumn); |
| 185 | fitCurve.setYDataColumn(&yDataColumn); |
| 186 | |
| 187 | // prepare the fit |
| 188 | XYFitCurve::FitData fitData = fitCurve.fitData(); |
| 189 | fitData.modelCategory = nsl_fit_model_custom; |
| 190 | XYFitCurve::initFitData(fitData); |
| 191 | fitData.model = QStringLiteral("b1*x"); |
| 192 | fitData.paramNames << QStringLiteral("b1"); |
| 193 | const int np = fitData.paramNames.size(); |
| 194 | fitData.paramStartValues << 1.; |
| 195 | fitData.paramLowerLimits << -std::numeric_limits<double>::max(); |
| 196 | fitData.paramUpperLimits << std::numeric_limits<double>::max(); |
| 197 | // fitData.eps = 1.e-15; |
| 198 | fitCurve.setFitData(fitData); |
| 199 | |
| 200 | // perform the fit |
| 201 | fitCurve.recalculate(); |
| 202 | const XYFitCurve::FitResult& fitResult = fitCurve.fitResult(); |
| 203 | |
| 204 | // check the results |
| 205 | QCOMPARE(fitResult.available, true); |
| 206 | QCOMPARE(fitResult.valid, true); |
| 207 | |
| 208 | QCOMPARE(np, 1); |
| 209 | |
| 210 | DEBUG(std::setprecision(15) << fitResult.paramValues.at(0)); // result: 2.07438016513166 |
| 211 | FuzzyCompare(fitResult.paramValues.at(0), 2.07438016528926, 1.e-9); |
| 212 | DEBUG(std::setprecision(15) << fitResult.errorValues.at(0)); // result: 0.0165289256079047 |
| 213 | FuzzyCompare(fitResult.errorValues.at(0), 0.165289256198347e-1, 1.e-9); |
| 214 | |
| 215 | QCOMPARE(fitResult.rsd, 3.56753034006338); |
| 216 | QCOMPARE(fitResult.sse, 127.272727272727); |
| 217 | QCOMPARE(fitResult.rms, 12.7272727272727); |
| 218 | QCOMPARE(fitResult.rsquare, 0.999365492298663); |
| 219 | DEBUG(std::setprecision(15) << fitResult.fdist_F); // result: 15750.2500000027 |
| 220 | QCOMPARE(fitResult.fdist_F, 15750.25); |
| 221 | } |
| 222 | |
| 223 | void FitTest::testLinearNoInt1_2() { |
| 224 | // NIST data for NoInt1 dataset |
nothing calls this directly
no test coverage detected