Namespaces | Functions
ML::Solver Namespace Reference

Namespaces

 Lars
 

Functions

void sgdFit (raft::handle_t &handle, float *input, int n_rows, int n_cols, float *labels, float *coef, float *intercept, bool fit_intercept, int batch_size, int epochs, int lr_type, float eta0, float power_t, int loss, int penalty, float alpha, float l1_ratio, bool shuffle, float tol, int n_iter_no_change)
 
void sgdFit (raft::handle_t &handle, double *input, int n_rows, int n_cols, double *labels, double *coef, double *intercept, bool fit_intercept, int batch_size, int epochs, int lr_type, double eta0, double power_t, int loss, int penalty, double alpha, double l1_ratio, bool shuffle, double tol, int n_iter_no_change)
 
void sgdPredict (raft::handle_t &handle, const float *input, int n_rows, int n_cols, const float *coef, float intercept, float *preds, int loss)
 
void sgdPredict (raft::handle_t &handle, const double *input, int n_rows, int n_cols, const double *coef, double intercept, double *preds, int loss)
 
void sgdPredictBinaryClass (raft::handle_t &handle, const float *input, int n_rows, int n_cols, const float *coef, float intercept, float *preds, int loss)
 
void sgdPredictBinaryClass (raft::handle_t &handle, const double *input, int n_rows, int n_cols, const double *coef, double intercept, double *preds, int loss)
 
void cdFit (raft::handle_t &handle, float *input, int n_rows, int n_cols, float *labels, float *coef, float *intercept, bool fit_intercept, bool normalize, int epochs, int loss, float alpha, float l1_ratio, bool shuffle, float tol, float *sample_weight=nullptr)
 
void cdFit (raft::handle_t &handle, double *input, int n_rows, int n_cols, double *labels, double *coef, double *intercept, bool fit_intercept, bool normalize, int epochs, int loss, double alpha, double l1_ratio, bool shuffle, double tol, double *sample_weight=nullptr)
 
void cdPredict (raft::handle_t &handle, const float *input, int n_rows, int n_cols, const float *coef, float intercept, float *preds, int loss)
 
void cdPredict (raft::handle_t &handle, const double *input, int n_rows, int n_cols, const double *coef, double intercept, double *preds, int loss)
 
template<typename math_t >
math_t max (math_t a, math_t b)
 
template<typename math_t >
math_t invScaling (math_t eta, math_t power_t, int t)
 
template<typename math_t >
math_t regDLoss (math_t a, math_t b)
 
template<typename math_t >
math_t calOptimalInit (math_t alpha)
 
template<typename math_t >
math_t optimal (math_t alpha, math_t optimal_init, int t)
 
template<typename math_t >
math_t calLearningRate (ML::lr_type lr_type, math_t eta, math_t power_t, math_t alpha, math_t t)
 
template<typename math_t >
void initShuffle (std::vector< math_t > &rand_indices, std::mt19937 &g, math_t random_state=0)
 
template<typename math_t >
void shuffle (std::vector< math_t > &rand_indices, std::mt19937 &g)
 

Function Documentation

◆ calLearningRate()

template<typename math_t >
math_t ML::Solver::calLearningRate ( ML::lr_type  lr_type,
math_t  eta,
math_t  power_t,
math_t  alpha,
math_t  t 
)

◆ calOptimalInit()

template<typename math_t >
math_t ML::Solver::calOptimalInit ( math_t  alpha)

◆ cdFit() [1/2]

void ML::Solver::cdFit ( raft::handle_t &  handle,
double *  input,
int  n_rows,
int  n_cols,
double *  labels,
double *  coef,
double *  intercept,
bool  fit_intercept,
bool  normalize,
int  epochs,
int  loss,
double  alpha,
double  l1_ratio,
bool  shuffle,
double  tol,
double *  sample_weight = nullptr 
)

◆ cdFit() [2/2]

void ML::Solver::cdFit ( raft::handle_t &  handle,
float *  input,
int  n_rows,
int  n_cols,
float *  labels,
float *  coef,
float *  intercept,
bool  fit_intercept,
bool  normalize,
int  epochs,
int  loss,
float  alpha,
float  l1_ratio,
bool  shuffle,
float  tol,
float *  sample_weight = nullptr 
)

Fits a linear, lasso, and elastic-net regression model using Coordinate Descent solver.

i.e. finds coefficients that minimize the following loss function:

f(coef) = 1/2 * || labels - input * coef ||^2

  • 1/2 * alpha * (1 - l1_ratio) * ||coef||^2
  • alpha * l1_ratio * ||coef||_1
Parameters
handleReference of raft::handle_t
inputpointer to an array in column-major format (size of n_rows, n_cols)
n_rowsn_samples or rows in input
n_colsn_features or columns in X
labelspointer to an array for labels (size of n_rows)
coefpointer to an array for coefficients (size of n_cols). This will be filled with coefficients once the function is executed.
interceptpointer to a scalar for intercept. This will be filled once the function is executed
fit_interceptboolean parameter to control if the intercept will be fitted or not
normalizeboolean parameter to control if the data will be normalized or not; NB: the input is scaled by the column-wise biased sample standard deviation estimator.
epochsMaximum number of iterations that solver will run
lossenum to use different loss functions. Only linear regression loss functions is supported right now
alphaL1 parameter
l1_ratioratio of alpha will be used for L1. (1 - l1_ratio) * alpha will be used for L2
shuffleboolean parameter to control whether coordinates will be picked randomly or not
toltolerance to stop the solver
sample_weightdevice pointer to sample weight vector of length n_rows (nullptr or uniform weights) This vector is modified during the computation

◆ cdPredict() [1/2]

void ML::Solver::cdPredict ( raft::handle_t &  handle,
const double *  input,
int  n_rows,
int  n_cols,
const double *  coef,
double  intercept,
double *  preds,
int  loss 
)

◆ cdPredict() [2/2]

void ML::Solver::cdPredict ( raft::handle_t &  handle,
const float *  input,
int  n_rows,
int  n_cols,
const float *  coef,
float  intercept,
float *  preds,
int  loss 
)

◆ initShuffle()

template<typename math_t >
void ML::Solver::initShuffle ( std::vector< math_t > &  rand_indices,
std::mt19937 &  g,
math_t  random_state = 0 
)

◆ invScaling()

template<typename math_t >
math_t ML::Solver::invScaling ( math_t  eta,
math_t  power_t,
int  t 
)

◆ max()

template<typename math_t >
math_t ML::Solver::max ( math_t  a,
math_t  b 
)

◆ optimal()

template<typename math_t >
math_t ML::Solver::optimal ( math_t  alpha,
math_t  optimal_init,
int  t 
)

◆ regDLoss()

template<typename math_t >
math_t ML::Solver::regDLoss ( math_t  a,
math_t  b 
)

◆ sgdFit() [1/2]

void ML::Solver::sgdFit ( raft::handle_t &  handle,
double *  input,
int  n_rows,
int  n_cols,
double *  labels,
double *  coef,
double *  intercept,
bool  fit_intercept,
int  batch_size,
int  epochs,
int  lr_type,
double  eta0,
double  power_t,
int  loss,
int  penalty,
double  alpha,
double  l1_ratio,
bool  shuffle,
double  tol,
int  n_iter_no_change 
)

◆ sgdFit() [2/2]

void ML::Solver::sgdFit ( raft::handle_t &  handle,
float *  input,
int  n_rows,
int  n_cols,
float *  labels,
float *  coef,
float *  intercept,
bool  fit_intercept,
int  batch_size,
int  epochs,
int  lr_type,
float  eta0,
float  power_t,
int  loss,
int  penalty,
float  alpha,
float  l1_ratio,
bool  shuffle,
float  tol,
int  n_iter_no_change 
)

◆ sgdPredict() [1/2]

void ML::Solver::sgdPredict ( raft::handle_t &  handle,
const double *  input,
int  n_rows,
int  n_cols,
const double *  coef,
double  intercept,
double *  preds,
int  loss 
)

◆ sgdPredict() [2/2]

void ML::Solver::sgdPredict ( raft::handle_t &  handle,
const float *  input,
int  n_rows,
int  n_cols,
const float *  coef,
float  intercept,
float *  preds,
int  loss 
)

◆ sgdPredictBinaryClass() [1/2]

void ML::Solver::sgdPredictBinaryClass ( raft::handle_t &  handle,
const double *  input,
int  n_rows,
int  n_cols,
const double *  coef,
double  intercept,
double *  preds,
int  loss 
)

◆ sgdPredictBinaryClass() [2/2]

void ML::Solver::sgdPredictBinaryClass ( raft::handle_t &  handle,
const float *  input,
int  n_rows,
int  n_cols,
const float *  coef,
float  intercept,
float *  preds,
int  loss 
)

◆ shuffle()

template<typename math_t >
void ML::Solver::shuffle ( std::vector< math_t > &  rand_indices,
std::mt19937 &  g 
)