22 #include <raft/core/handle.hpp>
24 #include <rmm/device_scalar.hpp>
25 #include <rmm/device_uvector.hpp>
27 #include <thrust/device_ptr.h>
29 #include <cuvs/distance/distance.hpp>
30 #include <cuvs/distance/grammian.hpp>
39 #include <type_traits>
69 template <
typename math_t>
75 cuvs::distance::kernels::GramMatrixBase<math_t>* kernel)
80 kernel_type(kernel_type),
81 cache_size(param.cache_size),
82 nochange_steps(param.nochange_steps),
83 epsilon(param.epsilon),
84 svmType(param.svmType),
85 stream(handle.get_stream()),
86 return_buff(2, stream),
89 delta_alpha(0, stream),
102 cudaStream_t stream);
124 template <
typename MatrixViewType>
129 const math_t* sample_weight,
135 int max_outer_iter = -1,
136 int max_inner_iter = 10000);
153 void UpdateF(math_t* f,
int n_rows,
const math_t* delta_alpha,
int n_ws,
const math_t* cacheTile);
176 void Initialize(math_t** y,
const math_t* sample_weight,
int n_rows,
int n_cols);
178 void InitPenalty(math_t* C_vec,
const math_t* sample_weight,
int n_rows);
227 void SvrInit(
const math_t* yr,
int n_rows, math_t* yc, math_t* f);
230 const raft::handle_t& handle;
239 rmm::device_uvector<math_t> alpha;
240 rmm::device_uvector<math_t> f;
241 rmm::device_uvector<math_t> y_label;
243 rmm::device_uvector<math_t> C_vec;
247 rmm::device_uvector<math_t> delta_alpha;
251 rmm::device_uvector<math_t> return_buff;
252 math_t host_return_buff[2];
258 cuvs::distance::kernels::GramMatrixBase<math_t>* kernel;
268 int n_increased_diff;
270 bool report_increased_diff;
272 bool CheckStoppingCondition(math_t diff)
274 if (diff > diff_prev * 1.5 && n_iter > 0) {
283 if (report_increased_diff && n_iter > 100 && n_increased_diff > n_iter * 0.1) {
285 "Solver is not converging monotonically. This might be caused by "
286 "insufficient normalization of the feature columns. In that case "
287 "MinMaxScaler((0,1)) could help. Alternatively, for nonlinear kernels, "
288 "you can try to increase the gamma parameter. To limit execution time, "
289 "you can also adjust the number of iterations using the max_iter "
291 report_increased_diff =
false;
293 bool keep_going =
true;
294 if (abs(diff - diff_prev) < 0.001 * tol) {
300 if (n_small_diff > nochange_steps) {
302 "SMO error: Stopping due to unchanged diff over %d"
303 " consecutive steps",
307 if (diff < tol) keep_going =
false;
310 if (std::is_same<float, math_t>::value) {
312 " This might be caused by floating point overflow. In such case using"
313 " fp64 could help. Alternatively, try gamma='scale' kernel"
316 THROW(
"SMO error: NaN found during fitting.%s", txt.c_str());
322 int GetDefaultMaxIter(
int n_train,
int max_outer_iter)
324 if (max_outer_iter == -1) {
328 max_outer_iter =
max(100000, max_outer_iter);
331 return max_outer_iter;
334 void ResizeBuffers(
int n_train,
int n_cols)
337 alpha.resize(n_train, stream);
338 C_vec.resize(n_train, stream);
339 f.resize(n_train, stream);
340 delta_alpha.resize(n_ws, stream);
341 if (svmType ==
EPSILON_SVR) y_label.resize(n_train, stream);
344 void ReleaseBuffers()
347 delta_alpha.release();
Solve the quadratic optimization problem using two level decomposition and Sequential Minimal Optimiz...
Definition: smosolver.h:70
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, cuvs::distance::kernels::KernelType kernel_type, cuvs::distance::kernels::GramMatrixBase< math_t > *kernel)
Definition: smosolver.h:72
SvmType
Definition: svm_parameter.h:23
@ EPSILON_SVR
Definition: svm_parameter.h:23
math_t max(math_t a, math_t b)
Definition: learning_rate.h:27
KernelType
Definition: kernel_params.hpp:27
Definition: dbscan.hpp:29
rapids_logger::logger & default_logger()
Get the default logger.
Definition: logger.hpp:54
Definition: svm_model.h:23
Definition: svm_parameter.h:36
rapids_logger::level_enum verbosity
Print information about training.
Definition: svm_parameter.h:44