void CStreamingSparseFeatures<T>::expand_if_required(float64_t*& vec, int32_t &len) { int32_t dim = get_dim_feature_space(); if (dim > len) { vec = SG_REALLOC(float64_t, vec, len, dim); memset(&vec[len], 0, (dim-len) * sizeof(float64_t)); len = dim; } }
float64_t CRandomKitchenSinksDotFeatures::dense_dot( int32_t vec_idx1, const float64_t* vec2, int32_t vec2_len) { SG_DEBUG("entering dense_dot()\n"); ASSERT(vec2_len == get_dim_feature_space()); float64_t dot_product = 0; for (index_t i=0; i<num_samples; i++) { float64_t tmp_dot = dot(vec_idx1, i); tmp_dot = post_dot(tmp_dot, i); dot_product += tmp_dot * vec2[i]; } SG_DEBUG("Leaving dense_dot()\n"); return dot_product; }
void CRandomKitchenSinksDotFeatures::add_to_dense_vec(float64_t alpha, int32_t vec_idx1, float64_t* vec2, int32_t vec2_len, bool abs_val) { SG_DEBUG("Entering add_to_dense()\n"); ASSERT(vec2_len == get_dim_feature_space()); for (index_t i=0; i<num_samples; i++) { float64_t tmp_dot = dot(vec_idx1, i); tmp_dot = post_dot(tmp_dot, i); if (abs_val) vec2[i] += CMath::abs(alpha * tmp_dot); else vec2[i] += alpha * tmp_dot; } SG_DEBUG("Leaving add_to_dense()\n"); }
float64_t CRandomKitchenSinksDotFeatures::dot(int32_t vec_idx1, CDotFeatures* df, int32_t vec_idx2) { ASSERT(typeid(*this) == typeid(*df)); CRandomKitchenSinksDotFeatures* other = (CRandomKitchenSinksDotFeatures* ) df; ASSERT(get_dim_feature_space()==other->get_dim_feature_space()); float64_t dot_product = 0; for (index_t i=0; i<num_samples; i++) { float64_t tmp_dot_1 = dot(vec_idx1, i); float64_t tmp_dot_2 = other->dot(vec_idx2, i); tmp_dot_1 = post_dot(tmp_dot_1, i); tmp_dot_2 = other->post_dot(tmp_dot_2, i); dot_product += tmp_dot_1 * tmp_dot_2; } return dot_product; }