11 #include <raft/core/handle.hpp>
13 #include <rmm/device_scalar.hpp>
14 #include <rmm/device_uvector.hpp>
16 #include <thrust/device_ptr.h>
18 #include <cuvs/distance/distance.hpp>
19 #include <cuvs/distance/grammian.hpp>
28 #include <type_traits>
58 template <
typename math_t>
64 cuvs::distance::kernels::GramMatrixBase<math_t>* kernel)
69 kernel_type(kernel_type),
70 cache_size(param.cache_size),
71 nochange_steps(param.nochange_steps),
72 epsilon(param.epsilon),
73 svmType(param.svmType),
74 stream(handle.get_stream()),
75 return_buff(2, stream),
78 delta_alpha(0, stream),
114 template <
typename MatrixViewType>
119 const math_t* sample_weight,
126 int max_outer_iter = -1,
127 int max_inner_iter = 10000);
144 void UpdateF(math_t* f,
int n_rows,
const math_t* delta_alpha,
int n_ws,
const math_t* cacheTile);
167 void Initialize(math_t** y,
const math_t* sample_weight,
int n_rows,
int n_cols);
169 void InitPenalty(math_t* C_vec,
const math_t* sample_weight,
int n_rows);
218 void SvrInit(
const math_t* yr,
int n_rows, math_t* yc, math_t* f);
223 const raft::handle_t& handle;
232 rmm::device_uvector<math_t> alpha;
233 rmm::device_uvector<math_t> f;
234 rmm::device_uvector<math_t> y_label;
236 rmm::device_uvector<math_t> C_vec;
240 rmm::device_uvector<math_t> delta_alpha;
244 rmm::device_uvector<math_t> return_buff;
245 math_t host_return_buff[2];
251 cuvs::distance::kernels::GramMatrixBase<math_t>* kernel;
261 int n_increased_diff;
264 bool report_increased_diff;
266 bool CheckStoppingCondition(math_t diff)
268 if (diff > diff_prev * 1.5 && n_outer_iter > 0) {
277 if (report_increased_diff && n_outer_iter > 100 && n_increased_diff > n_outer_iter * 0.1) {
279 "Solver is not converging monotonically. This might be caused by "
280 "insufficient normalization of the feature columns. In that case "
281 "MinMaxScaler((0,1)) could help. Alternatively, for nonlinear kernels, "
282 "you can try to increase the gamma parameter. To limit execution time, "
283 "you can also adjust the number of iterations using the max_iter "
285 report_increased_diff =
false;
287 bool keep_going =
true;
288 if (abs(diff - diff_prev) < 0.001 * tol) {
294 if (n_small_diff > nochange_steps) {
296 "SMO error: Stopping due to unchanged diff over %d"
297 " consecutive steps",
301 if (diff < tol) keep_going =
false;
304 if (std::is_same<float, math_t>::value) {
306 " This might be caused by floating point overflow. In such case using"
307 " fp64 could help. Alternatively, try gamma='scale' kernel"
310 THROW(
"SMO error: NaN found during fitting.%s", txt.c_str());
316 int GetDefaultMaxIter(
int n_train,
int max_outer_iter)
318 if (max_outer_iter == -1) {
322 max_outer_iter =
max(100000, max_outer_iter);
325 return max_outer_iter;
328 void ResizeBuffers(
int n_train,
int n_cols)
331 alpha.resize(n_train, stream);
332 C_vec.resize(n_train, stream);
333 f.resize(n_train, stream);
334 delta_alpha.resize(n_ws, stream);
335 if (svmType ==
EPSILON_SVR) y_label.resize(n_train, stream);
338 void ReleaseBuffers()
341 delta_alpha.release();
Solve the quadratic optimization problem using two level decomposition and Sequential Minimal Optimiz...
Definition: smosolver.h:59
int GetNIter()
Definition: smosolver.h:220
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 InitPenalty(math_t *C_vec, const math_t *sample_weight, int n_rows)
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_iter=-1, int max_outer_iter=-1, int max_inner_iter=10000)
Solve the quadratic optimization problem.
SmoSolver(const raft::handle_t &handle, SvmParameter param, cuvs::distance::kernels::KernelType kernel_type, cuvs::distance::kernels::GramMatrixBase< math_t > *kernel)
Definition: smosolver.h:61
SvmType
Definition: svm_parameter.h:12
@ EPSILON_SVR
Definition: svm_parameter.h:12
math_t max(math_t a, math_t b)
Definition: learning_rate.h:16
KernelType
Definition: kernel_params.hpp:16
Definition: dbscan.hpp:18
rapids_logger::logger & default_logger()
Get the default logger.
Definition: logger.hpp:43
Definition: svm_model.h:12
Definition: svm_parameter.h:27
rapids_logger::level_enum verbosity
Print information about training.
Definition: svm_parameter.h:34