22 using namespace shogun;
63 SG_ERROR(
"Specified features are not of type CDotFeatures\n");
73 if (num_vec!=lab.vlen || num_vec<=0)
74 SG_ERROR(
"num_vec=%d num_train_labels=%d\n", num_vec, lab.vlen);
110 SG_INFO(
"Ocas Converged after %d iterations\n"
111 "==================================\n"
112 "timing statistics:\n"
113 "output_time: %f s\n"
118 "ocas_time %f s\n\n", result.nIter, result.output_time, result.sort_time,
119 result.add_time, result.w_time, result.qp_solver_time, result.ocas_time);
123 uint32_t num_cut_planes = result.nCutPlanes;
125 SG_DEBUG(
"num_cut_planes=%d\n", num_cut_planes);
126 for (uint32_t i=0; i<num_cut_planes; i++)
162 uint32_t nDim = (uint32_t) o->
w_dim;
166 for(uint32_t j=0; j <nDim; j++)
168 W[j] = oldW[j]*(1-t) + t*W[j];
169 sq_norm_W += W[j]*W[j];
186 float64_t *new_col_H, uint32_t *new_cut, uint32_t cut_length,
187 uint32_t nSel,
void* ptr)
191 uint32_t nDim=(uint32_t) o->
w_dim;
200 uint32_t i, j, nz_dims;
204 memset(new_a, 0,
sizeof(
float64_t)*nDim);
206 for(i=0; i < cut_length; i++)
211 c_bias[nSel]+=y[new_cut[i]];
217 for(j=0; j < nDim; j++ ) {
220 sq_norm_a += new_a[j]*new_a[j];
225 c_nzd[nSel] = nz_dims;
231 c_idx[nSel]=
SG_MALLOC(uint32_t, nz_dims);
235 for(j=0; j < nDim; j++ )
239 c_idx[nSel][idx] = j;
240 c_val[nSel][idx++] = new_a[j];
245 new_col_H[nSel] = sq_norm_a;
247 for(i=0; i < nSel; i++)
250 for(j=0; j < c_nzd[i]; j++)
251 tmp += new_a[c_idx[i][j]]*c_val[i][j];
282 for (int32_t i=0; i<nData; i++)
283 output[i]+=y[i]*o->
bias;
303 uint32_t nDim= (uint32_t) o->
w_dim;
316 for(uint32_t i=0; i<nSel; i++)
318 uint32_t nz_dims = c_nzd[i];
320 if(nz_dims > 0 && alpha[i] > 0)
322 for(uint32_t j=0; j < nz_dims; j++)
323 W[c_idx[i][j]] += alpha[i]*c_val[i][j];
325 bias += c_bias[i]*alpha[i];
336 void CSVMOcas::init()
357 "Indicates if bias is used.");
361 "SVMOcas solver type.");
bool has_property(EFeatureProperty p)
virtual void dense_dot_range(float64_t *output, int32_t start, int32_t stop, float64_t *alphas, float64_t *vec, int32_t dim, float64_t b)
static void print(ocas_return_value_T value)
SGVector< float64_t > get_labels()
The class Labels models labels, i.e. class assignments of objects.
static void qsort_index(T1 *output, T2 *index, uint32_t size)
ocas_return_value_T svm_ocas_solver(float64_t C, uint32_t nData, float64_t TolRel, float64_t TolAbs, float64_t QPBound, float64_t MaxTime, uint32_t _BufSize, uint8_t Method, void(*compute_W)(float64_t *, float64_t *, float64_t *, uint32_t, void *), float64_t(*update_W)(float64_t, void *), int(*add_new_cut)(float64_t *, uint32_t *, uint32_t, uint32_t, void *), int(*compute_output)(float64_t *, void *), int(*sort)(float64_t *, float64_t *, uint32_t), void(*ocas_print)(ocas_return_value_T), void *user_data)
virtual int32_t get_num_vectors() const =0
virtual void add_to_dense_vec(float64_t alpha, int32_t vec_idx1, float64_t *vec2, int32_t vec2_len, bool abs_val=false)=0
virtual bool train_machine(CFeatures *data=NULL)
Features that support dot products among other operations.
virtual int32_t get_dim_feature_space() const =0
SGVector< float64_t > lab
void add(bool *param, const char *name, const char *description="")
virtual void destroy_vector()
float64_t get_max_train_time()
static int compute_output(float64_t *output, void *ptr)
Class LinearMachine is a generic interface for all kinds of linear machines like classifiers.
static float64_t dot(const bool *v1, const bool *v2, int32_t n)
compute dot product between v1 and v2 (blas optimized)
bool is_two_class_labeling()
static int sort(float64_t *vals, float64_t *data, uint32_t size)
static float64_t update_W(float64_t t, void *ptr)
The class Features is the base class of all feature objects.
virtual void set_features(CDotFeatures *feat)
static void swap(T &a, T &b)
swap e.g. floats a and b
static int add_new_cut(float64_t *new_col_H, uint32_t *new_cut, uint32_t cut_length, uint32_t nSel, void *ptr)
virtual void set_labels(CLabels *lab)
static void compute_W(float64_t *sq_norm_W, float64_t *dp_WoldW, float64_t *alpha, uint32_t nSel, void *ptr)
#define SG_MALLOC(type, len)