68 N *= grid->
Ng > 0 ? grid->
Ng : 1;
69 N *= grid->
Nc > 0 ? grid->
Nc : 1;
70 N *= grid->
Nd > 0 ? grid->
Nd : 1;
83 queue->
tasks[i] = task;
93 for (j=0; j<grid->
Np; j++) {
94 for (k=0; k<cnt; k++) {
104 for (j=0; j<grid->
Nl; j++) {
105 for (k=0; k<cnt; k++) {
116 for (j=0; j<grid->
Nk; j++) {
117 for (k=0; k<cnt; k++) {
127 for (j=0; j<grid->
Nw; j++) {
128 for (k=0; k<cnt; k++) {
139 for (j=0; j<grid->
Ne; j++) {
140 for (k=0; k<cnt; k++) {
149 while (i < N && grid->Ng > 0) {
150 for (j=0; j<grid->
Ng; j++) {
151 for (k=0; k<cnt; k++) {
158 cnt *= grid->
Ng > 0 ? grid->
Ng : 1;
160 while (i < N && grid->Nc > 0) {
161 for (j=0; j<grid->
Nc; j++) {
162 for (k=0; k<cnt; k++) {
169 cnt *= grid->
Nc > 0 ? grid->
Nc : 1;
171 while (i < N && grid->Nd > 0) {
172 for (j=0; j<grid->
Nd; j++) {
173 for (k=0; k<cnt; k++) {
244 note(
"Computing kernel ... ");
245 for (f=0; f<
folds; f++) {
246 if (train_folds[f]->Z != train_folds[f]->RAW)
247 free(train_folds[f]->Z);
248 if (test_folds[f]->Z != test_folds[f]->RAW)
249 free(test_folds[f]->Z);
277 double perf, duration, current_max = 0;
279 struct GenTask *prevtask = NULL;
281 struct timespec main_s, main_e, loop_s, loop_e;
296 for (f=0; f<folds; f++) {
300 test_folds[f], cv_idx, f);
316 current_max =
maximum(current_max, perf);
328 note(
"\nTotal elapsed training time: %8.8f seconds\n",
332 for (f=0; f<folds; f++) {
358 double duration,
double current_max)
361 sprintf(buffer,
"(%03li/%03li)\t", task->
ID+1, N);
363 sprintf(buffer + strlen(buffer),
"d = %2.2f\t", task->
degree);
365 sprintf(buffer + strlen(buffer),
"c = %2.2f\t", task->
coef);
368 sprintf(buffer + strlen(buffer),
"g = %3.3f\t", task->
gamma);
369 sprintf(buffer + strlen(buffer),
"eps = %g\tw = %i\tk = %2.2f\t" 370 "l = %f\tp = %2.2f\t", task->
epsilon,
373 note(
"\t%3.3f%% (%3.3fs)\t(best = %3.3f%%)\n", perf, duration,
#define Calloc(type, size)
long folds
number of folds in cross validation
Structure for describing the entire grid search.
double * epsilons
array of epsilon values
double coef
coef parameter for the GenModel
double gensvm_elapsed_time(struct timespec *start, struct timespec *stop)
Calculate the time between two time recordings.
long ID
numeric id of the task in the queue
double gensvm_cross_validation(struct GenModel *model, struct GenData **train_folds, struct GenData **test_folds, long folds, long n_total)
Run cross validation with a given set of train/test folds.
#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
long Nk
size of the array of kappa values
long Nw
size of the array of weight_idx values
struct GenTask * get_next_task(struct GenQueue *q)
Get new GenTask from GenQueue.
KernelType kerneltype
type of kernel to use throughout training
struct GenTask * gensvm_init_task(void)
Initialize a GenTask structure.
void gensvm_free_model(struct GenModel *model)
Free allocated GenModel struct.
bool gensvm_kernel_changed(struct GenTask *newtask, struct GenTask *oldtask)
Check if the kernel parameters change between tasks.
long i
index used for keeping track of the queue
double performance
performance after cross validation
#define Malloc(type, size)
struct GenModel * gensvm_init_model(void)
Initialize a GenModel structure.
double gamma
gamma parameter for the GenModel
double * lambdas
array of lambda values
KernelType kerneltype
kerneltype parameter for the GenModel
A structure to represent the data.
struct GenData * test_data
pointer to the test data (if any)
A structure to represent a single GenSVM model.
void gensvm_get_tt_split(struct GenData *full_data, struct GenData *train_data, struct GenData *test_data, long *cv_idx, long fold_idx)
Wrapper around sparse/dense versions of this function.
void gensvm_gridsearch_progress(struct GenTask *task, long N, double perf, double duration, double current_max)
Print the description of the current task on screen.
long n
number of instances in the dataset
void gensvm_make_cv_split(long N, long folds, long *cv_idx)
Create a cross validation split vector.
Header file for gensvm_gridsearch.c.
double degree
degree parameter for the GenModel
long Nl
size of the array of lambda values
double * kappas
array of kappa values
long Ng
size of the array of gamma values
double lambda
lambda parameter for the GenModel
void gensvm_free_data(struct GenData *data)
Free allocated GenData struct.
A structure for a single task in the queue.
void gensvm_allocate_model(struct GenModel *model)
Allocate memory for a GenModel.
FILE * GENSVM_OUTPUT_FILE
void gensvm_train_queue(struct GenQueue *q)
Run the grid search for a GenQueue.
void gensvm_init_V(struct GenModel *from_model, struct GenModel *to_model, struct GenData *data)
Seed the matrix V from an existing model or using rand.
long K
number of classes in the dataset
struct GenTask ** tasks
array of pointers to Task structs
int * weight_idxs
array of weight_idxs
void gensvm_kernel_folds(long folds, struct GenModel *model, struct GenData **train_folds, struct GenData **test_folds)
Compute the kernels for the folds of the train and test datasets.
long folds
number of folds in cross validation
long m
number of predictors (width of RAW)
double kappa
kappa parameter for the GenModel
double * gammas
array of gamma values
KernelType kerneltype
type of kernel used in the model
double * coefs
array of coef values
long Nd
size of the array of degree values
void gensvm_kernel_postprocess(struct GenModel *model, struct GenData *traindata, struct GenData *testdata)
Compute the kernel postprocessing factor.
long n
number of instances
struct GenData * gensvm_init_data(void)
Initialize a GenData structure.
double epsilon
epsilon parameter for the GenModel
long m
number of predictor variables in the dataset
void gensvm_kernel_preprocess(struct GenModel *model, struct GenData *data)
Do the preprocessing steps needed to perform kernel GenSVM.
double * ps
array of p values
double p
p parameter for the GenModel
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.
void note(const char *fmt,...)
Parse a formatted string and write to the output stream.
struct GenData * train_data
pointer to the training data
void gensvm_task_to_model(struct GenTask *task, struct GenModel *model)
Copy parameters from GenTask to GenModel.
#define Timer(spec)
Timer macro for easily recording time.
int weight_idx
weight_idx parameter for the GenModel