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");
virtual const char * get_name() const =0
virtual bool init(CFeatures *lhs, CFeatures *rhs)
int32_t get_num_support_vectors()
virtual ~CMulticlassSVM()
The class Labels models labels, i.e. class assignments of objects.
bool load(FILE *svm_file)
CDynamicObjectArray * m_machines
virtual int32_t get_num_vectors() const =0
virtual bool init_machines_for_apply(CFeatures *data)
int32_t get_num_elements() const
generic kernel multiclass
bool set_element(CSGObject *e, int32_t idx1, int32_t idx2=0, int32_t idx3=0)
void set_bias(float64_t bias)
CMulticlassStrategy * m_multiclass_strategy
virtual int32_t get_num_machines()=0
bool set_alpha(int32_t idx, float64_t val)
bool save(FILE *svm_file)
float64_t get_alpha(int32_t idx)
bool set_support_vector(int32_t idx, int32_t val)
int32_t get_support_vector(int32_t idx)
virtual const char * get_name() const
int32_t get_num_classes() const
all of classes and functions are contained in the shogun namespace
virtual EKernelType get_kernel_type()=0
The class Features is the base class of all feature objects.
bool create_multiclass_svm(int32_t num_classes)
A generic Support Vector Machine Interface.
CSGObject * get_element(int32_t index) const
class MulticlassStrategy used to construct generic multiclass classifiers with ensembles of binary cl...
void push_back(CSGObject *e)
void set_kernel(CKernel *k)
multiclass one vs rest strategy used to train generic multiclass machines for K-class problems with b...
bool set_svm(int32_t num, CSVM *svm)
bool is_data_locked() const
CSVM * get_svm(int32_t num)