| Algorithms_in_C++ 1.0.0
    Set of algorithms implemented in C++. | 
Linear regression example using Ordinary least squares More...
#include <cassert>#include <cmath>#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) | 
| void | ols_test () | 
| int | main () | 
Linear regression example using Ordinary least squares
Program that gets the number of data samples and number of features per sample along with output per sample. It applies OLS regression to compute the regression output for additional test data samples.
| 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 | ) | 
| 
 | inline | 
| int main | ( | void | ) | 
main function
| void ols_test | ( | ) | 
Self test checks
| 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 | ||
| ) | 
division of a vector by a 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 |