TEUCHOS_UNIT_TEST( Rythmos_ConvergenceTestHelpers, invalidData ) { LinearRegression<double> lr; Array<double> x,y; TEST_THROW(lr.setData(x,y), std::logic_error); x.push_back(0.0); y.push_back(0.0); TEST_THROW(lr.setData(x,y), std::logic_error); x.push_back(1.0); TEST_THROW(lr.setData(x,y), std::logic_error); }
TEUCHOS_UNIT_TEST( Rythmos_ConvergenceTestHelpers, trivialData ) { LinearRegression<double> lr; Array<double> x,y; x.push_back(0.0); x.push_back(1.0); y.push_back(0.0); y.push_back(1.0); lr.setData(x,y); TEST_EQUALITY_CONST( lr.getSlope(), 1.0 ); TEST_EQUALITY_CONST( lr.getYIntercept(), 0.0 ); }
TEUCHOS_UNIT_TEST( Rythmos_ConvergenceTestHelpers, nonUniqueXData ) { LinearRegression<double> lr; Array<double> x,y; x.push_back(0.0); x.push_back(1.0); x.push_back(1.0); y.push_back(0.0); y.push_back(0.5); y.push_back(1.5); lr.setData(x,y); double tol = 1.0e-10; TEST_FLOATING_EQUALITY( lr.getSlope(), 1.0, tol ); TEST_FLOATING_EQUALITY( lr.getYIntercept(), 0.0, tol ); }
TEUCHOS_UNIT_TEST( Rythmos_ConvergenceTestHelpers, CoSineData ) { LinearRegression<double> lr; Array<double> x,y; int N = 11; double dt = 0.1; for (int i=0 ; i<N ; ++i) { double xval = dt*i; x.push_back( xval ); y.push_back( cos(xval) ); } lr.setData(x,y); // 1.0e-14 works on rancilio but not on gabriel, exetazo, or s858352 double tol = 1.0e-13; TEST_FLOATING_EQUALITY( lr.getSlope(), -4.653508042678562e-01, tol ); // These came from matlab TEST_FLOATING_EQUALITY( lr.getYIntercept(), 1.067025181571952, tol ); }
TEUCHOS_UNIT_TEST( Rythmos_ConvergenceTestHelpers, SineData ) { LinearRegression<double> lr; Array<double> x,y; int N = 11; double dt = 0.1; for (int i=0 ; i<N ; ++i) { double xval = dt*i; x.push_back( xval ); y.push_back( sin(xval) ); } lr.setData(x,y); // 1.0e-14 works on rancilio but not on gabriel, exetazo, or s858352 double tol = 1.0e-13; TEST_FLOATING_EQUALITY( lr.getSlope(), 8.518189335013251e-01, tol ); // These came from matlab TEST_FLOATING_EQUALITY( lr.getYIntercept(), 2.989789515694744e-02, tol ); }
Scalar computeLinearRegressionSlope(Array<Scalar>& x, Array<Scalar>& y) { LinearRegression<Scalar> lr; lr.setData(x,y); return(lr.getSlope()); }