|
Algorithms_in_C++
1.0.0
Set of algorithms implemented in C++.
|
Linear regression example using Ordinary least squares More...
#include <iomanip>#include <iostream>#include <vector>Functions | |
| template<typename T > | |
| std::ostream & | operator<< (std::ostream &out, std::vector< std::vector< T >> const &v) |
| template<typename T > | |
| std::ostream & | operator<< (std::ostream &out, std::vector< T > const &v) |
| template<typename T > | |
| bool | is_square (std::vector< std::vector< T >> const &A) |
| template<typename T > | |
| std::vector< std::vector< T > > | operator* (std::vector< std::vector< T >> const &A, std::vector< std::vector< T >> const &B) |
| template<typename T > | |
| std::vector< T > | operator* (std::vector< std::vector< T >> const &A, std::vector< T > const &B) |
| template<typename T > | |
| std::vector< float > | operator* (float const scalar, std::vector< T > const &A) |
| template<typename T > | |
| std::vector< float > | operator* (std::vector< T > const &A, float const scalar) |
| template<typename T > | |
| std::vector< float > | operator/ (std::vector< T > const &A, float const scalar) |
| template<typename T > | |
| std::vector< T > | operator- (std::vector< T > const &A, std::vector< T > const &B) |
| template<typename T > | |
| std::vector< T > | operator+ (std::vector< T > const &A, std::vector< T > const &B) |
| template<typename T > | |
| std::vector< std::vector< float > > | get_inverse (std::vector< std::vector< T >> const &A) |
| template<typename T > | |
| std::vector< std::vector< T > > | get_transpose (std::vector< std::vector< T >> const &A) |
| template<typename T > | |
| std::vector< float > | fit_OLS_regressor (std::vector< std::vector< T >> const &X, std::vector< T > const &Y) |
| template<typename T > | |
| std::vector< float > | predict_OLS_regressor (std::vector< std::vector< T >> const &X, std::vector< float > const &beta) |
| int | main () |
Linear regression example using Ordinary least squares
| std::vector<float> fit_OLS_regressor | ( | std::vector< std::vector< T >> const & | X, |
| std::vector< T > const & | Y | ||
| ) |
Perform Ordinary Least Squares curve fit. This operation is defined as
\[\beta = \left(X^TXX^T\right)Y\]
| X | feature matrix with rows representing sample vector of features |
| Y | known regression value for each sample |
| std::vector<std::vector<float> > get_inverse | ( | std::vector< std::vector< T >> const & | A | ) |
Get matrix inverse using Row-trasnformations. Given matrix must be a square and non-singular.
| std::vector<std::vector<T> > get_transpose | ( | std::vector< std::vector< T >> const & | A | ) |
matrix transpose
|
inline |
function to check if given matrix is a square matrix
| int main | ( | ) |
main function
| std::vector<float> operator* | ( | float const | scalar, |
| std::vector< T > const & | A | ||
| ) |
pre-multiplication of a vector by a scalar
| std::vector<std::vector<T> > operator* | ( | std::vector< std::vector< T >> const & | A, |
| std::vector< std::vector< T >> const & | B | ||
| ) |
Matrix multiplication such that if A is size (mxn) and B is of size (pxq) then the multiplication is defined only when n = p and the resultant matrix is of size (mxq)
| std::vector<T> operator* | ( | std::vector< std::vector< T >> const & | A, |
| std::vector< T > const & | B | ||
| ) |
multiplication of a matrix with a column vector
| std::vector<float> operator* | ( | std::vector< T > const & | A, |
| float const | scalar | ||
| ) |
post-multiplication of a vector by a scalar
| std::vector<T> operator+ | ( | std::vector< T > const & | A, |
| std::vector< T > const & | B | ||
| ) |
addition of two vectors of identical lengths
| std::vector<T> operator- | ( | std::vector< T > const & | A, |
| std::vector< T > const & | B | ||
| ) |
subtraction of two vectors of identical lengths
| std::vector<float> operator/ | ( | std::vector< T > const & | A, |
| float const | scalar | ||
| ) |
| std::ostream& operator<< | ( | std::ostream & | out, |
| std::vector< std::vector< T >> const & | v | ||
| ) |
operator to print a matrix
| std::ostream& operator<< | ( | std::ostream & | out, |
| std::vector< T > const & | v | ||
| ) |
operator to print a vector
| std::vector<float> predict_OLS_regressor | ( | std::vector< std::vector< T >> const & | X, |
| std::vector< float > const & | beta | ||
| ) |
Given data and OLS model coeffficients, predict regression estimates. This operation is defined as
\[y_{\text{row}=i} = \sum_{j=\text{columns}}\beta_j\cdot X_{i,j}\]
| X | feature matrix with rows representing sample vector of features |
| beta | fitted regression model |