17 #define INDEX(ROW,COL,DIM) (((COL)*(DIM))+(ROW))
18 #define MINUS_INF INT_MIN
19 #define PLUS_INF INT_MAX
20 #define KDELTA(A,B) (A==B)
21 #define KDELTA4(A1,A2,A3,A4) ((A1==A2)||(A1==A3)||(A1==A4)||(A2==A3)||(A2==A4)||(A3==A4))
48 "Is the basic untransformed alpha.");
63 SG_ERROR(
"%s::train_machine(): Number of training vectors (%d) does"
64 " not match number of labels (%d)\n",
get_name(),
72 int32_t num_virtual_data= num_data*(num_classes-1);
74 SG_INFO(
"%d trainlabels, %d classes\n", num_data, num_classes)
77 for (int32_t i=0; i<num_data; i++)
84 int32_t tmax = 1000000000;
95 memset(vector_c, 0, num_virtual_data*
sizeof(
float64_t));
102 CGMNPLib mnp(vector_y,
m_kernel,num_data, num_virtual_data, num_classes, reg_const);
104 mnp.
gmnp_imdm(vector_c, num_virtual_data, tmax,
105 tolabs, tolrel, thlb, alpha, &t, &History, verb);
109 memset(all_alphas,0,num_classes*num_data*
sizeof(
float64_t));
113 memset(all_bs,0,num_classes*
sizeof(
float64_t));
116 for(int32_t i=0; i < num_classes; i++ )
118 for(int32_t j=0; j < num_virtual_data; j++ )
125 all_alphas[(inx1*num_classes)+i] +=
127 all_bs[i] += alpha[j]*(
KDELTA(vector_y[inx1],i+1)-
KDELTA(i+1,inx2));
133 for (int32_t i=0; i<num_classes; i++)
136 for (int32_t j=0; j<num_data; j++)
138 if (all_alphas[j*num_classes+i] != 0)
142 SG_DEBUG(
"svm[%d] has %d sv, b=%f\n", i, num_sv, all_bs[i])
147 for (int32_t j=0; j<num_data; j++)
149 if (all_alphas[j*num_classes+i] != 0)
151 svm->
set_alpha(k, all_alphas[j*num_classes+i]);
167 for(
index_t j=0; j<num_virtual_data; j++)
188 if (y == NULL || x == NULL)
return NULL;
virtual bool init(CFeatures *lhs, CFeatures *rhs)
virtual ELabelType get_label_type() const =0
class GMNPLib Library of solvers for Generalized Minimal Norm Problem (GMNP).
The class Labels models labels, i.e. class assignments of objects.
virtual int32_t get_num_labels() const =0
multi-class labels 0,1,...
float64_t * get_basealphas_ptr(index_t *y, index_t *x)
virtual int32_t get_num_vectors() const =0
Multiclass Labels for multi-class classification.
void get_indices2(int32_t *index, int32_t *c, int32_t i)
void set_bias(float64_t bias)
CMulticlassStrategy * m_multiclass_strategy
bool set_alpha(int32_t idx, float64_t val)
int8_t gmnp_imdm(float64_t *vector_c, int32_t dim, int32_t tmax, float64_t tolabs, float64_t tolrel, float64_t th, float64_t *alpha, int32_t *ptr_t, float64_t **ptr_History, int32_t verb)
bool set_support_vector(int32_t idx, int32_t val)
int32_t get_num_classes() const
all of classes and functions are contained in the shogun namespace
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.
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)
virtual const char * get_name() const
void add_matrix(bool **param, index_t *length_y, index_t *length_x, const char *name, const char *description="")
virtual bool train_machine(CFeatures *data=NULL)