Conscience Core
Classes | Public Member Functions | Static Public Member Functions | List of all members
CscSupervisedLearningRegression Class Reference

#include <CscSupervisedLearningRegression.h>

Classes

struct  RegressionInputsData
 
struct  RegressionOutputsData
 

Public Member Functions

 CscSupervisedLearningRegression (RegressionInputsData regressionInputsData)
 
RegressionOutputsData polynomialRegression (const int degree, bool dataToCsv=false)
 This method performs polynomial regression on the given input data. More...
 
RegressionOutputsData bestDegreePolynomialRegression (bool saveToCsv=false)
 This method iteratively trains polynomial regression models of increasing degree until the coefficient of determination (R^2) stops improving. More...
 

Static Public Member Functions

static float findMaxLocal (const vector< float > &coeffPolynomial, float minBounding, float maxBounding, float precision)
 This method is used to find the local maximum of a polynomial function of one variable within a given interval. More...
 

Constructor & Destructor Documentation

◆ CscSupervisedLearningRegression()

CscSupervisedLearningRegression::CscSupervisedLearningRegression ( RegressionInputsData  regressionInputsData)

Member Function Documentation

◆ bestDegreePolynomialRegression()

CscSupervisedLearningRegression::RegressionOutputsData CscSupervisedLearningRegression::bestDegreePolynomialRegression ( bool  saveToCsv = false)

This method iteratively trains polynomial regression models of increasing degree until the coefficient of determination (R^2) stops improving.

The method starts with a polynomial regression of degree 1 and continues to increase the degree until the R^2 value of the current model is less than the R^2 value of the previous model. The model with the highest R^2 value is then considered to be the best.

Note: This method assumes that the polynomialRegression method is implemented and works as expected.

Returns
The best trained model's output data as an object of the RegressionOutputsData class, containing the highest coefficient of determination and the corresponding coefficients of the polynomial function.

◆ findMaxLocal()

float CscSupervisedLearningRegression::findMaxLocal ( const vector< float > &  coeffPolynomial,
float  minBounding,
float  maxBounding,
float  precision 
)
static

This method is used to find the local maximum of a polynomial function of one variable within a given interval.

The polynomial function is defined by a vector of coefficients passed as an argument. The method evaluates the polynomial function at a series of points in the interval defined by minBounding and maxBounding, using the precision value to determine the spacing between these points. The method returns the x-value where the polynomial function reaches its local maximum within the given interval.

Parameters
coeffPolynomialA vector of coefficients defining the polynomial function. First value correspond to coefficient of x⁰, second to x¹, third to x², etc.
minBoundingThe lower bound of the interval within which to search for the local maximum.
maxBoundingThe upper bound of the interval within which to search for the local maximum.
precisionThe spacing between points in the interval at which the polynomial function is evaluated. A smaller value will result in a more precise maximum, but will increase computation time.
Returns
The x-value within the given interval where the polynomial function reaches its local maximum.

◆ polynomialRegression()

CscSupervisedLearningRegression::RegressionOutputsData CscSupervisedLearningRegression::polynomialRegression ( const int  degree,
bool  dataToCsv = false 
)

This method performs polynomial regression on the given input data.

The method first transforms the given input data into the Eigen::MatrixXf format, then applies polynomial transformation on the input data up to the given degree. A linear regression model is then trained on this transformed data. The trained model is then tested on the input data and the coefficient of determination is calculated. If the dataToCsv flag is set, the method will print the results in a csv file.

Parameters
dataInputsThe input data for the regression in the form of regressionInputsData object. This object contains a vector of vectors, where each inner vector represents a data point and the elements of the inner vector represent the features of that point.
degreeThe degree of the polynomial transformation to be applied on the input data.
dataToCsvA boolean flag that, if set to true, will print the results in a csv file.
Returns
A CscSupervisedLearningRegression::regressionOutputsData object that contains the coefficient of determination and the coefficients of the polynomial function obtained from the regression.

The documentation for this class was generated from the following files: