From: Chih-Jen Lin Date: Tue, 20 Oct 2020 23:43:05 +0000 (+0800) Subject: - add max Newton iter warning in newton.cpp X-Git-Tag: v242~5 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=7b0193baec9a443684e4a079ae4a2040971f67cf;p=liblinear - add max Newton iter warning in newton.cpp - in code comments replace tabs with spaces --- diff --git a/linear.h b/linear.h index bfd5e1c..c27c23a 100644 --- a/linear.h +++ b/linear.h @@ -30,7 +30,7 @@ struct parameter int solver_type; /* these are for training only */ - double eps; /* stopping criteria */ + double eps; /* stopping tolerance */ double C; int nr_weight; int *weight_label; @@ -44,12 +44,12 @@ struct parameter struct model { struct parameter param; - int nr_class; /* number of classes */ + int nr_class; /* number of classes */ int nr_feature; double *w; - int *label; /* label of each class */ + int *label; /* label of each class */ double bias; - double rho; /* one-class SVM only */ + double rho; /* one-class SVM only */ }; struct model* train(const struct problem *prob, const struct parameter *param); diff --git a/newton.cpp b/newton.cpp index 17ba7de..bb2c3b1 100644 --- a/newton.cpp +++ b/newton.cpp @@ -162,6 +162,9 @@ void NEWTON::newton(double *w) iter++; } + if(iter >= max_iter) + info("\nWARNING: reaching max number of Newton iterations\n"); + delete[] g; delete[] r; delete[] s; diff --git a/predict.c b/predict.c index 8f415d2..85ed067 100644 --- a/predict.c +++ b/predict.c @@ -97,7 +97,7 @@ void do_predict(FILE *input, FILE *output) while(1) { - if(i>=max_nr_attr-2) // need one more for index = -1 + if(i>=max_nr_attr-2) // need one more for index = -1 { max_nr_attr *= 2; x = (struct feature_node *) realloc(x,max_nr_attr*sizeof(struct feature_node)); diff --git a/train.c b/train.c index ef8fe70..7923a8d 100644 --- a/train.c +++ b/train.c @@ -17,41 +17,41 @@ void exit_with_help() "options:\n" "-s type : set type of solver (default 1)\n" " for multi-class classification\n" - " 0 -- L2-regularized logistic regression (primal)\n" - " 1 -- L2-regularized L2-loss support vector classification (dual)\n" - " 2 -- L2-regularized L2-loss support vector classification (primal)\n" - " 3 -- L2-regularized L1-loss support vector classification (dual)\n" - " 4 -- support vector classification by Crammer and Singer\n" - " 5 -- L1-regularized L2-loss support vector classification\n" - " 6 -- L1-regularized logistic regression\n" - " 7 -- L2-regularized logistic regression (dual)\n" + " 0 -- L2-regularized logistic regression (primal)\n" + " 1 -- L2-regularized L2-loss support vector classification (dual)\n" + " 2 -- L2-regularized L2-loss support vector classification (primal)\n" + " 3 -- L2-regularized L1-loss support vector classification (dual)\n" + " 4 -- support vector classification by Crammer and Singer\n" + " 5 -- L1-regularized L2-loss support vector classification\n" + " 6 -- L1-regularized logistic regression\n" + " 7 -- L2-regularized logistic regression (dual)\n" " for regression\n" - " 11 -- L2-regularized L2-loss support vector regression (primal)\n" - " 12 -- L2-regularized L2-loss support vector regression (dual)\n" - " 13 -- L2-regularized L1-loss support vector regression (dual)\n" + " 11 -- L2-regularized L2-loss support vector regression (primal)\n" + " 12 -- L2-regularized L2-loss support vector regression (dual)\n" + " 13 -- L2-regularized L1-loss support vector regression (dual)\n" " for outlier detection\n" - " 21 -- one-class support vector machine (dual)\n" + " 21 -- one-class support vector machine (dual)\n" "-c cost : set the parameter C (default 1)\n" "-p epsilon : set the epsilon in loss function of SVR (default 0.1)\n" "-n nu : set the parameter nu of one-class SVM (default 0.5)\n" "-e epsilon : set tolerance of termination criterion\n" - " -s 0 and 2\n" - " |f'(w)|_2 <= eps*min(pos,neg)/l*|f'(w0)|_2,\n" - " where f is the primal function and pos/neg are # of\n" - " positive/negative data (default 0.01)\n" - " -s 11\n" - " |f'(w)|_2 <= eps*|f'(w0)|_2 (default 0.0001)\n" - " -s 1, 3, 4, 7, and 21\n" - " Dual maximal violation <= eps; similar to libsvm (default 0.1 except 0.01 for -s 21)\n" - " -s 5 and 6\n" - " |f'(w)|_1 <= eps*min(pos,neg)/l*|f'(w0)|_1,\n" - " where f is the primal function (default 0.01)\n" - " -s 12 and 13\n" - " |f'(alpha)|_1 <= eps |f'(alpha0)|,\n" - " where f is the dual function (default 0.1)\n" + " -s 0 and 2\n" + " |f'(w)|_2 <= eps*min(pos,neg)/l*|f'(w0)|_2,\n" + " where f is the primal function and pos/neg are # of\n" + " positive/negative data (default 0.01)\n" + " -s 11\n" + " |f'(w)|_2 <= eps*|f'(w0)|_2 (default 0.0001)\n" + " -s 1, 3, 4, 7, and 21\n" + " Dual maximal violation <= eps; similar to libsvm (default 0.1 except 0.01 for -s 21)\n" + " -s 5 and 6\n" + " |f'(w)|_1 <= eps*min(pos,neg)/l*|f'(w0)|_1,\n" + " where f is the primal function (default 0.01)\n" + " -s 12 and 13\n" + " |f'(alpha)|_1 <= eps |f'(alpha0)|,\n" + " where f is the dual function (default 0.1)\n" "-B bias : if bias >= 0, instance x becomes [x; bias]; if < 0, no bias term added (default -1)\n" "-R : not regularize the bias; must with -B 1 to have the bias; DON'T use this unless you know what it is\n" - " (for -s 0, 2, 5, 6, 11)\n" + " (for -s 0, 2, 5, 6, 11)\n" "-wi weight: weights adjust the parameter C of different classes (see README for details)\n" "-v n: n-fold cross validation mode\n" "-C : find parameters (C for -s 0, 2 and C, p for -s 11)\n" @@ -211,7 +211,7 @@ void do_cross_validation() void parse_command_line(int argc, char **argv, char *input_file_name, char *model_file_name) { int i; - void (*print_func)(const char*) = NULL; // default printing to stdout + void (*print_func)(const char*) = NULL; // default printing to stdout // default values param.solver_type = L2R_L2LOSS_SVC_DUAL;