25 init(NULL, 0, use_quadr, keep_lin_terms);
32 init(feats, d, use_quadr, keep_lin_terms);
40 init(feats, d, use_quadr, keep_lin_terms);
45 int32_t d,
bool use_quadr,
bool keep_lin_terms) :
CDotFeatures()
48 init(feats, d, use_quadr, keep_lin_terms);
57 init(feats, d, use_quadr, keep_lin_terms);
67 use_quadratic = use_quadr;
68 keep_linear_terms = keep_lin_terms;
70 SG_ADD(&use_quadratic,
"use_quadratic",
"Whether to use quadratic features",
72 SG_ADD(&keep_linear_terms,
"keep_linear_terms",
"Whether to keep the linear terms or not",
75 SG_ADD((
CSGObject** ) &dense_feats,
"dense_feats",
"Dense features to work on",
120 bool same_vec = (df ==
this) && (vec_idx1 == vec_idx2);
122 float64_t result = vec_1.sparse_dot(vec_2);
133 SGVector<ST> vec = dense_feats->get_feature_vector(vec_idx1);
137 int32_t hash_cache_size = use_quadratic ? vec.
vlen : 0;
144 hash_cache[i] = h_idx;
146 if ( (!use_quadratic) || keep_linear_terms)
147 result += vec2[h_idx % dim] * vec[i];
154 int32_t n_idx = i * vec.
size() + i;
156 result += vec2[idx] * vec[i] * vec[i];
158 for (
index_t j=i+1; j<vec.size(); j++)
160 idx = (hash_cache[i] ^ hash_cache[j]) % dim;
161 result += vec2[idx] * vec[i] * vec[j];
166 dense_feats->free_feature_vector(vec, vec_idx1);
172 float64_t* vec2, int32_t vec2_len,
bool abs_val)
177 SGVector<ST> vec = dense_feats->get_feature_vector(vec_idx1);
179 int32_t hash_cache_size = use_quadratic ? vec.
vlen : 0;
187 hash_cache[i] = h_idx;
189 if ( (!use_quadratic) || keep_linear_terms)
190 vec2[h_idx % dim] += val * vec[i];
197 int32_t n_idx = i * vec.
size() + i;
199 vec2[idx] += val * vec[i] * vec[i];
201 for (
index_t j=i+1; j<vec.size(); j++)
203 idx = (hash_cache[i] ^ hash_cache[j]) % dim;
204 vec2[idx] += val * vec[i] * vec[j];
208 dense_feats->free_feature_vector(vec, vec_idx1);
239 return "HashedDenseFeatures";
257 return dense_feats->get_num_vectors();
263 SGVector<ST> vec = dense_feats->get_feature_vector(vec_idx);
265 vec, dim, use_quadratic, keep_linear_terms);
266 dense_feats->free_feature_vector(vec, vec_idx);
272 bool use_quadratic,
bool keep_linear_terms)
277 int32_t hash_cache_size = use_quadratic ? vec.
vlen : 0;
284 hash_cache[i] = hash;
286 if ( (!use_quadratic) || keep_linear_terms)
287 h_vec[hash % dim] += vec[i];
296 h_vec[idx] += vec[i] * vec[i];
298 for (
index_t j=i+1; j<vec.size(); j++)
300 idx = (hash_cache[i] ^ hash_cache[j]) % dim;
301 h_vec[idx] += vec[i] * vec[j];
306 int32_t num_nnz_feats = 0;
315 int32_t sparse_feat_index = 0;
321 hashed_vector.
features[sparse_feat_index++].
entry = h_vec[i];
325 return hashed_vector;
virtual const char * get_name() const =0
CDenseFeatures< ST > * dense_feats
static SGSparseVector< ST > hash_vector(SGVector< ST > vec, int32_t dim, bool use_quadratic=false, bool keep_linear_terms=true)
#define SG_NOTIMPLEMENTED
This class is identical to the CDenseFeatures class except that it hashes each dimension to a new fea...
virtual CFeatures * duplicate() const
Features that support dot products among other operations.
EFeatureClass
shogun feature class
static uint32_t MurmurHash3(uint8_t *data, int32_t len, uint32_t seed)
template class SGSparseVector The assumtion is that the stored SGSparseVectorEntry* vector is orde...
virtual const char * get_name() const
Class SGObject is the base class of all shogun objects.
A File access base class.
SGSparseVector< ST > get_hashed_feature_vector(int32_t vec_idx)
virtual EFeatureClass get_feature_class() const =0
CHashedDenseFeatures(int32_t size=0, bool use_quadr=false, bool keep_lin_terms=true)
virtual int32_t get_num_vectors() const
static void fill_vector(T *vec, int32_t len, T value)
virtual bool get_next_feature(int32_t &index, float64_t &value, void *iterator)
virtual EFeatureClass get_feature_class() const
virtual void free_feature_iterator(void *iterator)
EFeatureType
shogun feature type
virtual float64_t dot(int32_t vec_idx1, CDotFeatures *df, int32_t vec_idx2)
The class DenseFeatures implements dense feature matrices.
virtual float64_t dense_dot(int32_t vec_idx1, const float64_t *vec2, int32_t vec2_len)
virtual int32_t get_dim_feature_space() const
The class Features is the base class of all feature objects.
virtual int32_t get_nnz_features_for_vector(int32_t num)
virtual EFeatureType get_feature_type() const
virtual void load(CFile *loader)
virtual void add_to_dense_vec(float64_t alpha, int32_t vec_idx1, float64_t *vec2, int32_t vec2_len, bool abs_val=false)
virtual ~CHashedDenseFeatures()
virtual void * get_feature_iterator(int32_t vector_index)
virtual EFeatureType get_feature_type() const =0
static T abs(T a)
return the absolute value of a number
SGSparseVectorEntry< T > * features