SecreC 2 language 2.9.0 (2026.10)
Language and standard library reference
Loading...
Searching...
No Matches
Functions

Functions

template<domain D :shared3p >
D float32 linearRegressionCG (D int32 variables, D int32 dependent, uint iterations)
 
template<domain D :shared3p >
D float64 linearRegressionCG (D int64 variables, D int64 dependent, uint iterations)
 
template<domain D :shared3p >
D float32 linearRegressionCG (D float32 variables, D float32 dependent, uint iterations)
 
template<domain D :shared3p >
D float64 linearRegressionCG (D float64 variables, D float64 dependent, uint iterations)
 

Detailed Description

Fitting of linear models with multiple explanatory variables using the conjugate gradient method.

Note
D - shared3p protection domain
Supported types - int32 / int64 / float32 / float64
You can pass an empty matrix as the variables argument to specify a null model with just intercept.
Parameters
variables- a matrix where each column is a sample of an explanatory variable
dependent- sample vector of dependent variable
iterations- number of iterations to use. Empirical testing showed that 10 iterations provides better accuracy than LU decomposition and Gaussian elimination and with a high number of variables it is also faster.
Returns
returns vector {β_1, β_1, …, β_n} such that y ≈ β_1 * x_1 + β_2 * x_2 + … + β_(n-1) * x_(n-1) + β_n where y is the dependent variable and x_i are the explanatory variables.
Leakage
None

Function Documentation

◆ linearRegressionCG() [1/4]

template<domain D :shared3p >
D float32 linearRegressionCG ( D float32  variables,
D float32  dependent,
uint  iterations 
)

◆ linearRegressionCG() [2/4]

template<domain D :shared3p >
D float64 linearRegressionCG ( D float64  variables,
D float64  dependent,
uint  iterations 
)

◆ linearRegressionCG() [3/4]

template<domain D :shared3p >
D float32 linearRegressionCG ( D int32  variables,
D int32  dependent,
uint  iterations 
)

◆ linearRegressionCG() [4/4]

template<domain D :shared3p >
D float64 linearRegressionCG ( D int64  variables,
D int64  dependent,
uint  iterations 
)