23 #ifndef LINEAR_LEAST_SQUARES_HPP 24 #define LINEAR_LEAST_SQUARES_HPP 26 #include <dune/common/dynmatrix.hh> 27 #include <dune/common/dynvector.hh> 29 #include <opm/common/ErrorMacros.hpp> 31 #include <opm/simulators/linalg/SmallDenseMatrixUtils.hpp> 43 template <
class Scalar>
46 using Matrix = Dune::DynamicMatrix<Scalar>;
47 using Vector = Dune::DynamicVector<Scalar>;
57 : A_(A), b_(b), x_(A.M())
68 solveNormalEquations_();
76 const Vector&
x()
const 101 return r.two_norm2();
112 const auto ndata = b_.N();
113 for (
size_t i = 0; i < ndata; ++i) {
118 Vector r(ndata, ymean);
121 return r.two_norm2();
134 const auto ndata = b_.N();
135 for (
size_t i = 0; i < ndata; ++i) {
140 Vector r(ndata, ymean);
143 return r.two_norm2();
157 OPM_THROW(std::runtime_error,
158 "Total sum of squares is close to zero, hence R^2 is undefined!");
167 void solveNormalEquations_()
174 Matrix Ahat(A_.M(), A_.M());
175 detail::multMatrixTransposed(A_, A_, Ahat);
178 Ahat.solve(x_, bhat,
true);
188 #endif // LINEAR_LEAST_SQUARES_HPP Linear least squares calculations and properties.
Definition: linearleastsquares.hpp:44
Scalar residualSumOfSquares() const
Measure of the discrepancy between data and regression model.
Definition: linearleastsquares.hpp:97
Scalar evaluate(const Vector &x) const
Evaluate regression model at input x vector.
Definition: linearleastsquares.hpp:87
Scalar explainedSumOfSquares() const
Value for how well regression model represents the model.
Definition: linearleastsquares.hpp:109
Structs needed for tpfalinearizer and its gpuparams struct extracted to be defined in one place that ...
Definition: blackoilbioeffectsmodules.hh:45
Scalar RSquared() const
Coefficient of determination.
Definition: linearleastsquares.hpp:153
LinearLeastSquares(const Matrix &A, const Vector &b)
Constructor.
Definition: linearleastsquares.hpp:56
void solve()
Solve linear least squares system.
Definition: linearleastsquares.hpp:66
const Vector & x() const
Read-only vector of calculated coefficient vector.
Definition: linearleastsquares.hpp:76
Scalar totalSumOfSquares() const
Sum of all squared differences.
Definition: linearleastsquares.hpp:131