16 using namespace shogun;
41 void CMulticlassSVM::init()
53 for (
index_t i=0; i<num_svms; ++i)
75 SG_ERROR(
"CKernelMachine::apply(CFeatures*) cannot be called when "
76 "data_lock was called before. Call data_unlock to allow.");
88 SG_ERROR(
"%s: No vectors on left hand side (%s). This is probably due to"
89 " an implementation error in %s, where it was forgotten to set "
90 "the data (m_svs) indices\n",
get_name(),
112 char char_buffer[1024];
115 int32_t line_number=1;
120 if (fscanf(modelfl,
"%15s\n", char_buffer)==EOF)
121 SG_ERROR(
"error in svm file, line nr:%d\n", line_number);
124 char_buffer[15]=
'\0';
125 if (strcmp(
"%MultiClassSVM", char_buffer)!=0)
126 SG_ERROR(
"error in multiclass svm file, line nr:%d\n", line_number);
132 if (fscanf(modelfl,
" num_classes=%d; \n", &int_buffer) != 1)
133 SG_ERROR(
"error in svm file, line nr:%d\n", line_number);
139 SG_ERROR(
"less than 2 classes - how is this multiclass?\n");
144 if (fscanf(modelfl,
" num_svms=%d; \n", &int_buffer) != 1)
145 SG_ERROR(
"error in svm file, line nr:%d\n", line_number);
153 if (fscanf(modelfl,
" kernel='%s'; \n", char_buffer) != 1)
154 SG_ERROR(
"error in svm file, line nr:%d\n", line_number);
162 if (fscanf(modelfl,
"\n%4s %d of %d\n", char_buffer, &svm_idx, &int_buffer)==EOF)
165 SG_ERROR(
"error in svm file, line nr:%d\n", line_number);
170 if (strncmp(
"%SVM", char_buffer, 4)!=0)
173 SG_ERROR(
"error in svm file, line nr:%d\n", line_number);
177 SG_ERROR(
"svm index mismatch n=%d, n(file)=%d\n", n, svm_idx);
183 if (fscanf(modelfl,
"numsv%d=%d;\n", &svm_idx, &int_buffer) != 2)
184 SG_ERROR(
"error in svm file, line nr:%d\n", line_number);
187 SG_ERROR(
"svm index mismatch n=%d, n(file)=%d\n", n, svm_idx);
192 SG_INFO(
"loading %ld support vectors for svm %d\n",int_buffer, svm_idx);
197 if (fscanf(modelfl,
" b%d=%lf; \n", &svm_idx, &double_buffer) != 2)
198 SG_ERROR(
"error in svm file, line nr:%d\n", line_number);
201 SG_ERROR(
"svm index mismatch n=%d, n(file)=%d\n", n, svm_idx);
208 if (fscanf(modelfl,
"alphas%d=[\n", &svm_idx) != 1)
209 SG_ERROR(
"error in svm file, line nr:%d\n", line_number);
212 SG_ERROR(
"svm index mismatch n=%d, n(file)=%d\n", n, svm_idx);
222 if (fscanf(modelfl,
"\t[%lf,%d]; \n", &double_buffer, &int_buffer) != 2)
223 SG_ERROR(
"error in svm file, line nr:%d\n", line_number);
232 if (fscanf(modelfl,
"%2s", char_buffer) == EOF)
235 SG_ERROR(
"error in svm file, line nr:%d\n", line_number);
240 if (strcmp(
"];", char_buffer)!=0)
243 SG_ERROR(
"error in svm file, line nr:%d\n", line_number);
265 SG_ERROR(
"Multiclass SVM not trained!\n");
267 SG_INFO(
"Writing model file...");
268 fprintf(modelfl,
"%%MultiClassSVM\n");
279 fprintf(modelfl,
"b%d=%+10.16e;\n",i,svm->
get_bias());
281 fprintf(modelfl,
"alphas%d=[\n", i);
285 fprintf(modelfl,
"\t[%+10.16e,%d];\n",
289 fprintf(modelfl,
"];\n");