diff --git a/SimoxUtility/tests/math/regression/linear3d.cpp b/SimoxUtility/tests/math/regression/linear3d.cpp index fe6d2013566166a99538de96f59ca41caa7d9f4e..0ca866f92cc9c807d41d8b2332212763c97937da 100644 --- a/SimoxUtility/tests/math/regression/linear3d.cpp +++ b/SimoxUtility/tests/math/regression/linear3d.cpp @@ -55,6 +55,8 @@ BOOST_AUTO_TEST_CASE(test_linear_regression_3d_fit_and_predict) const LinearRegression3D regression = LinearRegression3D::Fit(xs, ys); + BOOST_TEST_MESSAGE("Regression: " << regression); + BOOST_CHECK_CLOSE(regression.coefficients(0, 0), - (1 + 0), prec); BOOST_CHECK_CLOSE(regression.coefficients(1, 0), - (1 + 1), prec); BOOST_CHECK_CLOSE(regression.coefficients(2, 0), - (1 + 2), prec); @@ -72,4 +74,24 @@ BOOST_AUTO_TEST_CASE(test_linear_regression_3d_fit_and_predict) } +BOOST_AUTO_TEST_CASE(test_linear_regression_3d_fit_and_predict_with_input_offset) +{ + using simox::math::LinearRegression3D; + + const bool inputOffset = true; + const LinearRegression3D regression = LinearRegression3D::Fit(xs, ys, inputOffset); + + BOOST_TEST_MESSAGE("Regression: " << regression); + BOOST_CHECK_EQUAL(regression.inputOffset, - xs[0]); + + // Coefficients are different now, but prediction should be the same. + + // Predict + + BOOST_CHECK_LE((regression.predict(xs[0]) - ys[0]).norm(), prec); + BOOST_CHECK_LE((regression.predict(xs[1]) - ys[1]).norm(), prec); + BOOST_CHECK_LE((regression.predict(xs[2]) - ys[2]).norm(), prec); +} + + BOOST_AUTO_TEST_SUITE_END()