72 printf(
"Copyright (C) 2016, G.J.J. van den Burg.\n");
73 printf(
"This program is free software, see the LICENSE file " 75 printf(
"Usage: %s [options] grid_file\n", argv[0]);
77 printf(
"-h | -help : print this help.\n");
78 printf(
"-q : quiet mode (no output, not even errors!)\n");
79 printf(
"-x : data files are in LibSVM/SVMlight format\n");
102 int main(
int argc,
char **argv)
104 bool libsvm_format =
false;
118 note(
"Reading grid file\n");
130 err(
"[GenSVM Error]: Class labels should start from 1 and " 131 "have no gaps. Please reformat your data.\n");
137 err(
"[GenSVM Warning]: Sparse matrices with nonlinear kernels " 138 "are not yet supported. Dense matrices will " 141 train_data->
Z = train_data->
RAW;
146 err(
"[GenSVM Warning]: Using test datasets in a grid search " 147 "is not yet supported in GenSVM.\n" 148 " The test dataset will be " 149 "ignored during training.\n");
154 note(
"Creating queue\n");
159 note(
"Starting training\n");
161 note(
"Training finished\n");
198 for (i=1; i<argc; i++) {
199 if (argv[i][0] !=
'-')
break;
202 switch (argv[i-1][1]) {
212 fprintf(stderr,
"Unknown option: -%c\n",
221 strcpy(input_filename, argv[i]);
247 fprintf(stderr,
"Unknown kernel specified on line: %s\n",
278 fid = fopen(input_filename,
"r");
280 fprintf(stderr,
"Error opening grid file %s\n",
289 sscanf(buffer,
"train: %s\n", train_filename);
294 sscanf(buffer,
"test: %s\n", test_filename);
303 grid->
ps[i] = params[i];
315 grid->
kappas[i] = params[i];
331 grid->
folds = lparams[0];
333 fprintf(stderr,
"Field \"folds\" only takes " 334 "one value. Additional " 335 "fields are ignored.\n");
340 fprintf(stderr,
"Field \"repeats\" only " 341 "takes one value. Additional " 342 "fields are ignored.\n");
347 fprintf(stderr,
"Field \"percentile\" only " 348 "takes one value. Additional " 349 "fields are ignored.\n");
355 fprintf(stderr,
"Field \"gamma\" ignored, " 356 "linear kernel is used.\n");
362 grid->
gammas[i] = params[i];
368 fprintf(stderr,
"Field \"coef\" ignored with " 369 "specified kernel.\n");
375 grid->
coefs[i] = params[i];
380 fprintf(stderr,
"Field \"degree\" ignored " 381 "with specified kernel.\n");
390 fprintf(stderr,
"Cannot find any parameters on line: " #define Calloc(type, size)
Structure for describing the entire grid search.
double * epsilons
array of epsilon values
void read_grid_from_file(char *input_filename, struct GenGrid *grid)
Read the GenGrid struct from file.
struct GenQueue * gensvm_init_queue(void)
Initialize a GenQueue structure.
void err(const char *fmt,...)
Parse a formatted string and write it to standard error.
void gensvm_read_data(struct GenData *dataset, char *data_file)
Read data from file.
#define GENSVM_MAX_LINE_LENGTH
long Np
size of the array of p values
long Ne
size of the array of epsilon values
long Nc
size of the array of coef values
double * degrees
array of degree values
int gensvm_check_argv_eq(int argc, char **argv, char *str)
Check if a command line argument equals a string.
long Nk
size of the array of kappa values
long Nw
size of the array of weight_idx values
#define Memset(var, type, size)
void gensvm_free_sparse(struct GenSparse *sp)
Free an allocated GenSparse structure.
KernelType kerneltype
type of kernel to use throughout training
long i
index used for keeping track of the queue
void gensvm_fill_queue(struct GenGrid *grid, struct GenQueue *queue, struct GenData *train_data, struct GenData *test_data)
Initialize a GenQueue from a Training instance.
bool gensvm_check_outcome_contiguous(struct GenData *data)
Check if the labels are contiguous on [1 .. K].
void parse_command_line(int argc, char **argv, char *input_filename)
Parse command line arguments.
Header file for gensvm_checks.c.
long all_longs_str(char *buffer, long offset, long *all_longs)
Read all longs in a given buffer.
double * lambdas
array of lambda values
A structure to represent the data.
void gensvm_train_queue(struct GenQueue *q)
Run the grid search for a GenQueue.
bool str_endswith(const char *str, const char *suf)
Check if a string ends with a suffix.
void gensvm_consistency_repeats(struct GenQueue *q, long repeats, double percentile)
Run repeats of the GenTask structs in GenQueue to find the best configuration.
char * test_data_file
filename of test data file
Header file for gensvm_cmdarg.c.
void exit_with_help(char **argv)
Help function.
double percentile
percentile to use for the consistency repeats
Header file for gensvm_gridsearch.c.
long all_doubles_str(char *buffer, long offset, double *all_doubles)
Read all doubles in a given buffer.
bool str_startswith(const char *str, const char *pre)
Check if a string starts with a prefix.
long Nl
size of the array of lambda values
double * kappas
array of kappa values
long Ng
size of the array of gamma values
void gensvm_free_data(struct GenData *data)
Free allocated GenData struct.
void gensvm_free_queue(struct GenQueue *q)
Free the GenQueue struct.
Header file for gensvm_consistency.c.
Header file for gensvm_io.c.
double * gensvm_sparse_to_dense(struct GenSparse *A)
Convert a GenSparse structure to a dense matrix.
int * weight_idxs
array of weight_idxs
long folds
number of folds in cross validation
int gensvm_check_argv(int argc, char **argv, char *str)
Check if any command line arguments contain string.
char * train_data_file
filename of train data file
KernelType
type of kernel used in training
double * gammas
array of gamma values
int main(int argc, char **argv)
Main interface function for GenSVMgrid.
double * coefs
array of coef values
TrainType traintype
type of training to use
long Nd
size of the array of degree values
FILE * GENSVM_OUTPUT_FILE
struct GenData * gensvm_init_data(void)
Initialize a GenData structure.
KernelType parse_kernel_str(char *kernel_line)
Parse the kernel string from the training file.
void gensvm_read_data_libsvm(struct GenData *dataset, char *data_file)
Read data from a file in LibSVM/SVMlight format.
double * RAW
augmented raw data matrix
struct GenSparse * spZ
sparse representation of the augmented data matrix
double * ps
array of p values
void gensvm_free_grid(struct GenGrid *grid)
Free a GenGrid structure.
void note(const char *fmt,...)
Parse a formatted string and write to the output stream.
struct GenGrid * gensvm_init_grid(void)
Initialize a GenGrid structure.