Classes | Enumerations | Functions
ML::SVM Namespace Reference

Classes

struct  LinearSVMParams
 
struct  LinearSVMModel
 
class  SVC
 C-Support Vector Classification. More...
 
struct  SupportStorage
 
struct  SvmModel
 
struct  SvmParameter
 
class  SmoSolver
 Solve the quadratic optimization problem using two level decomposition and Sequential Minimal Optimization (SMO). More...
 
class  WorkingSet
 

Enumerations

enum  SvmType { C_SVC , NU_SVC , EPSILON_SVR , NU_SVR }
 

Functions

template<typename math_t >
void svcFit (const raft::handle_t &handle, math_t *input, int n_rows, int n_cols, math_t *labels, const SvmParameter &param, raft::distance::kernels::KernelParams &kernel_params, SvmModel< math_t > &model, const math_t *sample_weight)
 Fit a support vector classifier to the training data. More...
 
template<typename math_t >
void svcFitSparse (const raft::handle_t &handle, int *indptr, int *indices, math_t *data, int n_rows, int n_cols, int nnz, math_t *labels, const SvmParameter &param, raft::distance::kernels::KernelParams &kernel_params, SvmModel< math_t > &model, const math_t *sample_weight)
 Fit a support vector classifier to the training data. More...
 
template<typename math_t >
void svcPredict (const raft::handle_t &handle, math_t *input, int n_rows, int n_cols, raft::distance::kernels::KernelParams &kernel_params, const SvmModel< math_t > &model, math_t *preds, math_t buffer_size, bool predict_class)
 Predict classes or decision function value for samples in input. More...
 
template<typename math_t >
void svcPredictSparse (const raft::handle_t &handle, int *indptr, int *indices, math_t *data, int n_rows, int n_cols, int nnz, raft::distance::kernels::KernelParams &kernel_params, const SvmModel< math_t > &model, math_t *preds, math_t buffer_size, bool predict_class)
 Predict classes or decision function value for samples in input. More...
 
template<typename math_t >
void svmFreeBuffers (const raft::handle_t &handle, SvmModel< math_t > &m)
 
template<typename math_t >
void svrFit (const raft::handle_t &handle, math_t *X, int n_rows, int n_cols, math_t *y, const SvmParameter &param, MLCommon::Matrix::KernelParams &kernel_params, SvmModel< math_t > &model, const math_t *sample_weight=nullptr)
 Fit a support vector regressor to the training data. More...
 
template<typename math_t >
void svrFitSparse (const raft::handle_t &handle, int *indptr, int *indices, math_t *data, int n_rows, int n_cols, int nnz, math_t *y, const SvmParameter &param, raft::distance::kernels::KernelParams &kernel_params, SvmModel< math_t > &model, const math_t *sample_weight=nullptr)
 Fit a support vector regressor to the training data. More...
 

Enumeration Type Documentation

◆ SvmType

Enumerator
C_SVC 
NU_SVC 
EPSILON_SVR 
NU_SVR 

Function Documentation

◆ svcFit()

template<typename math_t >
void ML::SVM::svcFit ( const raft::handle_t &  handle,
math_t *  input,
int  n_rows,
int  n_cols,
math_t *  labels,
const SvmParameter param,
raft::distance::kernels::KernelParams &  kernel_params,
SvmModel< math_t > &  model,
const math_t *  sample_weight 
)

Fit a support vector classifier to the training data.

Each row of the input data stores a feature vector. We use the SMO method to fit the SVM.

The output device buffers in model shall be unallocated on entry.

Template Parameters
math_tfloating point type
Parameters
[in]handlethe cuML handle
[in]inputdevice pointer for the input data in column major format. Size n_rows x n_cols.
[in]n_rowsnumber of rows
[in]n_colsnumber of columns
[in]labelsdevice pointer for the labels. Size [n_rows].
[in]paramparameters for training
[in]kernel_paramsparameters for the kernel function
[out]modelparameters of the trained model
[in]sample_weightoptional sample weights, size [n_rows]

◆ svcFitSparse()

template<typename math_t >
void ML::SVM::svcFitSparse ( const raft::handle_t &  handle,
int *  indptr,
int *  indices,
math_t *  data,
int  n_rows,
int  n_cols,
int  nnz,
math_t *  labels,
const SvmParameter param,
raft::distance::kernels::KernelParams &  kernel_params,
SvmModel< math_t > &  model,
const math_t *  sample_weight 
)

Fit a support vector classifier to the training data.

Each row of the input data stores a feature vector. We use the SMO method to fit the SVM.

The output device buffers in model shall be unallocated on entry.

Template Parameters
math_tfloating point type
Parameters
[in]handlethe cuML handle
[in]indptrdevice pointer for CSR row positions. Size [n_rows + 1].
[in]indicesdevice pointer for CSR column indices. Size [nnz].
[in]datadevice pointer for the CSR data. Size [nnz].
[in]n_rowsnumber of rows
[in]n_colsnumber of columns
[in]nnznumber of stored entries.
[in]labelsdevice pointer for the labels. Size [n_rows].
[in]paramparameters for training
[in]kernel_paramsparameters for the kernel function
[out]modelparameters of the trained model
[in]sample_weightoptional sample weights, size [n_rows]

◆ svcPredict()

template<typename math_t >
void ML::SVM::svcPredict ( const raft::handle_t &  handle,
math_t *  input,
int  n_rows,
int  n_cols,
raft::distance::kernels::KernelParams &  kernel_params,
const SvmModel< math_t > &  model,
math_t *  preds,
math_t  buffer_size,
bool  predict_class 
)

Predict classes or decision function value for samples in input.

We evaluate the decision function f(x_i). Depending on the parameter predict_class, we either return f(x_i) or the label corresponding to sign(f(x_i)).

The predictions are calculated according to the following formulas:

\[ f(x_i) = \sum_{j=1}^n_support K(x_i, x_j) * dual_coefs[j] + b) \]

pred(x_i) = label[sign(f(x_i))], if predict_class==true, or pred(x_i) = f(x_i), if predict_class==false.

Template Parameters
math_tfloating point type
Parameters
handlethe cuML handle
[in]inputdevice pointer for the input data in column major format, size [n_rows x n_cols].
[in]n_rowsnumber of rows (input vectors)
[in]n_colsnumber of columns (features)
[in]kernel_paramsparameters for the kernel function
[in]modelSVM model parameters
[out]predsdevice pointer to store the predicted class labels. Size [n_rows]. Should be allocated on entry.
[in]buffer_sizesize of temporary buffer in MiB
[in]predict_classwhether to predict class label (true), or just return the decision function value (false)

◆ svcPredictSparse()

template<typename math_t >
void ML::SVM::svcPredictSparse ( const raft::handle_t &  handle,
int *  indptr,
int *  indices,
math_t *  data,
int  n_rows,
int  n_cols,
int  nnz,
raft::distance::kernels::KernelParams &  kernel_params,
const SvmModel< math_t > &  model,
math_t *  preds,
math_t  buffer_size,
bool  predict_class 
)

Predict classes or decision function value for samples in input.

We evaluate the decision function f(x_i). Depending on the parameter predict_class, we either return f(x_i) or the label corresponding to sign(f(x_i)).

The predictions are calculated according to the following formulas:

\[ f(x_i) = \sum_{j=1}^n_support K(x_i, x_j) * dual_coefs[j] + b) \]

pred(x_i) = label[sign(f(x_i))], if predict_class==true, or pred(x_i) = f(x_i), if predict_class==falsee.

Template Parameters
math_tfloating point type
Parameters
handlethe cuML handle
[in]indptrdevice pointer for CSR row positions. Size [n_rows + 1].
[in]indicesdevice pointer for CSR column indices. Size [nnz].
[in]datadevice pointer for the CSR data. Size [nnz].
[in]n_rowsnumber of rows
[in]n_colsnumber of columns
[in]nnznumber of stored entries.
[in]kernel_paramsparameters for the kernel function
[in]modelSVM model parameters
[out]predsdevice pointer to store the predicted class labels. Size [n_rows]. Should be allocated on entry.
[in]buffer_sizesize of temporary buffer in MiB
[in]predict_classwhether to predict class label (true), or just return the decision function value (false)

◆ svmFreeBuffers()

template<typename math_t >
void ML::SVM::svmFreeBuffers ( const raft::handle_t &  handle,
SvmModel< math_t > &  m 
)

Deallocate device buffers in the SvmModel struct.

Parameters
[in]handlecuML handle
[in,out]mSVM model parameters

◆ svrFit()

template<typename math_t >
void ML::SVM::svrFit ( const raft::handle_t &  handle,
math_t *  X,
int  n_rows,
int  n_cols,
math_t *  y,
const SvmParameter param,
MLCommon::Matrix::KernelParams &  kernel_params,
SvmModel< math_t > &  model,
const math_t *  sample_weight = nullptr 
)

Fit a support vector regressor to the training data.

Each row of the input data stores a feature vector.

The output buffers in model shall be unallocated on entry.

Template Parameters
math_tfloating point type
Parameters
[in]handlethe cuML handle
[in]Xdevice pointer for the input data in column major format. Size n_rows x n_cols.
[in]n_rowsnumber of rows
[in]n_colsnumber of columns
[in]ydevice pointer for target values. Size [n_rows].
[in]paramparameters for training
[in]kernel_paramsparameters for the kernel function
[out]modelparameters of the trained model
[in]sample_weightoptional sample weights, size [n_rows]

◆ svrFitSparse()

template<typename math_t >
void ML::SVM::svrFitSparse ( const raft::handle_t &  handle,
int *  indptr,
int *  indices,
math_t *  data,
int  n_rows,
int  n_cols,
int  nnz,
math_t *  y,
const SvmParameter param,
raft::distance::kernels::KernelParams &  kernel_params,
SvmModel< math_t > &  model,
const math_t *  sample_weight = nullptr 
)

Fit a support vector regressor to the training data.

Each row of the input data stores a feature vector.

The output buffers in model shall be unallocated on entry.

Template Parameters
math_tfloating point type
Parameters
[in]handlethe cuML handle
[in]indptrdevice pointer for CSR row positions. Size [n_rows + 1].
[in]indicesdevice pointer for CSR column indices. Size [nnz].
[in]datadevice pointer for the CSR data. Size [nnz].
[in]n_rowsnumber of rows
[in]n_colsnumber of columns
[in]nnznumber of stored entries.
[in]ydevice pointer for target values. Size [n_rows].
[in]paramparameters for training
[in]kernel_paramsparameters for the kernel function
[out]modelparameters of the trained model
[in]sample_weightoptional sample weights, size [n_rows]