28 init(NULL, 0, use_quadr, keep_lin_terms);
35 init(feats, d, use_quadr, keep_lin_terms);
43 init(feats, d, use_quadr, keep_lin_terms);
48 int32_t d,
bool use_quadr,
bool keep_lin_terms) :
CDotFeatures()
51 init(feats, d, use_quadr, keep_lin_terms);
60 init(feats, d, use_quadr, keep_lin_terms);
70 use_quadratic = use_quadr;
71 keep_linear_terms = keep_lin_terms;
73 SG_ADD(&use_quadratic,
"use_quadratic",
"Whether to use quadratic features",
75 SG_ADD(&keep_linear_terms,
"keep_linear_terms",
"Whether to keep the linear terms or not",
78 SG_ADD((
CSGObject** ) &dense_feats,
"dense_feats",
"Dense features to work on",
123 bool same_vec = (df ==
this) && (vec_idx1 == vec_idx2);
136 SGVector<ST> vec = dense_feats->get_feature_vector(vec_idx1);
140 int32_t hash_cache_size = use_quadratic ? vec.
vlen : 0;
147 hash_cache[i] = h_idx;
149 if ( (!use_quadratic) || keep_linear_terms)
150 result += vec2[h_idx % dim] * vec[i];
157 int32_t n_idx = i * vec.
size() + i;
159 result += vec2[idx] * vec[i] * vec[i];
161 for (
index_t j=i+1; j<vec.size(); j++)
163 idx = (hash_cache[i] ^ hash_cache[j]) % dim;
164 result += vec2[idx] * vec[i] * vec[j];
169 dense_feats->free_feature_vector(vec, vec_idx1);
175 float64_t* vec2, int32_t vec2_len,
bool abs_val)
180 SGVector<ST> vec = dense_feats->get_feature_vector(vec_idx1);
182 int32_t hash_cache_size = use_quadratic ? vec.
vlen : 0;
190 hash_cache[i] = h_idx;
192 if ( (!use_quadratic) || keep_linear_terms)
193 vec2[h_idx % dim] += val * vec[i];
200 int32_t n_idx = i * vec.
size() + i;
202 vec2[idx] += val * vec[i] * vec[i];
204 for (
index_t j=i+1; j<vec.size(); j++)
206 idx = (hash_cache[i] ^ hash_cache[j]) % dim;
207 vec2[idx] += val * vec[i] * vec[j];
211 dense_feats->free_feature_vector(vec, vec_idx1);
242 return "HashedDenseFeatures";
260 return dense_feats->get_num_vectors();
266 SGVector<ST> vec = dense_feats->get_feature_vector(vec_idx);
268 vec, dim, use_quadratic, keep_linear_terms);
269 dense_feats->free_feature_vector(vec, vec_idx);
275 bool use_quadratic,
bool keep_linear_terms)
280 int32_t hash_cache_size = use_quadratic ? vec.
vlen : 0;
287 hash_cache[i] = hash;
289 if ( (!use_quadratic) || keep_linear_terms)
290 h_vec[hash % dim] += vec[i];
299 h_vec[idx] += vec[i] * vec[i];
301 for (
index_t j=i+1; j<vec.size(); j++)
303 idx = (hash_cache[i] ^ hash_cache[j]) % dim;
304 h_vec[idx] += vec[i] * vec[j];
309 int32_t num_nnz_feats = 0;
318 int32_t sparse_feat_index = 0;
324 hashed_vector.
features[sparse_feat_index++].
entry = h_vec[i];
328 return hashed_vector;
virtual const char * get_name() const =0
CDenseFeatures< ST > * dense_feats
static void fill_vector(T *vec, int32_t len, T value)
T sparse_dot(const SGSparseVector< T > &v)
The class DenseFeatures implements dense feature matrices.
virtual void load(CFile *loader)
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)
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
virtual bool get_next_feature(int32_t &index, float64_t &value, void *iterator)
virtual EFeatureClass get_feature_class() const
SGSparseVectorEntry< T > * features
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)
all of classes and functions are contained in the shogun namespace
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 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