#include <regression_helper.h>
|
libMesh::Real | linear_slope (std::vector< libMesh::Real > x, std::vector< libMesh::Real > y, unsigned int start_index, unsigned int end_index) |
| Slope for linear regression. More...
|
|
libMesh::Real | linear_intercept (std::vector< libMesh::Real > x, std::vector< libMesh::Real > y, unsigned int start_index, unsigned int end_index) |
| y-intercept for linear regression More...
|
|
void | check_convergence_rate (std::vector< libMesh::Real > x, std::vector< libMesh::Real > y, unsigned int start_index, unsigned int end_index, libMesh::Real convergence_rate, libMesh::Real tol) |
| Check the convergence rate of the supplied data to within the given absolute tolerance. More...
|
|
Provides helper functions for fitting data to a curve.
Currently supports linear regression
Definition at line 46 of file regression_helper.h.
void GRINSTesting::RegressionHelper::check_convergence_rate |
( |
std::vector< libMesh::Real > |
x, |
|
|
std::vector< libMesh::Real > |
y, |
|
|
unsigned int |
start_index, |
|
|
unsigned int |
end_index, |
|
|
libMesh::Real |
convergence_rate, |
|
|
libMesh::Real |
tol |
|
) |
| |
|
inlineprotected |
Check the convergence rate of the supplied data to within the given absolute tolerance.
Definition at line 110 of file regression_helper.h.
References linear_slope().
Referenced by GRINSTesting::IntegratedFunctionTest::test_convergence().
112 libmesh_assert(tol > 0.0);
113 libmesh_assert(x.size() == y.size());
114 libmesh_assert(start_index < end_index);
115 libmesh_assert(end_index < x.size());
117 libMesh::Real calculated_rate =
linear_slope(x,y,start_index,end_index);
119 #ifdef GRINS_HAVE_CPPUNIT
121 CPPUNIT_ASSERT_DOUBLES_EQUAL(convergence_rate,calculated_rate,tol);
123 if (std::abs(convergence_rate - calculated_rate) > tol)
125 std::stringstream ss;
126 ss <<
"ERROR" <<std::endl
127 <<
"calculated convergence rate: " <<calculated_rate <<std::endl
128 <<
"desired convergence rate: " <<convergence_rate <<std::endl
129 <<
"tolerance: " <<tol <<std::endl;
131 libmesh_error_msg(ss.str());
133 #endif // GRINS_HAVE_CPPUNIT
libMesh::Real linear_slope(std::vector< libMesh::Real > x, std::vector< libMesh::Real > y, unsigned int start_index, unsigned int end_index)
Slope for linear regression.
libMesh::Real GRINSTesting::RegressionHelper::linear_intercept |
( |
std::vector< libMesh::Real > |
x, |
|
|
std::vector< libMesh::Real > |
y, |
|
|
unsigned int |
start_index, |
|
|
unsigned int |
end_index |
|
) |
| |
|
inlineprotected |
y-intercept for linear regression
Definition at line 81 of file regression_helper.h.
83 libmesh_assert(x.size() == y.size());
84 libmesh_assert(start_index < end_index);
86 unsigned int n = x.size();
87 libmesh_assert(end_index < n);
89 libMesh::Real sum_y = 0.0,
94 for (
unsigned int i=start_index; i<=end_index; i++)
96 libMesh::Real xi = x[i];
97 libMesh::Real yi = y[i];
105 libMesh::Real intercept = ( sum_y*sum_x2 - sum_x*sum_xy )/( n*sum_x2 - (sum_x*sum_x) );
libMesh::Real GRINSTesting::RegressionHelper::linear_slope |
( |
std::vector< libMesh::Real > |
x, |
|
|
std::vector< libMesh::Real > |
y, |
|
|
unsigned int |
start_index, |
|
|
unsigned int |
end_index |
|
) |
| |
|
inlineprotected |
Slope for linear regression.
Definition at line 51 of file regression_helper.h.
Referenced by check_convergence_rate().
53 libmesh_assert(x.size() == y.size());
54 libmesh_assert(start_index < end_index);
56 unsigned int n = x.size();
57 libmesh_assert(end_index < n);
59 libMesh::Real sum_y = 0.0,
64 for (
unsigned int i=start_index; i<=end_index; i++)
66 libMesh::Real xi = x[i];
67 libMesh::Real yi = y[i];
76 libMesh::Real slope = ( n*sum_xy - sum_x*sum_y )/( n*sum_x2 - (sum_x*sum_x) );
The documentation for this class was generated from the following file: