22 #include <raft/core/handle.hpp>
24 #include <rmm/device_scalar.hpp>
25 #include <rmm/device_uvector.hpp>
27 #include <thrust/device_ptr.h>
36 #include <type_traits>
66 template <
typename math_t>
71 raft::distance::kernels::KernelType kernel_type,
72 raft::distance::kernels::GramMatrixBase<math_t>* kernel)
77 kernel_type(kernel_type),
78 cache_size(param.cache_size),
79 nochange_steps(param.nochange_steps),
80 epsilon(param.epsilon),
81 svmType(param.svmType),
82 stream(handle.get_stream()),
83 return_buff(2, stream),
86 delta_alpha(0, stream),
121 template <
typename MatrixViewType>
126 const math_t* sample_weight,
132 int max_outer_iter = -1,
133 int max_inner_iter = 10000);
150 void UpdateF(math_t* f,
int n_rows,
const math_t* delta_alpha,
int n_ws,
const math_t* cacheTile);
173 void Initialize(math_t** y,
const math_t* sample_weight,
int n_rows,
int n_cols);
175 void InitPenalty(math_t* C_vec,
const math_t* sample_weight,
int n_rows);
224 void SvrInit(
const math_t* yr,
int n_rows, math_t* yc, math_t* f);
227 const raft::handle_t& handle;
236 rmm::device_uvector<math_t> alpha;
237 rmm::device_uvector<math_t> f;
238 rmm::device_uvector<math_t> y_label;
240 rmm::device_uvector<math_t> C_vec;
244 rmm::device_uvector<math_t> delta_alpha;
248 rmm::device_uvector<math_t> return_buff;
249 math_t host_return_buff[2];
255 raft::distance::kernels::GramMatrixBase<math_t>* kernel;
256 raft::distance::kernels::KernelType kernel_type;
265 int n_increased_diff;
267 bool report_increased_diff;
269 bool CheckStoppingCondition(math_t diff)
271 if (diff > diff_prev * 1.5 && n_iter > 0) {
280 if (report_increased_diff && n_iter > 100 && n_increased_diff > n_iter * 0.1) {
282 "Solver is not converging monotonically. This might be caused by "
283 "insufficient normalization of the feature columns. In that case "
284 "MinMaxScaler((0,1)) could help. Alternatively, for nonlinear kernels, "
285 "you can try to increase the gamma parameter. To limit execution time, "
286 "you can also adjust the number of iterations using the max_iter "
288 report_increased_diff =
false;
290 bool keep_going =
true;
291 if (abs(diff - diff_prev) < 0.001 * tol) {
297 if (n_small_diff > nochange_steps) {
299 "SMO error: Stopping due to unchanged diff over %d"
300 " consecutive steps",
304 if (diff < tol) keep_going =
false;
307 if (std::is_same<float, math_t>::value) {
309 " This might be caused by floating point overflow. In such case using"
310 " fp64 could help. Alternatively, try gamma='scale' kernel"
313 THROW(
"SMO error: NaN found during fitting.%s", txt.c_str());
319 int GetDefaultMaxIter(
int n_train,
int max_outer_iter)
321 if (max_outer_iter == -1) {
325 max_outer_iter =
max(100000, max_outer_iter);
328 return max_outer_iter;
331 void ResizeBuffers(
int n_train,
int n_cols)
334 alpha.resize(n_train, stream);
335 C_vec.resize(n_train, stream);
336 f.resize(n_train, stream);
337 delta_alpha.resize(n_ws, stream);
338 if (svmType ==
EPSILON_SVR) y_label.resize(n_train, stream);
341 void ReleaseBuffers()
344 delta_alpha.release();
void setLevel(int level)
Set the logging level.
Definition: logger.cpp:67
static Logger & get()
Singleton method to get the underlying logger object.
Definition: logger.cpp:52
Solve the quadratic optimization problem using two level decomposition and Sequential Minimal Optimiz...
Definition: smosolver.h:67
void SvrInit(const math_t *yr, int n_rows, math_t *yc, math_t *f)
Initializes the solver for epsilon-SVR.
void UpdateF(math_t *f, int n_rows, const math_t *delta_alpha, int n_ws, const math_t *cacheTile)
Update the f vector after a block solve step.
void Initialize(math_t **y, const math_t *sample_weight, int n_rows, int n_cols)
Initialize the problem to solve.
void SvcInit(const math_t *y)
Initialize Support Vector Classification.
void GetNonzeroDeltaAlpha(const math_t *vec, int n_ws, const int *idx, math_t *nz_vec, int *n_nz, int *nz_idx, cudaStream_t stream)
void Solve(MatrixViewType matrix, int n_rows, int n_cols, math_t *y, const math_t *sample_weight, math_t **dual_coefs, int *n_support, SupportStorage< math_t > *support_matrix, int **idx, math_t *b, int max_outer_iter=-1, int max_inner_iter=10000)
Solve the quadratic optimization problem.
void InitPenalty(math_t *C_vec, const math_t *sample_weight, int n_rows)
SmoSolver(const raft::handle_t &handle, SvmParameter param, raft::distance::kernels::KernelType kernel_type, raft::distance::kernels::GramMatrixBase< math_t > *kernel)
Definition: smosolver.h:69
#define CUML_LOG_ERROR(fmt,...)
Definition: logger.hpp:222
#define CUML_LOG_DEBUG(fmt,...)
Definition: logger.hpp:198
SvmType
Definition: svm_parameter.h:21
@ EPSILON_SVR
Definition: svm_parameter.h:21
math_t max(math_t a, math_t b)
Definition: learning_rate.h:27
Definition: dbscan.hpp:30
Definition: svm_model.h:23
Definition: svm_parameter.h:34
int verbosity
Print information about training.
Definition: svm_parameter.h:42