16 using namespace shogun;
42 void CMulticlassSVM::init()
55 for (
index_t i=0; i<num_svms; ++i)
77 SG_ERROR(
"CKernelMachine::apply(CFeatures*) cannot be called when "
78 "data_lock was called before. Call data_unlock to allow.");
90 SG_ERROR(
"%s: No vectors on left hand side (%s). This is probably due to"
91 " an implementation error in %s, where it was forgotten to set "
92 "the data (m_svs) indices\n",
get_name(),
114 char char_buffer[1024];
117 int32_t line_number=1;
122 if (fscanf(modelfl,
"%15s\n", char_buffer)==EOF)
123 SG_ERROR(
"error in svm file, line nr:%d\n", line_number)
126 char_buffer[15]=
'\0';
127 if (strcmp(
"%MultiClassSVM", char_buffer)!=0)
128 SG_ERROR(
"error in multiclass svm file, line nr:%d\n", line_number)
134 if (fscanf(modelfl,
" num_classes=%d; \n", &int_buffer) != 1)
135 SG_ERROR(
"error in svm file, line nr:%d\n", line_number)
141 SG_ERROR(
"less than 2 classes - how is this multiclass?\n")
146 if (fscanf(modelfl,
" num_svms=%d; \n", &int_buffer) != 1)
147 SG_ERROR(
"error in svm file, line nr:%d\n", line_number)
155 if (fscanf(modelfl,
" kernel='%s'; \n", char_buffer) != 1)
156 SG_ERROR(
"error in svm file, line nr:%d\n", line_number)
164 if (fscanf(modelfl,
"\n%4s %d of %d\n", char_buffer, &svm_idx, &int_buffer)==EOF)
167 SG_ERROR(
"error in svm file, line nr:%d\n", line_number)
172 if (strncmp(
"%SVM", char_buffer, 4)!=0)
175 SG_ERROR(
"error in svm file, line nr:%d\n", line_number)
179 SG_ERROR(
"svm index mismatch n=%d, n(file)=%d\n", n, svm_idx)
185 if (fscanf(modelfl,
"numsv%d=%d;\n", &svm_idx, &int_buffer) != 2)
186 SG_ERROR(
"error in svm file, line nr:%d\n", line_number)
189 SG_ERROR(
"svm index mismatch n=%d, n(file)=%d\n", n, svm_idx)
194 SG_INFO(
"loading %ld support vectors for svm %d\n",int_buffer, svm_idx)
199 if (fscanf(modelfl,
" b%d=%lf; \n", &svm_idx, &double_buffer) != 2)
200 SG_ERROR(
"error in svm file, line nr:%d\n", line_number)
203 SG_ERROR(
"svm index mismatch n=%d, n(file)=%d\n", n, svm_idx)
210 if (fscanf(modelfl,
"alphas%d=[\n", &svm_idx) != 1)
211 SG_ERROR(
"error in svm file, line nr:%d\n", line_number)
214 SG_ERROR(
"svm index mismatch n=%d, n(file)=%d\n", n, svm_idx)
224 if (fscanf(modelfl,
"\t[%lf,%d]; \n", &double_buffer, &int_buffer) != 2)
225 SG_ERROR(
"error in svm file, line nr:%d\n", line_number)
234 if (fscanf(modelfl,
"%2s", char_buffer) == EOF)
237 SG_ERROR(
"error in svm file, line nr:%d\n", line_number)
242 if (strcmp(
"];", char_buffer)!=0)
245 SG_ERROR(
"error in svm file, line nr:%d\n", line_number)
267 SG_ERROR(
"Multiclass SVM not trained!\n")
269 SG_INFO(
"Writing model file...")
270 fprintf(modelfl,
"%%MultiClassSVM\n");
281 fprintf(modelfl,
"b%d=%+10.16e;\n",i,svm->
get_bias());
283 fprintf(modelfl,
"alphas%d=[\n", i);
287 fprintf(modelfl,
"\t[%+10.16e,%d];\n",
291 fprintf(modelfl,
"];\n");