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);
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;