GenSVM
test_gensvm_copy.c
Go to the documentation of this file.
1 
27 #include "minunit.h"
28 #include "gensvm_copy.h"
29 
31 {
32  struct GenModel *from_model = gensvm_init_model();
33  struct GenModel *to_model = gensvm_init_model();
34 
35  from_model->p = 2.0;
36  from_model->lambda = 1.0;
37  from_model->epsilon = 1e-8;
38  from_model->kappa = 1.0;
39  from_model->weight_idx = 2;
40  from_model->kerneltype = K_LINEAR;
41  from_model->max_iter = 100;
42 
43  gensvm_copy_model(from_model, to_model);
44 
45  mu_assert(to_model->p == 2.0, "to_model->p incorrect.");
46  mu_assert(to_model->lambda == 1.0, "to_model->lambda incorrect.");
47  mu_assert(to_model->epsilon == 1e-8, "to_model->epsilon incorrect.");
48  mu_assert(to_model->kappa == 1.0, "to_model->kappa incorrect.");
49  mu_assert(to_model->weight_idx == 2,
50  "to_model->weight_idx incorrect.");
51  mu_assert(to_model->kerneltype == K_LINEAR, "to->kerneltype incorrect");
52  mu_assert(to_model->max_iter == 100, "to->max_iter incorrect");
53 
54  gensvm_free_model(from_model);
55  gensvm_free_model(to_model);
56 
57  return NULL;
58 }
59 
61 {
62  struct GenModel *from_model = gensvm_init_model();
63  struct GenModel *to_model = gensvm_init_model();
64 
65  from_model->p = 2.0;
66  from_model->lambda = 1.0;
67  from_model->epsilon = 1e-8;
68  from_model->kappa = 1.0;
69  from_model->weight_idx = 2;
70  from_model->kerneltype = K_POLY;
71  from_model->gamma = 1.0;
72  from_model->coef = 2.0;
73  from_model->degree = 3.0;
74 
75  gensvm_copy_model(from_model, to_model);
76 
77  mu_assert(to_model->p == 2.0, "to->p incorrect.");
78  mu_assert(to_model->lambda == 1.0, "to->lambda incorrect.");
79  mu_assert(to_model->epsilon == 1e-8, "to->epsilon incorrect.");
80  mu_assert(to_model->kappa == 1.0, "to->kappa incorrect.");
81  mu_assert(to_model->weight_idx == 2, "to->weight_idx incorrect.");
82  mu_assert(to_model->kerneltype == K_POLY, "to->kerneltype incorrect");
83  mu_assert(to_model->gamma == 1.0, "to->gamma is incorrect.");
84  mu_assert(to_model->coef == 2.0, "to->coef is incorrect.");
85  mu_assert(to_model->degree == 3.0, "to->degree is incorrect.");
86 
87  gensvm_free_model(from_model);
88  gensvm_free_model(to_model);
89 
90  return NULL;
91 }
92 
94 {
95  struct GenModel *from_model = gensvm_init_model();
96  struct GenModel *to_model = gensvm_init_model();
97 
98  from_model->p = 2.0;
99  from_model->lambda = 1.0;
100  from_model->epsilon = 1e-8;
101  from_model->kappa = 1.0;
102  from_model->weight_idx = 2;
103  from_model->kerneltype = K_POLY;
104  from_model->gamma = 1.0;
105  from_model->coef = 2.0;
106  from_model->degree = 3.0;
107 
108  gensvm_copy_model(from_model, to_model);
109 
110  mu_assert(to_model->p == 2.0, "to_model->p incorrect.");
111  mu_assert(to_model->lambda == 1.0, "to_model->lambda incorrect.");
112  mu_assert(to_model->epsilon == 1e-8, "to_model->epsilon incorrect.");
113  mu_assert(to_model->kappa == 1.0, "to_model->kappa incorrect.");
114  mu_assert(to_model->weight_idx == 2,
115  "to_model->weight_idx incorrect.");
116  mu_assert(to_model->kerneltype == K_POLY, "to->kerneltype incorrect");
117  mu_assert(to_model->gamma == 1.0, "to->gamma is incorrect.");
118  mu_assert(to_model->coef == 2.0, "to->coef is incorrect.");
119  mu_assert(to_model->degree == 3.0, "to->degree is incorrect.");
120 
121  gensvm_free_model(from_model);
122  gensvm_free_model(to_model);
123 
124  return NULL;
125 }
126 
128 {
129  struct GenModel *from_model = gensvm_init_model();
130  struct GenModel *to_model = gensvm_init_model();
131 
132  from_model->p = 2.0;
133  from_model->lambda = 1.0;
134  from_model->epsilon = 1e-8;
135  from_model->kappa = 1.0;
136  from_model->weight_idx = 2;
137  from_model->kerneltype = K_RBF;
138  from_model->gamma = 5.0;
139 
140  gensvm_copy_model(from_model, to_model);
141 
142  mu_assert(to_model->p == 2.0, "to_model->p incorrect.");
143  mu_assert(to_model->lambda == 1.0, "to_model->lambda incorrect.");
144  mu_assert(to_model->epsilon == 1e-8, "to_model->epsilon incorrect.");
145  mu_assert(to_model->kappa == 1.0, "to_model->kappa incorrect.");
146  mu_assert(to_model->weight_idx == 2,
147  "to_model->weight_idx incorrect.");
148  mu_assert(to_model->kerneltype == K_RBF, "to->kerneltype incorrect");
149  mu_assert(to_model->gamma == 5.0, "to->gamma is incorrect.");
150 
151  gensvm_free_model(from_model);
152  gensvm_free_model(to_model);
153 
154  return NULL;
155 }
156 
158 {
159  struct GenModel *from_model = gensvm_init_model();
160  struct GenModel *to_model = gensvm_init_model();
161 
162  from_model->p = 2.0;
163  from_model->lambda = 1.0;
164  from_model->epsilon = 1e-8;
165  from_model->kappa = 1.0;
166  from_model->weight_idx = 2;
167  from_model->kerneltype = K_RBF;
168  from_model->gamma = 5.0;
169 
170  gensvm_copy_model(from_model, to_model);
171 
172  mu_assert(to_model->p == 2.0, "to_model->p incorrect.");
173  mu_assert(to_model->lambda == 1.0, "to_model->lambda incorrect.");
174  mu_assert(to_model->epsilon == 1e-8, "to_model->epsilon incorrect.");
175  mu_assert(to_model->kappa == 1.0, "to_model->kappa incorrect.");
176  mu_assert(to_model->weight_idx == 2,
177  "to_model->weight_idx incorrect.");
178  mu_assert(to_model->kerneltype == K_RBF, "to->kerneltype incorrect");
179  mu_assert(to_model->gamma == 5.0, "to->gamma is incorrect.");
180 
181  gensvm_free_model(from_model);
182  gensvm_free_model(to_model);
183 
184  return NULL;
185 }
186 
188 {
189  struct GenModel *from_model = gensvm_init_model();
190  struct GenModel *to_model = gensvm_init_model();
191 
192  from_model->p = 2.0;
193  from_model->lambda = 1.0;
194  from_model->epsilon = 1e-8;
195  from_model->kappa = 1.0;
196  from_model->weight_idx = 2;
197  from_model->kerneltype = K_SIGMOID;
198  from_model->gamma = 5.0;
199  from_model->coef = 10.0;
200 
201  gensvm_copy_model(from_model, to_model);
202 
203  mu_assert(to_model->p == 2.0, "to_model->p incorrect.");
204  mu_assert(to_model->lambda == 1.0, "to_model->lambda incorrect.");
205  mu_assert(to_model->epsilon == 1e-8, "to_model->epsilon incorrect.");
206  mu_assert(to_model->kappa == 1.0, "to_model->kappa incorrect.");
207  mu_assert(to_model->weight_idx == 2,
208  "to_model->weight_idx incorrect.");
209  mu_assert(to_model->kerneltype == K_SIGMOID,
210  "to->kerneltype incorrect");
211  mu_assert(to_model->gamma == 5.0, "to->gamma is incorrect.");
212  mu_assert(to_model->coef == 10.0, "to->coef is incorrect.");
213 
214  gensvm_free_model(from_model);
215  gensvm_free_model(to_model);
216 
217  return NULL;
218 }
219 
221 {
222  struct GenModel *from_model = gensvm_init_model();
223  struct GenModel *to_model = gensvm_init_model();
224 
225  from_model->p = 2.0;
226  from_model->lambda = 1.0;
227  from_model->epsilon = 1e-8;
228  from_model->kappa = 1.0;
229  from_model->weight_idx = 2;
230  from_model->kerneltype = K_SIGMOID;
231  from_model->gamma = 5.0;
232  from_model->coef = 10.0;
233 
234  gensvm_copy_model(from_model, to_model);
235 
236  mu_assert(to_model->p == 2.0, "to_model->p incorrect.");
237  mu_assert(to_model->lambda == 1.0, "to_model->lambda incorrect.");
238  mu_assert(to_model->epsilon == 1e-8, "to_model->epsilon incorrect.");
239  mu_assert(to_model->kappa == 1.0, "to_model->kappa incorrect.");
240  mu_assert(to_model->weight_idx == 2,
241  "to_model->weight_idx incorrect.");
242  mu_assert(to_model->kerneltype == K_SIGMOID,
243  "to->kerneltype incorrect");
244  mu_assert(to_model->gamma == 5.0, "to->gamma is incorrect.");
245  mu_assert(to_model->coef == 10.0, "to->coef is incorrect.");
246 
247  gensvm_free_model(from_model);
248  gensvm_free_model(to_model);
249 
250  return NULL;
251 }
252 
253 char *all_tests()
254 {
255  mu_suite_start();
263 
264  return NULL;
265 }
266 
Minimal unit testing framework for C.
double epsilon
stopping criterion for the IM algorithm.
Definition: gensvm_base.h:101
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_model_sigmoid_1()
void gensvm_free_model(struct GenModel *model)
Free allocated GenModel struct.
Definition: gensvm_base.c:211
int weight_idx
which weights to use (1 = unit, 2 = group)
Definition: gensvm_base.h:93
RUN_TESTS(all_tests)
char * test_copy_model_rbf_2()
#define mu_run_test(test)
Definition: minunit.h:35
struct GenModel * gensvm_init_model(void)
Initialize a GenModel structure.
Definition: gensvm_base.c:102
A structure to represent a single GenSVM model.
Definition: gensvm_base.h:92
char * all_tests()
char * test_copy_model_poly_1()
long max_iter
maximum number of iterations of the algorithm
Definition: gensvm_base.h:141
void gensvm_copy_model(struct GenModel *from, struct GenModel *to)
Copy model parameters between two GenModel structs.
Definition: gensvm_copy.c:48
double kappa
parameter for the Huber hinge function
Definition: gensvm_base.h:105
char * test_copy_model_sigmoid_2()
double degree
kernel parameter for poly
Definition: gensvm_base.h:113
double coef
kernel parameter for poly and sigmoid
Definition: gensvm_base.h:111
Header file for gensvm_copy.c.
KernelType kerneltype
type of kernel used in the model
Definition: gensvm_base.h:136
double gamma
kernel parameter for RBF, poly, and sigmoid
Definition: gensvm_base.h:109
char * test_copy_model_poly_2()
char * test_copy_model_linear()
char * test_copy_model_rbf_1()
#define mu_suite_start()
Definition: minunit.h:24
double lambda
regularization parameter in the loss function
Definition: gensvm_base.h:107