30 #ifndef DOXYGEN_SHOULD_SKIP_THIS
31 struct S_THREAD_PARAM_WD
46 #endif // DOXYGEN_SHOULD_SKIP_THIS
118 SG_DEBUG(
"deleting CWeightedDegreeStringKernel optimization\n")
142 int32_t lhs_changed=(
lhs!=l);
143 int32_t rhs_changed=(
rhs!=r);
147 SG_DEBUG(
"lhs_changed: %i\n", lhs_changed)
148 SG_DEBUG(
"rhs_changed: %i\n", rhs_changed)
155 SG_ERROR(
"All strings in WD kernel must have same length (lhs wrong)!\n")
158 SG_ERROR(
"All strings in WD kernel must have same length (rhs wrong)!\n")
184 SG_DEBUG(
"deleting CWeightedDegreeStringKernel optimization\n")
209 SG_DEBUG(
"deleting CWeightedDegreeStringKernel optimization\n")
214 SG_DEBUG(
"initializing CWeightedDegreeStringKernel optimization\n")
216 for (int32_t i=0; i<count; i++)
220 if ( (i % (count/10+1)) == 0)
263 char* avec, int32_t alen,
char* bvec, int32_t blen)
267 for (int32_t i=0; i<alen; i++)
270 int32_t mismatches=0;
272 for (int32_t j=0; (i+j<alen) && (j<
degree); j++)
274 if (avec[i+j]!=bvec[i+j])
291 char* avec, int32_t alen,
char* bvec, int32_t blen)
296 int32_t match_len=-1;
298 for (int32_t i=0; i<alen; i++)
300 if (avec[i]==bvec[i])
317 char* avec, int32_t alen,
char* bvec, int32_t blen)
321 for (int32_t i=0; i<alen; i++)
325 for (int32_t j=0; (i+j<alen) && (j<
degree); j++)
327 if (avec[i+j]!=bvec[i+j])
340 char* avec, int32_t alen,
char* bvec, int32_t blen)
344 for (int32_t i=0; i<alen; i++)
347 for (int32_t j=0; (i+j<alen) && (j<
degree); j++)
349 if (avec[i+j]!=bvec[i+j])
366 bool free_avec, free_bvec;
399 int32_t *vec=SG_MALLOC(int32_t, len);
401 for (int32_t i=0; i<len; i++)
407 for (int32_t i=0; i<len; i++)
420 for (int32_t i=0; i<len; i++)
436 int32_t idx,
float64_t alpha, int32_t tree_num)
445 int32_t *vec = SG_MALLOC(int32_t, len);
447 for (int32_t i=tree_num; i<tree_num+
degree && i<len; i++)
470 int32_t *vec = SG_MALLOC(int32_t, len);
472 for (int32_t i=0; i<len; i++)
476 for (int32_t i=0; i<len; i++)
487 int32_t idx,
float64_t alpha, int32_t tree_num)
496 int32_t *vec=SG_MALLOC(int32_t, len);
498 for (int32_t i=tree_num; i<len && i<tree_num+
degree; i++)
523 int32_t *vec=SG_MALLOC(int32_t, len);
525 for (int32_t i=0; i<len; i++)
531 for (int32_t i=0; i<len; i++)
548 int32_t *vec = SG_MALLOC(int32_t, len);
550 for (int32_t i=0; i<len; i++)
555 for (int32_t i=0; i<len; i++)
631 SG_ERROR(
"WD: Dimension mismatch (should be (seq_length | 1) x degree) got (%d x %d)\n", len,
degree)
648 for (int32_t i=0; i<
degree*len; i++)
676 for (int32_t i=0; i<len; i++)
751 for (int32_t i=1; i<
degree+1 ; i++)
754 for (int32_t i=degree+1; i<
seq_length+1 ; i++)
765 for (int32_t i=1; i<
degree+1 ; i++)
768 for (int32_t i=degree+1; i<
seq_length+1 ; i++)
778 for (int32_t i=1; i<
degree+1 ; i++)
781 for (int32_t i=degree+1; i<
seq_length+1 ; i++)
792 for (int32_t i=1; i<
degree+1 ; i++)
795 for (int32_t i=degree+1; i<
seq_length+1 ; i++)
828 S_THREAD_PARAM_WD* params = (S_THREAD_PARAM_WD*) p;
833 int32_t
length=params->length;
834 int32_t* vec=params->vec;
837 int32_t* vec_idx=params->vec_idx;
842 for (int32_t i=params->start; i<params->end; i++)
863 int32_t num_vec, int32_t* vec_idx,
float64_t* result, int32_t num_suppvec,
870 ASSERT(num_vec<=rhs->get_num_vectors())
880 int32_t* vec=SG_MALLOC(int32_t, num_threads*num_feat);
885 for (int32_t j=0; j<num_feat; j++)
892 S_THREAD_PARAM_WD params;
894 params.result=result;
898 params.factor=factor;
903 params.vec_idx=vec_idx;
916 pthread_t* threads = SG_MALLOC(pthread_t, num_threads-1);
917 S_THREAD_PARAM_WD* params = SG_MALLOC(S_THREAD_PARAM_WD, num_threads);
918 int32_t step= num_vec/num_threads;
921 for (t=0; t<num_threads-1; t++)
923 params[t].vec=&vec[num_feat*t];
924 params[t].result=result;
926 params[t].kernel=
this;
927 params[t].tries=
tries;
928 params[t].factor=factor;
930 params[t].start = t*step;
931 params[t].end = (t+1)*step;
933 params[t].vec_idx=vec_idx;
936 params[t].vec=&vec[num_feat*t];
937 params[t].result=result;
939 params[t].kernel=
this;
940 params[t].tries=
tries;
941 params[t].factor=factor;
943 params[t].start=t*step;
944 params[t].end=num_vec;
946 params[t].vec_idx=vec_idx;
949 for (t=0; t<num_threads-1; t++)
950 pthread_join(threads[t], NULL);
973 if (
lhs!=NULL &&
rhs!=NULL)
979 void CWeightedDegreeStringKernel::init()
1013 "weights",
"WD Kernel weights.");
1016 "Weights per position.");
1026 "The selected degree. All degrees are used by default (for value -1).",
float64_t * block_weights
virtual int32_t get_max_vector_length()
float64_t compute_with_mismatch(char *avec, int32_t alen, char *bvec, int32_t blen)
SGVector< ST > get_feature_vector(int32_t num)
void delete_trees(bool p_use_compact_terminal_nodes=true)
void create_empty_tries()
void add_example_to_tree_mismatch_recursion(int32_t tree, int32_t i, float64_t alpha, int32_t *vec, int32_t len_rem, int32_t degree_rec, int32_t mismatch_rec, int32_t max_mismatch, float64_t *weights)
void add_example_to_single_tree(int32_t idx, float64_t weight, int32_t tree_num)
bool init_block_weights_exp()
int32_t get_num_threads() const
bool init_block_weights_log()
float64_t compute_using_block(char *avec, int32_t alen, char *bvec, int32_t blen)
bool set_max_mismatch(int32_t max)
int32_t position_weights_len
friend class CFirstElementKernelNormalizer
EAlphabet get_alphabet() const
virtual ~CWeightedDegreeStringKernel()
virtual float64_t normalize_rhs(float64_t value, int32_t idx_rhs)=0
void add_example_to_single_tree_mismatch(int32_t idx, float64_t weight, int32_t tree_num)
void set_is_initialized(bool p_init)
The class Alphabet implements an alphabet and alphabet utility functions.
virtual void remove_lhs()
void free_feature_vector(ST *feat_vec, int32_t num, bool dofree)
bool set_position_weights(float64_t *pws, int32_t len)
virtual bool set_normalizer(CKernelNormalizer *normalizer_)
uint8_t remap_to_bin(uint8_t c)
float64_t compute_by_tree_helper(int32_t *vec, int32_t len, int32_t seq_pos, int32_t tree_pos, int32_t weight_pos, float64_t *weights, bool degree_times_position_weights)
virtual void compute_batch(int32_t num_vec, int32_t *vec_idx, float64_t *target, int32_t num_suppvec, int32_t *IDX, float64_t *alphas, float64_t factor=1.0)
float64_t * weights_buffer
bool get_is_initialized()
static void * compute_batch_helper(void *p)
void set_position_weights(float64_t *p_position_weights)
CWeightedDegreeStringKernel()
Class SGObject is the base class of all shogun objects.
bool set_wd_weights_by_type(EWDKernType type)
virtual bool init_optimization(int32_t count, int32_t *IDX, float64_t *alphas)
float64_t * position_weights
static void clear_cancel()
float64_t compute_without_mismatch(char *avec, int32_t alen, char *bvec, int32_t blen)
bool init_block_weights_from_wd()
void create(int32_t len, bool p_use_compact_terminal_nodes=true)
void compute_by_tree(int32_t idx, float64_t *LevelContrib)
The Weighted Degree String kernel.
float64_t compute_without_mismatch_matrix(char *avec, int32_t alen, char *bvec, int32_t blen)
virtual bool init(CFeatures *l, CFeatures *r)
CAlphabet * get_alphabet()
virtual bool delete_optimization()
static bool cancel_computations()
bool init_block_weights_const()
virtual bool init_normalizer()
bool have_same_length(int32_t len=-1)
CFeatures * rhs
feature vectors to occur on right hand side
static int64_t nchoosek(int32_t n, int32_t k)
void add_vector(bool **param, index_t *length, const char *name, const char *description="")
all of classes and functions are contained in the shogun namespace
float64_t * compute_abs_weights(int32_t &len)
void add_to_trie(int32_t i, int32_t seq_offset, int32_t *vec, float32_t alpha, float64_t *weights, bool degree_times_position_weights)
CFeatures * lhs
feature vectors to occur on left hand side
The class Features is the base class of all feature objects.
void add_example_to_tree(int32_t idx, float64_t weight)
static float64_t log(float64_t v)
virtual void remove_lhs()
bool init_block_weights_sqpoly()
float64_t compute(int32_t idx_a, int32_t idx_b)
bool init_block_weights_from_wd_external()
CKernelNormalizer * normalizer
Matrix::Scalar max(Matrix m)
float64_t * compute_abs_weights(int32_t &len)
bool init_block_weights_linear()
bool init_block_weights()
virtual float64_t normalize_lhs(float64_t value, int32_t idx_lhs)=0
void add_matrix(bool **param, index_t *length_y, index_t *length_x, const char *name, const char *description="")
Template class StringKernel, is the base class of all String Kernels.
void add_example_to_tree_mismatch(int32_t idx, float64_t weight)
int32_t get_degree() const
bool set_weights(SGMatrix< float64_t > new_weights)
bool init_block_weights_cubicpoly()
static int32_t pow(bool x, int32_t n)