25 #ifndef DOXYGEN_SHOULD_SKIP_THIS
26 struct DF_THREAD_PARAM
39 #endif // DOXYGEN_SHOULD_SKIP_THIS
50 :
CFeatures(orig), combined_weight(orig.combined_weight)
77 int32_t num_vectors=stop-start;
89 DF_THREAD_PARAM params;
91 params.sub_index=NULL;
99 params.progress=
false;
105 pthread_t* threads = SG_MALLOC(pthread_t, num_threads-1);
106 DF_THREAD_PARAM* params = SG_MALLOC(DF_THREAD_PARAM, num_threads);
107 int32_t step= num_vectors/num_threads;
111 for (t=0; t<num_threads-1; t++)
114 params[t].sub_index=NULL;
115 params[t].output = output;
116 params[t].start = start+t*step;
117 params[t].stop = start+(t+1)*step;
118 params[t].alphas=alphas;
122 params[t].progress =
false;
123 pthread_create(&threads[t], NULL,
128 params[t].output = output;
129 params[t].sub_index=NULL;
130 params[t].start = start+t*step;
131 params[t].stop = stop;
132 params[t].alphas=alphas;
136 params[t].progress =
false;
139 for (t=0; t<num_threads-1; t++)
140 pthread_join(threads[t], NULL);
149 SG_INFO(
"prematurely stopped. \n")
167 DF_THREAD_PARAM params;
169 params.sub_index=sub_index;
170 params.output=output;
173 params.alphas=alphas;
177 params.progress=
false;
183 pthread_t* threads = SG_MALLOC(pthread_t, num_threads-1);
184 DF_THREAD_PARAM* params = SG_MALLOC(DF_THREAD_PARAM, num_threads);
185 int32_t step= num/num_threads;
189 for (t=0; t<num_threads-1; t++)
192 params[t].sub_index=sub_index;
193 params[t].output = output;
194 params[t].start = t*step;
195 params[t].stop = (t+1)*step;
196 params[t].alphas=alphas;
200 params[t].progress =
false;
201 pthread_create(&threads[t], NULL,
206 params[t].sub_index=sub_index;
207 params[t].output = output;
208 params[t].start = t*step;
209 params[t].stop = num;
210 params[t].alphas=alphas;
214 params[t].progress =
false;
217 for (t=0; t<num_threads-1; t++)
218 pthread_join(threads[t], NULL);
227 SG_INFO(
"prematurely stopped. \n")
233 DF_THREAD_PARAM* par=(DF_THREAD_PARAM*) p;
235 int32_t* sub_index=par->sub_index;
237 int32_t start=par->start;
238 int32_t stop=par->stop;
241 int32_t dim=par->dim;
243 bool progress=par->progress;
248 for (int32_t i=start; i<stop i++)
250 for (int32_t i=start; i<stop &&
255 output[i]=alphas[sub_index[i]]*df->
dense_dot(sub_index[i], vec, dim)+bias;
257 output[i]=df->
dense_dot(sub_index[i], vec, dim)+bias;
266 for (int32_t i=start; i<stop i++)
268 for (int32_t i=start; i<stop &&
273 output[i]=alphas[i]*df->
dense_dot(i, vec, dim)+bias;
275 output[i]=df->
dense_dot(i, vec, dim)+bias;
296 for (int32_t i=0; i<num; i++)
328 for (int32_t r=0; r<repeats; r++)
330 for (int32_t i=0; i<num; i++)
334 SG_PRINT(
"Time to process %d x num=%d add_to_dense_vector ops: cputime %fs walltime %fs\n",
357 for (int32_t r=0; r<repeats; r++)
360 #ifdef DEBUG_DOTFEATURES
361 CMath::display_vector(out, 40,
"dense_dot_range");
364 for (int32_t r=0; r<repeats; r++)
366 CMath::fill_vector(out2, num, 0.0);
367 for (int32_t i=0; i<num; i++)
368 out2[i]+=
dense_dot(i, w, d)*alphas[i]+23;
370 CMath::display_vector(out2, 40,
"dense_dot");
371 for (int32_t i=0; i<num; i++)
373 CMath::display_vector(out2, 40,
"diff");
375 SG_PRINT(
"Time to process %d x num=%d dense_dot_range ops: cputime %fs walltime %fs\n",
394 for (
int i = 0; i < num; i++)
396 for (
int j = 0; j < dim; j++)
417 for (
int i = 0; i < num_lhs; i++)
419 for (
int i = 0; i < num_rhs; i++)
421 for (
int j = 0; j < dim; j++)
422 mean.
vector[j] /= (num_lhs+num_rhs);
440 for (
int i = 0; i < num; i++)
444 for (
int m = 0; m < v.
vlen; m++)
446 for (
int n = 0; n <= m ; n++)
452 for (
int m = 0; m < dim; m++)
454 for (
int n = 0; n <= m ; n++)
456 (cov.
matrix)[m*dim+n] /= num;
459 for (
int m = 0; m < dim-1; m++)
461 for (
int n = m+1; n < dim; n++)
475 int32_t nums[2], dims[2], num=0;
477 for (
int i = 0; i < 2; i++)
487 int32_t dim = dims[0];
495 for (
int i = 0; i < 2; i++)
497 for (
int j = 0; j < nums[i]; j++)
501 for (
int m = 0; m < v.
vlen; m++)
503 for (
int n = 0; n <= m; n++)
510 for (
int m = 0; m < dim; m++)
512 for (
int n = 0; n <= m; n++)
514 (cov.
matrix)[m*dim+n] /= num;
517 for (
int m = 0; m < dim-1; m++)
519 for (
int n = m+1; n < dim; n++)
530 int32_t num_vectors=stop-start;
533 if ( (i% (num_vectors/100+1))== 0)
537 void CDotFeatures::init()
541 "Feature weighting in combined dot features.");
Class Time that implements a stopwatch based on either cpu time or wall clock time.
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 fill_vector(T *vec, int32_t len, T value)
int32_t get_num_threads() const
virtual float64_t dense_dot(int32_t vec_idx1, const float64_t *vec2, int32_t vec2_len)=0
CDotFeatures(int32_t size=0)
static float64_t get_runtime()
virtual int32_t get_num_vectors() const =0
void set_property(EFeatureProperty p)
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
void benchmark_dense_dot_range(int32_t repeats=5)
virtual float64_t dense_dot_sgvec(int32_t vec_idx1, const SGVector< float64_t > vec2)
Features that support dot products among other operations.
virtual int32_t get_dim_feature_space() const =0
static float64_t get_curtime()
virtual SGVector< float64_t > get_mean()
static SGMatrix< float64_t > compute_cov(CDotFeatures *lhs, CDotFeatures *rhs)
void add(bool *param, const char *name, const char *description="")
static void clear_cancel()
virtual void dense_dot_range_subset(int32_t *sub_index, int32_t num, float64_t *output, float64_t *alphas, float64_t *vec, int32_t dim, float64_t b)
static void range_fill_vector(T *vec, int32_t len, T start=0)
A File access base class.
void benchmark_add_to_dense_vector(int32_t repeats=5)
static bool cancel_computations()
all of classes and functions are contained in the shogun namespace
The class Features is the base class of all feature objects.
SGVector< float64_t > get_computed_dot_feature_vector(int32_t num)
void display_progress(int32_t start, int32_t stop, int32_t v)
float64_t combined_weight
feature weighting in combined dot features
SGMatrix< float64_t > get_computed_dot_feature_matrix()
void add(const SGVector< T > x)
static void * dense_dot_range_helper(void *p)
virtual SGMatrix< float64_t > get_cov()