65 data->
Z =
Calloc(
double, n*(m+1));
69 matrix_set(data->
Z, m+1, 0, 1, -0.3943375672974065);
70 matrix_set(data->
Z, m+1, 0, 2, -0.1056624327025935);
72 matrix_set(data->
Z, m+1, 1, 1, -0.2886751345948129);
73 matrix_set(data->
Z, m+1, 1, 2, -0.2886751345948128);
75 matrix_set(data->
Z, m+1, 2, 1, -0.1056624327025937);
76 matrix_set(data->
Z, m+1, 2, 2, -0.3943375672974063);
79 matrix_set(data->
Z, m+1, 3, 2, -0.3943375672974064);
82 matrix_set(data->
Z, m+1, 4, 2, -0.2886751345948129);
85 matrix_set(data->
Z, m+1, 5, 2, -0.1056624327025937);
96 matrix_set(data->
Z, m+1, 9, 1, -0.1056624327025934);
98 matrix_set(data->
Z, m+1, 10, 0, 1.0000000000000000);
99 matrix_set(data->
Z, m+1, 10, 1, -0.2886751345948126);
100 matrix_set(data->
Z, m+1, 10, 2, 0.2886751345948132);
101 matrix_set(data->
Z, m+1, 11, 0, 1.0000000000000000);
102 matrix_set(data->
Z, m+1, 11, 1, -0.3943375672974064);
103 matrix_set(data->
Z, m+1, 11, 2, 0.1056624327025939);
107 matrix_set(model->
V, K-1, 0, 0, 0.0000000000000000);
108 matrix_set(model->
V, K-1, 0, 1, 0.0000000000000000);
109 matrix_set(model->
V, K-1, 1, 0, -2.4494897427831779);
110 matrix_set(model->
V, K-1, 1, 1, -0.0000000000000002);
111 matrix_set(model->
V, K-1, 2, 0, 0.0000000000000000);
112 matrix_set(model->
V, K-1, 2, 1, -2.4494897427831783);
115 long *predy =
Calloc(
long, n);
118 mu_assert(predy[0] == 2,
"Incorrect label at index 0");
119 mu_assert(predy[1] == 3,
"Incorrect label at index 1");
120 mu_assert(predy[2] == 3,
"Incorrect label at index 2");
121 mu_assert(predy[3] == 3,
"Incorrect label at index 3");
122 mu_assert(predy[4] == 3,
"Incorrect label at index 4");
123 mu_assert(predy[5] == 1,
"Incorrect label at index 5");
124 mu_assert(predy[6] == 1,
"Incorrect label at index 6");
125 mu_assert(predy[7] == 1,
"Incorrect label at index 7");
126 mu_assert(predy[8] == 1,
"Incorrect label at index 8");
127 mu_assert(predy[9] == 2,
"Incorrect label at index 9");
128 mu_assert(predy[10] == 2,
"Incorrect label at index 10");
129 mu_assert(predy[11] == 2,
"Incorrect label at index 11");
157 data->
Z =
Calloc(
double, n*(m+1));
160 matrix_set(data->
Z, m+1, 0, 0, 1.0000000000000000);
161 matrix_set(data->
Z, m+1, 0, 1, -0.3943375672974065);
162 matrix_set(data->
Z, m+1, 0, 2, -0.1056624327025935);
163 matrix_set(data->
Z, m+1, 1, 0, 1.0000000000000000);
164 matrix_set(data->
Z, m+1, 1, 1, -0.2886751345948129);
165 matrix_set(data->
Z, m+1, 1, 2, -0.2886751345948128);
166 matrix_set(data->
Z, m+1, 2, 0, 1.0000000000000000);
167 matrix_set(data->
Z, m+1, 2, 1, -0.1056624327025937);
168 matrix_set(data->
Z, m+1, 2, 2, -0.3943375672974063);
169 matrix_set(data->
Z, m+1, 3, 0, 1.0000000000000000);
170 matrix_set(data->
Z, m+1, 3, 1, 0.1056624327025935);
171 matrix_set(data->
Z, m+1, 3, 2, -0.3943375672974064);
172 matrix_set(data->
Z, m+1, 4, 0, 1.0000000000000000);
173 matrix_set(data->
Z, m+1, 4, 1, 0.2886751345948129);
174 matrix_set(data->
Z, m+1, 4, 2, -0.2886751345948129);
175 matrix_set(data->
Z, m+1, 5, 0, 1.0000000000000000);
176 matrix_set(data->
Z, m+1, 5, 1, 0.3943375672974064);
177 matrix_set(data->
Z, m+1, 5, 2, -0.1056624327025937);
178 matrix_set(data->
Z, m+1, 6, 0, 1.0000000000000000);
179 matrix_set(data->
Z, m+1, 6, 1, 0.3943375672974065);
180 matrix_set(data->
Z, m+1, 6, 2, 0.1056624327025935);
181 matrix_set(data->
Z, m+1, 7, 0, 1.0000000000000000);
182 matrix_set(data->
Z, m+1, 7, 1, 0.2886751345948130);
183 matrix_set(data->
Z, m+1, 7, 2, 0.2886751345948128);
184 matrix_set(data->
Z, m+1, 8, 0, 1.0000000000000000);
185 matrix_set(data->
Z, m+1, 8, 1, 0.1056624327025939);
186 matrix_set(data->
Z, m+1, 8, 2, 0.3943375672974063);
187 matrix_set(data->
Z, m+1, 9, 0, 1.0000000000000000);
188 matrix_set(data->
Z, m+1, 9, 1, -0.1056624327025934);
189 matrix_set(data->
Z, m+1, 9, 2, 0.3943375672974064);
190 matrix_set(data->
Z, m+1, 10, 0, 1.0000000000000000);
191 matrix_set(data->
Z, m+1, 10, 1, -0.2886751345948126);
192 matrix_set(data->
Z, m+1, 10, 2, 0.2886751345948132);
193 matrix_set(data->
Z, m+1, 11, 0, 1.0000000000000000);
194 matrix_set(data->
Z, m+1, 11, 1, -0.3943375672974064);
195 matrix_set(data->
Z, m+1, 11, 2, 0.1056624327025939);
205 matrix_set(model->
V, K-1, 0, 0, 0.0000000000000000);
206 matrix_set(model->
V, K-1, 0, 1, 0.0000000000000000);
207 matrix_set(model->
V, K-1, 1, 0, -2.4494897427831779);
208 matrix_set(model->
V, K-1, 1, 1, -0.0000000000000002);
209 matrix_set(model->
V, K-1, 2, 0, 0.0000000000000000);
210 matrix_set(model->
V, K-1, 2, 1, -2.4494897427831783);
213 long *predy =
Calloc(
long, n);
216 mu_assert(predy[0] == 2,
"Incorrect label at index 0");
217 mu_assert(predy[1] == 3,
"Incorrect label at index 1");
218 mu_assert(predy[2] == 3,
"Incorrect label at index 2");
219 mu_assert(predy[3] == 3,
"Incorrect label at index 3");
220 mu_assert(predy[4] == 3,
"Incorrect label at index 4");
221 mu_assert(predy[5] == 1,
"Incorrect label at index 5");
222 mu_assert(predy[6] == 1,
"Incorrect label at index 6");
223 mu_assert(predy[7] == 1,
"Incorrect label at index 7");
224 mu_assert(predy[8] == 1,
"Incorrect label at index 8");
225 mu_assert(predy[9] == 2,
"Incorrect label at index 9");
226 mu_assert(predy[10] == 2,
"Incorrect label at index 10");
227 mu_assert(predy[11] == 2,
"Incorrect label at index 11");
256 "Incorrect first time.");
261 "Incorrect second time.");
266 "Incorrect third time.");
Minimal unit testing framework for C.
#define Calloc(type, size)
Header file for gensvm_predict.c.
#define mu_assert(test, message)
char * test_gensvm_predict_labels_dense()
double gensvm_prediction_perf(struct GenData *data, long *perdy)
Calculate the predictive performance (percentage correct)
void gensvm_free_model(struct GenModel *model)
Free allocated GenModel struct.
char * test_gensvm_prediction_perf()
double * V
augmented weight matrix
#define mu_run_test(test)
long * y
array of class labels, 1..K
struct GenModel * gensvm_init_model(void)
Initialize a GenModel structure.
A structure to represent the data.
A structure to represent a single GenSVM model.
void gensvm_predict_labels(struct GenData *testdata, struct GenModel *model, long *predy)
Predict class labels of data given and output in predy.
long n
number of instances in the dataset
void gensvm_free_data(struct GenData *data)
Free allocated GenData struct.
void gensvm_allocate_model(struct GenModel *model)
Allocate memory for a GenModel.
long r
number of eigenvalues (width of Z)
long K
number of classes in the dataset
char * test_gensvm_predict_labels_sparse()
long m
number of predictors (width of RAW)
struct GenSparse * gensvm_dense_to_sparse(double *A, long rows, long cols)
Convert a dense matrix to a GenSparse structure if advantageous.
#define matrix_set(M, cols, i, j, val)
long n
number of instances
struct GenData * gensvm_init_data(void)
Initialize a GenData structure.
long m
number of predictor variables in the dataset
double * RAW
augmented raw data matrix
struct GenSparse * spZ
sparse representation of the augmented data matrix