18 #include <shogun/lib/external/libocas.h>
27 #ifndef DOXYGEN_SHOULD_SKIP_THIS
28 struct wdocas_thread_params_output
38 struct wdocas_thread_params_add
47 #endif // DOXYGEN_SHOULD_SKIP_THIS
50 :
CMachine(), use_bias(false), bufsize(3000), C1(1), C2(1),
66 :
CMachine(), use_bias(false), bufsize(3000), C1(1), C2(1),
82 :
CMachine(), use_bias(false), bufsize(3000), C1(C), C2(C),
epsilon(1e-3),
83 degree(d), from_degree(from_d)
119 SG_ERROR(
"Features not of class string type byte\n")
137 for (int32_t i=0; i<num; i++)
151 int32_t w_dim_single_c=0;
153 for (int32_t i=0; i<
degree; i++)
159 return w_dim_single_c;
173 SG_ERROR(
"Features not of class string type byte\n")
239 SG_INFO(
"Ocas Converged after %d iterations\n"
240 "==================================\n"
241 "timing statistics:\n"
242 "output_time: %f s\n"
247 "ocas_time %f s\n\n", result.nIter, result.output_time, result.sort_time,
248 result.add_time, result.w_time, result.qp_solver_time, result.ocas_time);
250 for (int32_t i=bufsize-1; i>=0; i--)
271 uint32_t nDim = (uint32_t) o->
w_dim;
277 for(uint32_t j=0; j <nDim; j++)
279 W[j] = oldW[j]*(1-t) + t*W[j];
280 sq_norm_W += W[j]*W[j];
302 wdocas_thread_params_add* p = (wdocas_thread_params_add*) ptr;
304 int32_t start = p->start;
305 int32_t end = p->end;
308 uint32_t cut_length=p->cut_length;
309 uint32_t* new_cut=p->new_cut;
323 int32_t* val=SG_MALLOC(int32_t, cut_length);
324 for (int32_t j=start; j<end; j++)
327 memset(val,0,
sizeof(int32_t)*cut_length);
328 int32_t lim=
CMath::min(degree, string_length-j);
331 for (int32_t k=0; k<lim; k++)
337 for(uint32_t i=0; i < cut_length; i++)
339 val[i]=val[i]*alphabet_size + vec[new_cut[i]];
340 new_a[offs+val[i]]+=wd * y[new_cut[i]];
353 float64_t *new_col_H, uint32_t *new_cut, uint32_t cut_length,
354 uint32_t nSel,
void* ptr)
359 uint32_t nDim=(uint32_t) o->
w_dim;
362 memset(new_a, 0,
sizeof(
float32_t)*nDim);
375 nthreads=string_length-1;
379 for (t=0; t<nthreads; t++)
381 params_add[t].wdocas=o;
383 params_add[t].new_a=new_a;
384 params_add[t].new_cut=new_cut;
385 params_add[t].start = step*t;
386 params_add[t].end = step*(t+1);
387 params_add[t].cut_length = cut_length;
397 params_add[t].wdocas=o;
399 params_add[t].new_a=new_a;
400 params_add[t].new_cut=new_cut;
401 params_add[t].start = step*t;
403 params_add[t].cut_length = cut_length;
407 for (t=0; t<nthreads; t++)
409 if (pthread_join(threads[t], NULL) != 0)
420 for(i=0; i < cut_length; i++)
423 c_bias[nSel]+=o->
lab[new_cut[i]];
427 for(i=0; i < nSel; i++)
452 wdocas_thread_params_output* p = (wdocas_thread_params_output*) ptr;
454 int32_t start = p->start;
455 int32_t end = p->end;
458 int32_t* val = p->val;
476 for (int32_t i=start ; i<end; i++)
479 int32_t lim=
CMath::min(degree, string_length-j);
482 for (int32_t k=0; k<lim; k++)
488 for (int32_t i=start; i<end; i++)
490 val[i]=val[i]*alphabet_size + vec[i];
491 out[i]+=wd*w[offs+val[i]];
534 for (int32_t i=start; i<end; i++)
535 output[i]=y[i]*o->
bias + out[i]*y[i]/normalization_const;
547 wdocas_thread_params_output* params_output=SG_MALLOC(wdocas_thread_params_output, o->
parallel->
get_num_threads());
551 int32_t* val=SG_MALLOC(int32_t, nData);
564 for (t=0; t<nthreads; t++)
566 params_output[t].wdocas=o;
567 params_output[t].output=output;
568 params_output[t].out=out;
569 params_output[t].val=val;
570 params_output[t].start = step*t;
571 params_output[t].end = step*(t+1);
582 params_output[t].wdocas=o;
583 params_output[t].output=output;
584 params_output[t].out=out;
585 params_output[t].val=val;
586 params_output[t].start = step*t;
587 params_output[t].end = nData;
591 for (t=0; t<nthreads; t++)
593 if (pthread_join(threads[t], NULL) != 0)
597 SG_FREE(params_output);
617 uint32_t nDim= (uint32_t) o->
w_dim;
627 for (uint32_t i=0; i<nSel; i++)
632 bias += c_bias[i]*alpha[i];
virtual int32_t get_max_vector_length()
SGVector< ST > get_feature_vector(int32_t num)
virtual ELabelType get_label_type() const =0
Real Labels are real-valued labels.
RAWDNA - letters 0,1,2,3.
int32_t get_num_threads() const
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)
virtual CRegressionLabels * apply_regression(CFeatures *data=NULL)
static void * add_new_cut_helper(void *ptr)
EAlphabet get_alphabet() const
virtual int32_t get_num_vectors() const
static int compute_output(float64_t *output, void *ptr)
The class Alphabet implements an alphabet and alphabet utility functions.
void free_feature_vector(ST *feat_vec, int32_t num, bool dofree)
A generic learning machine interface.
SGVector< float64_t > apply_get_outputs(CFeatures *data)
static float64_t update_W(float64_t t, void *ptr)
virtual CBinaryLabels * apply_binary(CFeatures *data=NULL)
static const float64_t epsilon
CStringFeatures< uint8_t > * get_features()
static void * compute_output_helper(void *ptr)
CStringFeatures< uint8_t > * features
float64_t normalization_const
void set_normalization_const()
int32_t get_num_symbols() const
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)
virtual EFeatureClass get_feature_class() const =0
CAlphabet * get_alphabet()
virtual float64_t apply_one(int32_t num)
static void vec1_plus_scalar_times_vec2(T *vec1, const T scalar, const T *vec2, int32_t n)
x=x+alpha*y
static float64_t dot(const bool *v1, const bool *v2, int32_t n)
compute dot product between v1 and v2 (blas optimized)
all of classes and functions are contained in the shogun namespace
The class Features is the base class of all feature objects.
static T min(T a, T b)
return the minimum of two integers
Binary Labels for binary classification.
static void swap(T &a, T &b)
swap e.g. floats a and b
static void print(ocas_return_value_T value)
int32_t w_dim_single_char
virtual void set_labels(CLabels *lab)
#define SG_UNSTABLE(func,...)
static int32_t pow(bool x, int32_t n)
virtual EFeatureType get_feature_type() const =0
void set_features(CStringFeatures< uint8_t > *feat)