24 using namespace shogun;
26 #ifndef DOXYGEN_SHOULD_SKIP_THIS
27 struct wdocas_thread_params_output
37 struct wdocas_thread_params_add
46 #endif // DOXYGEN_SHOULD_SKIP_THIS
49 :
CMachine(), use_bias(false), bufsize(3000), C1(1), C2(1),
50 epsilon(1e-3), method(SVM_OCAS)
65 :
CMachine(), use_bias(false), bufsize(3000), C1(1), C2(1),
66 epsilon(1e-3), method(type)
81 :
CMachine(), use_bias(false), bufsize(3000), C1(C), C2(C), epsilon(1e-3),
82 degree(d), from_degree(from_d)
112 for (int32_t i=0; i<num; i++)
124 SG_ERROR(
"No features specified\n");
129 SG_ERROR(
"Features not of class string type byte\n");
143 int32_t w_dim_single_c=0;
145 for (int32_t i=0; i<
degree; i++)
151 return w_dim_single_c;
164 SG_ERROR(
"Features not of class string type byte\n");
231 SG_INFO(
"Ocas Converged after %d iterations\n"
232 "==================================\n"
233 "timing statistics:\n"
234 "output_time: %f s\n"
239 "ocas_time %f s\n\n", result.nIter, result.output_time, result.sort_time,
240 result.add_time, result.w_time, result.qp_solver_time, result.ocas_time);
242 for (int32_t i=bufsize-1; i>=0; i--)
265 uint32_t nDim = (uint32_t) o->
w_dim;
271 for(uint32_t j=0; j <nDim; j++)
273 W[j] = oldW[j]*(1-t) + t*W[j];
274 sq_norm_W += W[j]*W[j];
296 wdocas_thread_params_add* p = (wdocas_thread_params_add*) ptr;
298 int32_t start = p->start;
299 int32_t end = p->end;
302 uint32_t cut_length=p->cut_length;
303 uint32_t* new_cut=p->new_cut;
317 int32_t* val=
SG_MALLOC(int32_t, cut_length);
318 for (int32_t j=start; j<end; j++)
321 memset(val,0,
sizeof(int32_t)*cut_length);
322 int32_t lim=
CMath::min(degree, string_length-j);
325 for (int32_t k=0; k<lim; k++)
331 for(uint32_t i=0; i < cut_length; i++)
333 val[i]=val[i]*alphabet_size + vec[new_cut[i]];
334 new_a[offs+val[i]]+=wd * y[new_cut[i]];
347 float64_t *new_col_H, uint32_t *new_cut, uint32_t cut_length,
348 uint32_t nSel,
void* ptr)
352 uint32_t nDim=(uint32_t) o->
w_dim;
360 memset(new_a, 0,
sizeof(
float32_t)*nDim);
368 nthreads=string_length-1;
372 for (t=0; t<nthreads; t++)
374 params_add[t].wdocas=o;
376 params_add[t].new_a=new_a;
377 params_add[t].new_cut=new_cut;
378 params_add[t].start = step*t;
379 params_add[t].end = step*(t+1);
380 params_add[t].cut_length = cut_length;
390 params_add[t].wdocas=o;
392 params_add[t].new_a=new_a;
393 params_add[t].new_cut=new_cut;
394 params_add[t].start = step*t;
396 params_add[t].cut_length = cut_length;
400 for (t=0; t<nthreads; t++)
402 if (pthread_join(threads[t], NULL) != 0)
411 for(i=0; i < cut_length; i++)
414 c_bias[nSel]+=o->
lab[new_cut[i]];
418 for(i=0; i < nSel; i++)
419 new_col_H[i] =
CMath::dot(new_a,
cuts[i], nDim) + c_bias[nSel]*c_bias[i];
445 wdocas_thread_params_output* p = (wdocas_thread_params_output*) ptr;
447 int32_t start = p->start;
448 int32_t end = p->end;
451 int32_t* val = p->val;
469 for (int32_t i=start ; i<end; i++)
472 int32_t lim=
CMath::min(degree, string_length-j);
475 for (int32_t k=0; k<lim; k++)
481 for (int32_t i=start; i<end; i++)
483 val[i]=val[i]*alphabet_size + vec[i];
484 out[i]+=wd*w[offs+val[i]];
527 for (int32_t i=start; i<end; i++)
528 output[i]=y[i]*o->
bias + out[i]*y[i]/normalization_const;
556 for (t=0; t<nthreads; t++)
558 params_output[t].wdocas=o;
559 params_output[t].output=output;
560 params_output[t].out=out;
561 params_output[t].val=val;
562 params_output[t].start = step*t;
563 params_output[t].end = step*(t+1);
574 params_output[t].wdocas=o;
575 params_output[t].output=output;
576 params_output[t].out=out;
577 params_output[t].val=val;
578 params_output[t].start = step*t;
579 params_output[t].end = nData;
583 for (t=0; t<nthreads; t++)
585 if (pthread_join(threads[t], NULL) != 0)
608 uint32_t nDim= (uint32_t) o->
w_dim;
618 for (uint32_t i=0; i<nSel; i++)
623 bias += c_bias[i]*alpha[i];
virtual EFeatureType get_feature_type()=0
bool set_label(int32_t idx, float64_t label)
RAWDNA - letters 0,1,2,3.
int32_t get_num_threads() const
SGVector< float64_t > get_labels()
static int sort(float64_t *vals, float64_t *data, uint32_t size)
The class Labels models labels, i.e. class assignments of objects.
static int add_new_cut(float64_t *new_col_H, uint32_t *new_cut, uint32_t cut_length, uint32_t nSel, void *ptr)
static void qsort_index(T1 *output, T2 *index, uint32_t size)
static void * add_new_cut_helper(void *ptr)
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)
static int compute_output(float64_t *output, void *ptr)
The class Alphabet implements an alphabet and alphabet utility functions.
static void vec1_plus_scalar_times_vec2(T *vec1, T scalar, const T *vec2, int32_t n)
x=x+alpha*y
virtual int32_t get_num_vectors() const
A generic learning machine interface.
static float64_t update_W(float64_t t, void *ptr)
virtual void free_vector()
CStringFeatures< uint8_t > * get_features()
static void * compute_output_helper(void *ptr)
virtual EFeatureClass get_feature_class()=0
CStringFeatures< uint8_t > * features
float64_t normalization_const
static int32_t pow(int32_t x, int32_t n)
void set_normalization_const()
void free_feature_vector(ST *feat_vec, int32_t num, bool dofree)
float64_t get_max_train_time()
virtual bool train_machine(CFeatures *data=NULL)
static void compute_W(float64_t *sq_norm_W, float64_t *dp_WoldW, float64_t *alpha, uint32_t nSel, void *ptr)
SGVector< ST > get_feature_vector(int32_t num)
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()
The class Features is the base class of all feature objects.
static T min(T a, T b)
return the minimum of two integers
virtual int32_t get_max_vector_length()
static void swap(T &a, T &b)
swap e.g. floats a and b
CAlphabet * get_alphabet()
static void print(ocas_return_value_T value)
int32_t w_dim_single_char
virtual void set_labels(CLabels *lab)
#define SG_UNSTABLE(func,...)
#define SG_MALLOC(type, len)
void set_features(CStringFeatures< uint8_t > *feat)