23 SG_DEBUG(
"CManhattanWordDistance created")
30 SG_DEBUG(
"CManhattanWordDistance created")
53 bool free_avec, free_bvec;
56 get_feature_vector(idx_a, alen, free_avec);
58 get_feature_vector(idx_b, blen, free_bvec);
65 while (left_idx < alen && right_idx < blen)
67 uint16_t sym=avec[left_idx];
68 if (avec[left_idx]==bvec[right_idx])
70 int32_t old_left_idx=left_idx;
71 int32_t old_right_idx=right_idx;
73 while (left_idx< alen && avec[left_idx]==sym)
76 while (right_idx< blen && bvec[right_idx]==sym)
79 result +=
CMath::abs( (left_idx-old_left_idx) - (right_idx-old_right_idx) );
81 else if (avec[left_idx]<bvec[right_idx])
84 while (left_idx< alen && avec[left_idx]==sym)
94 while (right_idx< blen && bvec[right_idx]==sym)
102 result+=blen-right_idx + alen-left_idx;
105 free_feature_vector(avec, idx_a, free_avec);
107 free_feature_vector(bvec, idx_b, free_bvec);
virtual ~CManhattanWordDistance()
virtual bool init(CFeatures *l, CFeatures *r)
float64_t compute(int32_t idx_a, int32_t idx_b)
all of classes and functions are contained in the shogun namespace
CFeatures * lhs
feature vectors to occur on the left hand side
The class Features is the base class of all feature objects.
CFeatures * rhs
feature vectors to occur on the right hand side
template class StringDistance