GenSVM
test_gensvm_task.c
Go to the documentation of this file.
1 
27 #include "minunit.h"
28 #include "gensvm_task.h"
29 
31 {
32  struct GenTask *task = gensvm_init_task();
33  gensvm_free_task(task);
34  return NULL;
35 }
36 
38 {
39  struct GenTask *task = gensvm_init_task();
40  struct GenModel *model = gensvm_init_model();
41 
42  // start test code //
43  task->weight_idx = 2;
44  task->p = 1.3;
45  task->kappa = 0.1;
46  task->lambda = 1.4;
47  task->epsilon = 5e-3;
48  task->kerneltype = K_LINEAR;
49  task->max_iter = 100;
50 
51  gensvm_task_to_model(task, model);
52 
53  mu_assert(model->weight_idx = 2, "Incorrect model weight_idx");
54  mu_assert(model->p == 1.3, "Incorrect model p");
55  mu_assert(model->kappa == 0.1, "Incorrect model kappa");
56  mu_assert(model->lambda == 1.4, "Incorrect model lambda");
57  mu_assert(model->epsilon == 5e-3, "Incorrect model epsilon");
58  mu_assert(model->kerneltype == K_LINEAR, "Incorrect model kerneltype");
59  mu_assert(model->max_iter == 100, "Incorrect model max_iter");
60  // end test code //
61 
62  gensvm_free_model(model);
63  gensvm_free_task(task);
64  return NULL;
65 }
66 
68 {
69  struct GenTask *task = gensvm_init_task();
70  struct GenModel *model = gensvm_init_model();
71 
72  // start test code //
73  task->weight_idx = 2;
74  task->p = 1.3;
75  task->kappa = 0.1;
76  task->lambda = 1.4;
77  task->epsilon = 5e-3;
78  task->kerneltype = K_RBF;
79  task->gamma = 3.1;
80 
81  gensvm_task_to_model(task, model);
82 
83  mu_assert(model->weight_idx = 2, "Incorrect model weight_idx");
84  mu_assert(model->p == 1.3, "Incorrect model p");
85  mu_assert(model->kappa == 0.1, "Incorrect model kappa");
86  mu_assert(model->lambda == 1.4, "Incorrect model lambda");
87  mu_assert(model->epsilon == 5e-3, "Incorrect model epsilon");
88  mu_assert(model->kerneltype == K_RBF, "Incorrect model kerneltype");
89  mu_assert(model->gamma == 3.1, "Incorrect model gamma");
90  // end test code //
91 
92  gensvm_free_model(model);
93  gensvm_free_task(task);
94  return NULL;
95 }
96 
98 {
99  struct GenTask *task = gensvm_init_task();
100  struct GenModel *model = gensvm_init_model();
101 
102  // start test code //
103  task->weight_idx = 2;
104  task->p = 1.3;
105  task->kappa = 0.1;
106  task->lambda = 1.4;
107  task->epsilon = 5e-3;
108  task->kerneltype = K_POLY;
109  task->gamma = 3.1;
110  task->coef = 2.1;
111  task->degree = 1.1;
112 
113  gensvm_task_to_model(task, model);
114 
115  mu_assert(model->weight_idx = 2, "Incorrect model weight_idx");
116  mu_assert(model->p == 1.3, "Incorrect model p");
117  mu_assert(model->kappa == 0.1, "Incorrect model kappa");
118  mu_assert(model->lambda == 1.4, "Incorrect model lambda");
119  mu_assert(model->epsilon == 5e-3, "Incorrect model epsilon");
120  mu_assert(model->kerneltype == K_POLY, "Incorrect model kerneltype");
121  mu_assert(model->gamma == 3.1, "Incorrect model gamma");
122  mu_assert(model->coef == 2.1, "Incorrect model coef");
123  mu_assert(model->degree == 1.1, "Incorrect model degree");
124  // end test code //
125 
126  gensvm_free_model(model);
127  gensvm_free_task(task);
128  return NULL;
129 }
130 
132 {
133  struct GenTask *task = gensvm_init_task();
134  struct GenModel *model = gensvm_init_model();
135 
136  // start test code //
137  task->weight_idx = 2;
138  task->p = 1.3;
139  task->kappa = 0.1;
140  task->lambda = 1.4;
141  task->epsilon = 5e-3;
142  task->kerneltype = K_SIGMOID;
143  task->gamma = 3.1;
144  task->coef = 0.1;
145 
146  gensvm_task_to_model(task, model);
147 
148  mu_assert(model->weight_idx = 2, "Incorrect model weight_idx");
149  mu_assert(model->p == 1.3, "Incorrect model p");
150  mu_assert(model->kappa == 0.1, "Incorrect model kappa");
151  mu_assert(model->lambda == 1.4, "Incorrect model lambda");
152  mu_assert(model->epsilon == 5e-3, "Incorrect model epsilon");
153  mu_assert(model->kerneltype == K_SIGMOID, "Incorrect model kerneltype");
154  mu_assert(model->gamma == 3.1, "Incorrect model gamma");
155  mu_assert(model->coef == 0.1, "Incorrect model coef");
156  // end test code //
157 
158  gensvm_free_model(model);
159  gensvm_free_task(task);
160  return NULL;
161 }
162 
164 {
165  struct GenTask *task = gensvm_init_task();
166  struct GenTask *copy = NULL;
167  struct GenData *train = gensvm_init_data();
168  struct GenData *test = gensvm_init_data();
169 
170  // start test code //
171  task->folds = 7;
172  task->ID = 13;
173  task->weight_idx = 2;
174  task->p = 1.3;
175  task->kappa = 0.1;
176  task->lambda = 1.4;
177  task->epsilon = 5e-3;
178  task->kerneltype = K_LINEAR;
179  task->train_data = train;
180  task->test_data = test;
181  task->performance = 11.11;
182 
183  copy = gensvm_copy_task(task);
184 
185  mu_assert(copy->folds == 7, "Incorrect copy folds");
186  mu_assert(copy->ID == 13, "Incorrect copy ID");
187  mu_assert(copy->weight_idx = 2, "Incorrect copy weight_idx");
188  mu_assert(copy->p == 1.3, "Incorrect copy p");
189  mu_assert(copy->kappa == 0.1, "Incorrect copy kappa");
190  mu_assert(copy->lambda == 1.4, "Incorrect copy lambda");
191  mu_assert(copy->epsilon == 5e-3, "Incorrect copy epsilon");
192  mu_assert(copy->train_data == train, "Incorrect copy train data");
193  mu_assert(copy->test_data == test, "Incorrect copy test data");
194  mu_assert(copy->performance == 11.11, "Incorrect copy performance");
195  mu_assert(copy->kerneltype == K_LINEAR, "Incorrect copy kerneltype");
196 
197  // end test code //
198  gensvm_free_task(task);
199  gensvm_free_task(copy);
200  gensvm_free_data(train);
201  gensvm_free_data(test);
202 
203  return NULL;
204 }
205 
207 {
208  struct GenTask *task = gensvm_init_task();
209  struct GenTask *copy = NULL;
210  struct GenData *train = gensvm_init_data();
211  struct GenData *test = gensvm_init_data();
212 
213  // start test code //
214 
215  task->folds = 7;
216  task->ID = 13;
217  task->weight_idx = 2;
218  task->p = 1.3;
219  task->kappa = 0.1;
220  task->lambda = 1.4;
221  task->epsilon = 5e-3;
222  task->train_data = train;
223  task->test_data = test;
224  task->performance = 11.11;
225  task->kerneltype = K_RBF;
226  task->gamma = 3.1;
227 
228  copy = gensvm_copy_task(task);
229 
230  mu_assert(copy->folds == 7, "Incorrect copy folds");
231  mu_assert(copy->ID == 13, "Incorrect copy ID");
232  mu_assert(copy->weight_idx = 2, "Incorrect copy weight_idx");
233  mu_assert(copy->p == 1.3, "Incorrect copy p");
234  mu_assert(copy->kappa == 0.1, "Incorrect copy kappa");
235  mu_assert(copy->lambda == 1.4, "Incorrect copy lambda");
236  mu_assert(copy->epsilon == 5e-3, "Incorrect copy epsilon");
237  mu_assert(copy->train_data == train, "Incorrect copy train data");
238  mu_assert(copy->test_data == test, "Incorrect copy test data");
239  mu_assert(copy->performance == 11.11, "Incorrect copy performance");
240  mu_assert(copy->kerneltype == K_RBF, "Incorrect copy kerneltype");
241  mu_assert(copy->gamma == 3.1, "Incorrect copy gamma");
242 
243  // end test code //
244  gensvm_free_task(copy);
245  gensvm_free_task(task);
246  gensvm_free_data(train);
247  gensvm_free_data(test);
248 
249  return NULL;
250 }
251 
253 {
254  struct GenTask *task = gensvm_init_task();
255  struct GenTask *copy = NULL;
256  struct GenData *train = gensvm_init_data();
257  struct GenData *test = gensvm_init_data();
258 
259  // start test code //
260  task->folds = 7;
261  task->ID = 13;
262  task->weight_idx = 2;
263  task->p = 1.3;
264  task->kappa = 0.1;
265  task->lambda = 1.4;
266  task->epsilon = 5e-3;
267  task->train_data = train;
268  task->test_data = test;
269  task->performance = 11.11;
270  task->kerneltype = K_POLY;
271  task->gamma = 3.1;
272  task->coef = 2.1;
273  task->degree = 1.1;
274 
275  copy = gensvm_copy_task(task);
276 
277  mu_assert(copy->folds == 7, "Incorrect copy folds");
278  mu_assert(copy->ID == 13, "Incorrect copy ID");
279  mu_assert(copy->weight_idx = 2, "Incorrect copy weight_idx");
280  mu_assert(copy->p == 1.3, "Incorrect copy p");
281  mu_assert(copy->kappa == 0.1, "Incorrect copy kappa");
282  mu_assert(copy->lambda == 1.4, "Incorrect copy lambda");
283  mu_assert(copy->epsilon == 5e-3, "Incorrect copy epsilon");
284  mu_assert(copy->train_data == train, "Incorrect copy train data");
285  mu_assert(copy->test_data == test, "Incorrect copy test data");
286  mu_assert(copy->performance == 11.11, "Incorrect copy performance");
287  mu_assert(copy->kerneltype == K_POLY, "Incorrect copy kerneltype");
288  mu_assert(copy->gamma == 3.1, "Incorrect copy gamma");
289  mu_assert(copy->coef == 2.1, "Incorrect copy coef");
290  mu_assert(copy->degree == 1.1, "Incorrect copy degree");
291 
292  // end test code //
293  gensvm_free_task(task);
294  gensvm_free_task(copy);
295  gensvm_free_data(train);
296  gensvm_free_data(test);
297 
298  return NULL;
299 }
300 
302 {
303  struct GenTask *task = gensvm_init_task();
304  struct GenTask *copy = NULL;
305  struct GenData *train = gensvm_init_data();
306  struct GenData *test = gensvm_init_data();
307 
308  // start test code //
309  task->folds = 7;
310  task->ID = 13;
311  task->weight_idx = 2;
312  task->p = 1.3;
313  task->kappa = 0.1;
314  task->lambda = 1.4;
315  task->epsilon = 5e-3;
316  task->train_data = train;
317  task->test_data = test;
318  task->performance = 11.11;
319  task->kerneltype = K_SIGMOID;
320  task->gamma = 3.1;
321  task->coef = 0.1;
322 
323  copy = gensvm_copy_task(task);
324 
325  mu_assert(copy->folds == 7, "Incorrect copy folds");
326  mu_assert(copy->ID == 13, "Incorrect copy ID");
327  mu_assert(copy->weight_idx = 2, "Incorrect copy weight_idx");
328  mu_assert(copy->p == 1.3, "Incorrect copy p");
329  mu_assert(copy->kappa == 0.1, "Incorrect copy kappa");
330  mu_assert(copy->lambda == 1.4, "Incorrect copy lambda");
331  mu_assert(copy->epsilon == 5e-3, "Incorrect copy epsilon");
332  mu_assert(copy->train_data == train, "Incorrect copy train data");
333  mu_assert(copy->test_data == test, "Incorrect copy test data");
334  mu_assert(copy->performance == 11.11, "Incorrect copy performance");
335  mu_assert(copy->kerneltype == K_SIGMOID, "Incorrect copy kerneltype");
336  mu_assert(copy->gamma == 3.1, "Incorrect copy gamma");
337  mu_assert(copy->coef == 0.1, "Incorrect copy coef");
338 
339  // end test code //
340  gensvm_free_task(task);
341  gensvm_free_task(copy);
342  gensvm_free_data(train);
343  gensvm_free_data(test);
344  return NULL;
345 }
346 
347 char *all_tests()
348 {
349  mu_suite_start();
359 
360  return NULL;
361 }
362 
Minimal unit testing framework for C.
long folds
number of folds in cross validation
Definition: gensvm_task.h:60
double coef
coef parameter for the GenModel
Definition: gensvm_task.h:74
char * test_task_to_model_sigmoid()
double epsilon
stopping criterion for the IM algorithm.
Definition: gensvm_base.h:101
RUN_TESTS(all_tests)
char * test_task_to_model_poly()
long ID
numeric id of the task in the queue
Definition: gensvm_task.h:62
double p
parameter for the L-p norm in the loss function
Definition: gensvm_base.h:103
#define mu_assert(test, message)
Definition: minunit.h:29
char * test_copy_task_poly()
struct GenTask * gensvm_init_task(void)
Initialize a GenTask structure.
Definition: gensvm_task.c:38
void gensvm_free_model(struct GenModel *model)
Free allocated GenModel struct.
Definition: gensvm_base.c:211
char * test_copy_task_sigmoid()
double performance
performance after cross validation
Definition: gensvm_task.h:84
int weight_idx
which weights to use (1 = unit, 2 = group)
Definition: gensvm_base.h:93
#define mu_run_test(test)
Definition: minunit.h:35
struct GenModel * gensvm_init_model(void)
Initialize a GenModel structure.
Definition: gensvm_base.c:102
double gamma
gamma parameter for the GenModel
Definition: gensvm_task.h:72
char * test_copy_task_linear()
KernelType kerneltype
kerneltype parameter for the GenModel
Definition: gensvm_task.h:56
A structure to represent the data.
Definition: gensvm_base.h:57
struct GenData * test_data
pointer to the test data (if any)
Definition: gensvm_task.h:82
A structure to represent a single GenSVM model.
Definition: gensvm_base.h:92
long max_iter
maximum number of iterations of the algorithm
Definition: gensvm_base.h:141
double degree
degree parameter for the GenModel
Definition: gensvm_task.h:76
double lambda
lambda parameter for the GenModel
Definition: gensvm_task.h:68
void gensvm_free_data(struct GenData *data)
Free allocated GenData struct.
Definition: gensvm_base.c:73
A structure for a single task in the queue.
Definition: gensvm_task.h:55
char * test_copy_task_rbf()
char * test_task_to_model_linear()
char * all_tests()
void gensvm_free_task(struct GenTask *t)
Free the GenTask struct.
Definition: gensvm_task.c:71
double kappa
parameter for the Huber hinge function
Definition: gensvm_base.h:105
char * test_task_to_model_rbf()
long max_iter
maximum number of iterations of the algorithm
Definition: gensvm_task.h:78
double degree
kernel parameter for poly
Definition: gensvm_base.h:113
double kappa
kappa parameter for the GenModel
Definition: gensvm_task.h:66
struct GenTask * gensvm_copy_task(struct GenTask *t)
Deepcopy a GenTask struct.
Definition: gensvm_task.c:88
double coef
kernel parameter for poly and sigmoid
Definition: gensvm_base.h:111
KernelType kerneltype
type of kernel used in the model
Definition: gensvm_base.h:136
Header file for gensvm_task.c.
double gamma
kernel parameter for RBF, poly, and sigmoid
Definition: gensvm_base.h:109
struct GenData * gensvm_init_data(void)
Initialize a GenData structure.
Definition: gensvm_base.c:45
double epsilon
epsilon parameter for the GenModel
Definition: gensvm_task.h:70
#define mu_suite_start()
Definition: minunit.h:24
double p
p parameter for the GenModel
Definition: gensvm_task.h:64
double lambda
regularization parameter in the loss function
Definition: gensvm_base.h:107
char * test_init_free_task()
struct GenData * train_data
pointer to the training data
Definition: gensvm_task.h:80
void gensvm_task_to_model(struct GenTask *task, struct GenModel *model)
Copy parameters from GenTask to GenModel.
Definition: gensvm_task.c:122
int weight_idx
weight_idx parameter for the GenModel
Definition: gensvm_task.h:58