-B bias : if bias >= 0, instance x becomes [x; bias]; if < 0, no bias term added (default 1)
-wi weight: weights adjust the parameter C of different classes (see README for details)
-v n: n-fold cross validation mode
+-q : quiet mode (no outputs)
Option -v randomly splits the data into n parts and calculates cross
validation accuracy on them.
This function frees the memory used by a parameter set.
+- Variable: extern void (*liblinear_print_string) (const char *);
+
+ Users can specify their output format by
+ liblinear_print_string = &your_print_function;
+
Building Windows Binaries
=========================
#define Malloc(type,n) (type *)malloc((n)*sizeof(type))
#define INF HUGE_VAL
+static void print_string_stdout(const char *s)
+{
+ fputs(s,stdout);
+ fflush(stdout);
+}
+
+void (*liblinear_print_string) (const char *) = &print_string_stdout;
+
#if 1
static void info(const char *fmt,...)
{
+ char buf[BUFSIZ];
va_list ap;
va_start(ap,fmt);
- vprintf(fmt,ap);
+ vsprintf(buf,fmt,ap);
va_end(ap);
-}
-static void info_flush()
-{
- fflush(stdout);
+ (*liblinear_print_string)(buf);
}
#else
-static void info(char *fmt,...) {}
-static void info_flush() {}
+static void info(const char *fmt,...) {}
#endif
class l2_lr_fun : public function
iter++;
if(iter % 10 == 0)
{
- info(".");
- info_flush();
+ info(".");
}
if(stopping < eps_shrink)
active_size = l;
for(i=0;i<l;i++)
active_size_i[i] = nr_class;
- info("*"); info_flush();
+ info("*");
eps_shrink = max(eps_shrink/2, eps);
start_from_all = true;
}
iter++;
if(iter % 10 == 0)
{
- info(".");
- info_flush();
+ info(".");
}
if(PGmax_new - PGmin_new <= eps)
else
{
active_size = l;
- info("*"); info_flush();
+ info("*");
PGmax_old = INF;
PGmin_old = -INF;
continue;
{
fun_obj=new l2_lr_fun(prob, Cp, Cn);
TRON tron_obj(fun_obj, eps*min(pos,neg)/prob->l);
+ tron_obj.set_print_string(liblinear_print_string);
tron_obj.tron(w);
delete fun_obj;
break;
{
fun_obj=new l2loss_svm_fun(prob, Cp, Cn);
TRON tron_obj(fun_obj, eps*min(pos,neg)/prob->l);
+ tron_obj.set_print_string(liblinear_print_string);
tron_obj.tron(w);
delete fun_obj;
break;
void destroy_model(struct model *model_);
void destroy_param(struct parameter *param);
const char *check_parameter(const struct problem *prob, const struct parameter *param);
+extern void (*liblinear_print_string) (const char *);
#ifdef __cplusplus
}
#define Malloc(type,n) (type *)malloc((n)*sizeof(type))
#define INF HUGE_VAL
+void print_null(const char *s){}
+
+void (*liblinear_default_print_string) (const char *);
+
void exit_with_help()
{
mexPrintf(
col_format_flag = 0;
bias = 1;
+ // train loaded only once under matlab
+ if(liblinear_default_print_string == NULL)
+ liblinear_default_print_string = liblinear_print_string;
+ else
+ liblinear_print_string = liblinear_default_print_string;
+
if(nrhs <= 1)
return 1;
for(i=1;i<argc;i++)
{
if(argv[i][0] != '-') break;
- if(++i>=argc)
+ ++i;
+ if(i>=argc && argv[i-1][1] != 'q') // since option -q has no parameter
return 1;
switch(argv[i-1][1])
{
param.weight_label[param.nr_weight-1] = atoi(&argv[i-1][2]);
param.weight[param.nr_weight-1] = atof(argv[i]);
break;
+ case 'q':
+ liblinear_print_string = &print_null;
+ i--;
+ break;
default:
mexPrintf("unknown option\n");
return 1;
#define Malloc(type,n) (type *)malloc((n)*sizeof(type))
#define INF HUGE_VAL
+void print_null(const char *s) {}
+
void exit_with_help()
{
printf(
"-B bias : if bias >= 0, instance x becomes [x; bias]; if < 0, no bias term added (default 1)\n"
"-wi weight: weights adjust the parameter C of different classes (see README for details)\n"
"-v n: n-fold cross validation mode\n"
+ "-q : quiet mode (no outputs)\n"
);
exit(1);
}
}
break;
+ case 'q':
+ liblinear_print_string = &print_null;
+ i--;
+ break;
+
default:
fprintf(stderr,"unknown option: -%c\n", argv[i-1][1]);
exit_with_help();
}
#endif
+void default_print(const char *buf)
+{
+ fputs(buf,stdout);
+ fflush(stdout);
+}
+
+void TRON::info(const char *fmt,...)
+{
+ char buf[BUFSIZ];
+ va_list ap;
+ va_start(ap,fmt);
+ vsprintf(buf,fmt,ap);
+ va_end(ap);
+ (*tron_print_string)(buf);
+}
TRON::TRON(const function *fun_obj, double eps, int max_iter)
{
this->fun_obj=const_cast<function *>(fun_obj);
this->eps=eps;
this->max_iter=max_iter;
+ tron_print_string = default_print;
}
TRON::~TRON()
else
delta = max(delta, min(alpha*snorm, sigma3*delta));
- printf("iter %2d act %5.3e pre %5.3e delta %5.3e f %5.3e |g| %5.3e CG %3d\n", iter, actred, prered, delta, f, gnorm, cg_iter);
+ info("iter %2d act %5.3e pre %5.3e delta %5.3e f %5.3e |g| %5.3e CG %3d\n", iter, actred, prered, delta, f, gnorm, cg_iter);
if (actred > eta0*prered)
{
}
if (f < -1.0e+32)
{
- printf("warning: f < -1.0e+32\n");
+ info("warning: f < -1.0e+32\n");
break;
}
if (fabs(actred) <= 0 && prered <= 0)
{
- printf("warning: actred and prered <= 0\n");
+ info("warning: actred and prered <= 0\n");
break;
}
if (fabs(actred) <= 1.0e-12*fabs(f) &&
fabs(prered) <= 1.0e-12*fabs(f))
{
- printf("warning: actred and prered too small\n");
+ info("warning: actred and prered too small\n");
break;
}
}
daxpy_(&n, &alpha, d, &inc, s, &inc);
if (dnrm2_(&n, s, &inc) > delta)
{
- printf("cg reaches trust region boundary\n");
+ info("cg reaches trust region boundary\n");
alpha = -alpha;
daxpy_(&n, &alpha, d, &inc, s, &inc);
dmax = fabs(x[i]);
return(dmax);
}
+
+void TRON::set_print_string(void (*print_string) (const char *buf))
+{
+ tron_print_string = print_string;
+}
~TRON();
void tron(double *w);
+ void set_print_string(void (*i_print) (const char *buf));
private:
int trcg(double delta, double *g, double *s, double *r);
double eps;
int max_iter;
function *fun_obj;
+ void info(const char *fmt,...);
+ void (*tron_print_string)(const char *buf);
};
-
#endif