https://mooseframework.inl.gov
Loading...
Searching...
No Matches
LeastSquaresFitBase.h
Go to the documentation of this file.
1//* This file is part of the MOOSE framework
2//* https://mooseframework.inl.gov
3//*
4//* All rights reserved, see COPYRIGHT for full restrictions
5//* https://github.com/idaholab/moose/blob/master/COPYRIGHT
6//*
7//* Licensed under LGPL 2.1, please see LICENSE for details
8//* https://www.gnu.org/licenses/lgpl-2.1.html
9
10#pragma once
11
12#include <vector>
13#include <string>
14
15#include "Moose.h"
16
24{
25public:
27 LeastSquaresFitBase(const std::vector<Real> & x, const std::vector<Real> & y);
28
29 virtual ~LeastSquaresFitBase() = default;
30
36 virtual void generate();
37
44 virtual Real sample(Real x) = 0;
45
50 unsigned int getSampleSize();
51
56 const std::vector<Real> & getCoefficients();
57
58 void setVariables(const std::vector<Real> & x, const std::vector<Real> & y);
59
60protected:
64 virtual void fillMatrix() = 0;
65
70 void doLeastSquares();
71
73 std::vector<Real> _x;
75 std::vector<Real> _y;
77 std::vector<Real> _matrix;
79 std::vector<Real> _coeffs;
81 unsigned int _num_coeff;
82};
Base class for linear least squares fit method.
virtual void generate()
Generate the fit.
virtual void fillMatrix()=0
Helper function that creates the matrix necessary for the least squares algorithm.
unsigned int getSampleSize()
Size of the array holding the points.
std::vector< Real > _x
Independent variable.
std::vector< Real > _coeffs
Vector of coefficients of the least squares fit.
virtual Real sample(Real x)=0
This function will take an independent variable input and will return the dependent variable based on...
unsigned int _num_coeff
The number of coefficients.
const std::vector< Real > & getCoefficients()
Const reference to the vector of coefficients of the least squares fit.
void doLeastSquares()
Wrapper for the LAPACK dgels function.
void setVariables(const std::vector< Real > &x, const std::vector< Real > &y)
std::vector< Real > _y
Dependent variable.
std::vector< Real > _matrix
Basis functions evaluated at each independent variable (note: actually a vector)
virtual ~LeastSquaresFitBase()=default