23 using namespace shogun;
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)
72 int32_t num_vectors=stop-start;
84 DF_THREAD_PARAM params;
86 params.sub_index=NULL;
94 params.progress=
false;
100 pthread_t* threads =
SG_MALLOC(pthread_t, num_threads-1);
101 DF_THREAD_PARAM* params =
SG_MALLOC(DF_THREAD_PARAM, num_threads);
102 int32_t step= num_vectors/num_threads;
106 for (t=0; t<num_threads-1; t++)
109 params[t].sub_index=NULL;
110 params[t].output = output;
111 params[t].start = start+t*step;
112 params[t].stop = start+(t+1)*step;
113 params[t].alphas=alphas;
117 params[t].progress =
false;
118 pthread_create(&threads[t], NULL,
123 params[t].output = output;
124 params[t].sub_index=NULL;
125 params[t].start = start+t*step;
126 params[t].stop = stop;
127 params[t].alphas=alphas;
131 params[t].progress =
false;
134 for (t=0; t<num_threads-1; t++)
135 pthread_join(threads[t], NULL);
144 SG_INFO(
"prematurely stopped. \n");
162 DF_THREAD_PARAM params;
164 params.sub_index=sub_index;
165 params.output=output;
168 params.alphas=alphas;
172 params.progress=
false;
178 pthread_t* threads =
SG_MALLOC(pthread_t, num_threads-1);
179 DF_THREAD_PARAM* params =
SG_MALLOC(DF_THREAD_PARAM, num_threads);
180 int32_t step= num/num_threads;
184 for (t=0; t<num_threads-1; t++)
187 params[t].sub_index=sub_index;
188 params[t].output = output;
189 params[t].start = t*step;
190 params[t].stop = (t+1)*step;
191 params[t].alphas=alphas;
195 params[t].progress =
false;
196 pthread_create(&threads[t], NULL,
201 params[t].sub_index=sub_index;
202 params[t].output = output;
203 params[t].start = t*step;
204 params[t].stop = num;
205 params[t].alphas=alphas;
209 params[t].progress =
false;
212 for (t=0; t<num_threads-1; t++)
213 pthread_join(threads[t], NULL);
222 SG_INFO(
"prematurely stopped. \n");
228 DF_THREAD_PARAM* par=(DF_THREAD_PARAM*) p;
230 int32_t* sub_index=par->sub_index;
232 int32_t start=par->start;
233 int32_t stop=par->stop;
236 int32_t dim=par->dim;
238 bool progress=par->progress;
243 for (int32_t i=start; i<stop i++)
245 for (int32_t i=start; i<stop &&
250 output[i]=alphas[sub_index[i]]*df->
dense_dot(sub_index[i], vec, dim)+bias;
252 output[i]=df->
dense_dot(sub_index[i], vec, dim)+bias;
261 for (int32_t i=start; i<stop i++)
263 for (int32_t i=start; i<stop &&
268 output[i]=alphas[i]*df->
dense_dot(i, vec, dim)+bias;
270 output[i]=df->
dense_dot(i, vec, dim)+bias;
289 int64_t sz=((uint64_t) num)* dim;
297 for (int32_t i=0; i<num; i++)
333 for (int32_t r=0; r<repeats; r++)
335 for (int32_t i=0; i<num; i++)
339 SG_PRINT(
"Time to process %d x num=%d add_to_dense_vector ops: cputime %fs walltime %fs\n",
362 for (int32_t r=0; r<repeats; r++)
365 #ifdef DEBUG_DOTFEATURES
369 for (int32_t r=0; r<repeats; r++)
372 for (int32_t i=0; i<num; i++)
373 out2[i]+=
dense_dot(i, w, d)*alphas[i]+23;
376 for (int32_t i=0; i<num; i++)
380 SG_PRINT(
"Time to process %d x num=%d dense_dot_range ops: cputime %fs walltime %fs\n",
399 for (
int i = 0; i < num; i++)
401 for (
int j = 0; j < dim; j++)
420 for (
int i = 0; i < num; i++)
424 for (
int m = 0; m < v.
vlen; m++)
426 for (
int n = 0; n <= m ; n++)
433 for (
int m = 0; m < dim; m++)
435 for (
int n = 0; n <= m ; n++)
437 (cov.
matrix)[m*dim+n] /= num;
440 for (
int m = 0; m < dim-1; m++)
442 for (
int n = m+1; n < dim; n++)
453 int32_t num_vectors=stop-start;
456 if ( (i% (num_vectors/100+1))== 0)
460 void CDotFeatures::init()
464 "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)
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)
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()
void add(bool *param, const char *name, const char *description="")
virtual void free_vector()
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)
virtual void destroy_vector()
A File access base class.
void benchmark_add_to_dense_vector(int32_t repeats=5)
static void display_vector(const T *vector, int32_t n, const char *name="vector")
display vector (useful for debugging)
static bool cancel_computations()
The class Features is the base class of all feature objects.
static void fill_vector(T *vec, int32_t len, T value)
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()
static void range_fill_vector(T *vec, int32_t len, T start=0)
#define SG_MALLOC(type, len)
static void * dense_dot_range_helper(void *p)
virtual SGMatrix< float64_t > get_cov()