Skip to content

Commit

Permalink
Print debug message if SVM convergence is poor (#3562)
Browse files Browse the repository at this point in the history
closes #947 

If the input data for SVM is not normalized correctly, then convergence can be very slow. The solver can even fail to converge. This PR detects such cases and prints a debug message with suggestions how to fix this problem. 

Such problems were reported in #947, #1664, #2857, #3233. The threshold for reporting is set so that the message is printed in those cases. I have tested several properly normalized cases to confirm that the message is not shown. Still, the threshold for printing the message does not have a proper theoretical justification, and false positives might occur. Therefore only a debug message is shown instead of a warning.

Authors:
  - Tamas Bela Feher (@tfeher)

Approvers:
  - Dante Gama Dessavre (@dantegd)

URL: #3562
  • Loading branch information
tfeher authored Mar 2, 2021
1 parent 4c9282b commit 6dddae4
Showing 1 changed file with 26 additions and 2 deletions.
28 changes: 26 additions & 2 deletions cpp/src/svm/smosolver.cuh
Original file line number Diff line number Diff line change
Expand Up @@ -127,10 +127,12 @@ class SmoSolver {
cache_size, svmType);
// Init counters
max_outer_iter = GetDefaultMaxIter(n_train, max_outer_iter);
int n_iter = 0;
n_iter = 0;
int n_inner_iter = 0;
diff_prev = 0;
n_small_diff = 0;
n_increased_diff = 0;
report_increased_diff = true;
bool keep_going = true;

while (n_iter < max_outer_iter && keep_going) {
Expand Down Expand Up @@ -376,9 +378,31 @@ class SmoSolver {
math_t diff_prev;
int n_small_diff;
int nochange_steps;
int n_increased_diff;
int n_iter;
bool report_increased_diff;

bool CheckStoppingCondition(math_t diff) {
// TODO improve stopping condition to detect oscillations, see Issue #947
if (diff > diff_prev * 1.5 && n_iter > 0) {
// Ideally, diff should decrease monotonically. In practice we can have
// small fluctuations (10% increase is not uncommon). Here we consider a
// 50% increase in the diff value large enough to indicate a problem.
// The 50% value is an educated guess that triggers the convergence debug
// message for problematic use cases while avoids false alarms in many
// other cases.
n_increased_diff++;
}
if (report_increased_diff && n_iter > 100 &&
n_increased_diff > n_iter * 0.1) {
CUML_LOG_DEBUG(
"Solver is not converging monotonically. This might be caused by "
"insufficient normalization of the feature columns. In that case "
"MinMaxScaler((0,1)) could help. Alternatively, for nonlinear kernels, "
"you can try to increase the gamma parameter. To limit execution time, "
"you can also adjust the number of iterations using the max_iter "
"parameter.");
report_increased_diff = false;
}
bool keep_going = true;
if (abs(diff - diff_prev) < 0.001 * tol) {
n_small_diff++;
Expand Down

0 comments on commit 6dddae4

Please sign in to comment.