svc.hpp
Go to the documentation of this file.
1 /*
2  * SPDX-FileCopyrightText: Copyright (c) 2019-2025, NVIDIA CORPORATION.
3  * SPDX-License-Identifier: Apache-2.0
4  */
5 
6 #pragma once
7 
8 #include "svm_model.h"
9 #include "svm_parameter.h"
10 
11 #include <cuml/common/logger.hpp>
13 
14 #include <raft/core/handle.hpp>
15 
16 namespace ML {
17 namespace SVM {
18 
19 // Forward declarations of the stateless API
41 template <typename math_t>
42 int svcFit(const raft::handle_t& handle,
43  math_t* input,
44  int n_rows,
45  int n_cols,
46  math_t* labels,
47  const SvmParameter& param,
48  ML::matrix::KernelParams& kernel_params,
49  SvmModel<math_t>& model,
50  const math_t* sample_weight);
51 
75 template <typename math_t>
76 int svcFitSparse(const raft::handle_t& handle,
77  int* indptr,
78  int* indices,
79  math_t* data,
80  int n_rows,
81  int n_cols,
82  int nnz,
83  math_t* labels,
84  const SvmParameter& param,
85  ML::matrix::KernelParams& kernel_params,
86  SvmModel<math_t>& model,
87  const math_t* sample_weight);
88 
118 template <typename math_t>
119 void svcPredict(const raft::handle_t& handle,
120  math_t* input,
121  int n_rows,
122  int n_cols,
123  ML::matrix::KernelParams& kernel_params,
124  const SvmModel<math_t>& model,
125  math_t* preds,
126  math_t buffer_size,
127  bool predict_class);
128 
160 template <typename math_t>
161 void svcPredictSparse(const raft::handle_t& handle,
162  int* indptr,
163  int* indices,
164  math_t* data,
165  int n_rows,
166  int n_cols,
167  int nnz,
168  ML::matrix::KernelParams& kernel_params,
169  const SvmModel<math_t>& model,
170  math_t* preds,
171  math_t buffer_size,
172  bool predict_class);
173 
180 template <typename math_t>
181 void svmFreeBuffers(const raft::handle_t& handle, SvmModel<math_t>& m);
182 
202 template <typename math_t>
203 class SVC {
204  public:
205  // Public members for easier access during testing from Python.
206 
221  SVC(raft::handle_t& handle,
222  math_t C = 1,
223  math_t tol = 1.0e-3,
226  math_t cache_size = 200,
227  int max_iter = -1,
228  int nochange_steps = 1000,
229  rapids_logger::level_enum verbosity = rapids_logger::level_enum::info);
230 
231  ~SVC();
232 
245  void fit(
246  math_t* input, int n_rows, int n_cols, math_t* labels, const math_t* sample_weight = nullptr);
247 
257  void predict(math_t* input, int n_rows, int n_cols, math_t* preds);
258 
268  void decisionFunction(math_t* input, int n_rows, int n_cols, math_t* preds);
269 
270  private:
271  const raft::handle_t& handle;
272 };
273 
274 }; // end namespace SVM
275 }; // end namespace ML
C-Support Vector Classification.
Definition: svc.hpp:203
SvmModel< math_t > model
Definition: svc.hpp:209
ML::matrix::KernelParams kernel_params
Definition: svc.hpp:207
SvmParameter param
Definition: svc.hpp:208
SVC(raft::handle_t &handle, math_t C=1, math_t tol=1.0e-3, ML::matrix::KernelParams kernel_params=ML::matrix::KernelParams{ML::matrix::KernelType::LINEAR, 3, 1, 0}, math_t cache_size=200, int max_iter=-1, int nochange_steps=1000, rapids_logger::level_enum verbosity=rapids_logger::level_enum::info)
Constructs a support vector classifier.
void fit(math_t *input, int n_rows, int n_cols, math_t *labels, const math_t *sample_weight=nullptr)
Fit a support vector classifier to the training data.
void decisionFunction(math_t *input, int n_rows, int n_cols, math_t *preds)
Calculate decision function value for samples in input.
void predict(math_t *input, int n_rows, int n_cols, math_t *preds)
Predict classes for samples in input.
void buffer_size(int n, int batch_size, int frequency, int *start_leveltrend_len, int *start_season_len, int *components_len, int *error_len, int *leveltrend_coef_shift, int *season_coef_shift)
int 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 ¶m, ML::matrix::KernelParams &kernel_params, SvmModel< math_t > &model, const math_t *sample_weight)
Fit a support vector classifier to the training data.
void svcPredictSparse(const raft::handle_t &handle, int *indptr, int *indices, math_t *data, int n_rows, int n_cols, int nnz, ML::matrix::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.
void svcPredict(const raft::handle_t &handle, math_t *input, int n_rows, int n_cols, ML::matrix::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.
int svcFit(const raft::handle_t &handle, math_t *input, int n_rows, int n_cols, math_t *labels, const SvmParameter ¶m, ML::matrix::KernelParams &kernel_params, SvmModel< math_t > &model, const math_t *sample_weight)
Fit a support vector classifier to the training data.
void svmFreeBuffers(const raft::handle_t &handle, SvmModel< math_t > &m)
Definition: dbscan.hpp:18
Definition: svm_model.h:24
Definition: svm_parameter.h:27
Definition: kernel_params.hpp:18