Loading [MathJax]/extensions/tex2jax.js
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
linear.hpp
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2021-2025, NVIDIA CORPORATION.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #pragma once
18 
19 #include <cuml/common/logger.hpp>
20 
21 #include <raft/core/handle.hpp>
22 
23 namespace ML {
24 namespace SVM {
25 
28  enum Penalty {
30  L1,
32  L2
33  };
35  enum Loss {
44  };
45 
51  bool fit_intercept = true;
55  bool penalized_intercept = false;
57  bool probability = false;
59  int max_iter = 1000;
67  int lbfgs_memory = 5;
69  rapids_logger::level_enum verbose = rapids_logger::level_enum::off;
74  double C = 1.0;
76  double grad_tol = 0.0001;
78  double change_tol = 0.00001;
80  double epsilon = 0.0;
81 };
82 
83 template <typename T>
91  T* w;
93  T* classes = nullptr;
101  T* probScale = nullptr;
103  std::size_t nClasses = 0;
105  std::size_t coefRows;
106 
108  inline std::size_t coefCols() const { return nClasses <= 2 ? 1 : nClasses; }
109 
123  static LinearSVMModel<T> fit(const raft::handle_t& handle,
124  const LinearSVMParams& params,
125  const T* X,
126  const std::size_t nRows,
127  const std::size_t nCols,
128  const T* y,
129  const T* sampleWeight);
130 
140  static LinearSVMModel<T> allocate(const raft::handle_t& handle,
141  const LinearSVMParams& params,
142  const std::size_t nCols,
143  const std::size_t nClasses = 0);
144 
146  static void free(const raft::handle_t& handle, LinearSVMModel<T>& model);
147 
159  static void predict(const raft::handle_t& handle,
160  const LinearSVMParams& params,
161  const LinearSVMModel<T>& model,
162  const T* X,
163  const std::size_t nRows,
164  const std::size_t nCols,
165  T* out);
166 
178  static void decisionFunction(const raft::handle_t& handle,
179  const LinearSVMParams& params,
180  const LinearSVMModel<T>& model,
181  const T* X,
182  const std::size_t nRows,
183  const std::size_t nCols,
184  T* out);
185 
198  static void predictProba(const raft::handle_t& handle,
199  const LinearSVMParams& params,
200  const LinearSVMModel<T>& model,
201  const T* X,
202  const std::size_t nRows,
203  const std::size_t nCols,
204  const bool log,
205  T* out);
206 };
207 
208 } // namespace SVM
209 } // namespace ML
Definition: params.hpp:34
Definition: dbscan.hpp:30
penalty
Definition: params.hpp:34
Definition: linear.hpp:84
static void decisionFunction(const raft::handle_t &handle, const LinearSVMParams ¶ms, const LinearSVMModel< T > &model, const T *X, const std::size_t nRows, const std::size_t nCols, T *out)
Calculate decision function value for samples in input.
std::size_t coefCols() const
Definition: linear.hpp:108
std::size_t nClasses
Definition: linear.hpp:103
static void predictProba(const raft::handle_t &handle, const LinearSVMParams ¶ms, const LinearSVMModel< T > &model, const T *X, const std::size_t nRows, const std::size_t nCols, const bool log, T *out)
For SVC, predict the probabilities for each outcome.
static void predict(const raft::handle_t &handle, const LinearSVMParams ¶ms, const LinearSVMModel< T > &model, const T *X, const std::size_t nRows, const std::size_t nCols, T *out)
Predict using the trained LinearSVM model.
static LinearSVMModel< T > fit(const raft::handle_t &handle, const LinearSVMParams ¶ms, const T *X, const std::size_t nRows, const std::size_t nCols, const T *y, const T *sampleWeight)
Allocate and fit the LinearSVM model.
T * w
Definition: linear.hpp:91
static void free(const raft::handle_t &handle, LinearSVMModel< T > &model)
Free the allocated memory. The model is not usable after the call of this method.
static LinearSVMModel< T > allocate(const raft::handle_t &handle, const LinearSVMParams ¶ms, const std::size_t nCols, const std::size_t nClasses=0)
Explicitly allocate the data for the model without training it.
T * probScale
Definition: linear.hpp:101
T * classes
Definition: linear.hpp:93
std::size_t coefRows
Definition: linear.hpp:105
Definition: linear.hpp:26
bool probability
Definition: linear.hpp:57
Loss
Definition: linear.hpp:35
@ EPSILON_INSENSITIVE
Definition: linear.hpp:41
@ HINGE
Definition: linear.hpp:37
@ SQUARED_HINGE
Definition: linear.hpp:39
@ SQUARED_EPSILON_INSENSITIVE
Definition: linear.hpp:43
double epsilon
Definition: linear.hpp:80
bool fit_intercept
Definition: linear.hpp:51
double change_tol
Definition: linear.hpp:78
int linesearch_max_iter
Definition: linear.hpp:63
double C
Definition: linear.hpp:74
int max_iter
Definition: linear.hpp:59
int lbfgs_memory
Definition: linear.hpp:67
Penalty
Definition: linear.hpp:28
@ L2
Definition: linear.hpp:32
@ L1
Definition: linear.hpp:30
rapids_logger::level_enum verbose
Definition: linear.hpp:69
bool penalized_intercept
Definition: linear.hpp:55
double grad_tol
Definition: linear.hpp:76
Loss loss
Definition: linear.hpp:49