float32_t CStreamingDenseFeatures<T>::dot(CStreamingDotFeatures* df)
{
	ASSERT(df);
	ASSERT(df->get_feature_type() == get_feature_type());
	ASSERT(df->get_feature_class() == get_feature_class());
	CStreamingDenseFeatures<T>* sf = (CStreamingDenseFeatures<T>*) df;

	SGVector<T> other_vector=sf->get_vector();

	float32_t result = CMath::dot(current_vector, other_vector.vector, current_length);

	return result;
}
float64_t CHashedSparseFeatures<ST>::dot(int32_t vec_idx1, CDotFeatures* df,
        int32_t vec_idx2)
{
    ASSERT(df)
    ASSERT(df->get_feature_type() == get_feature_type())
    ASSERT(df->get_feature_class() == get_feature_class())
    ASSERT(strcmp(df->get_name(), get_name())==0)

    CHashedSparseFeatures<ST>* feats = (CHashedSparseFeatures<ST>* ) df;
    SGSparseVector<ST> vec_1 = get_hashed_feature_vector(vec_idx1);
    SGSparseVector<ST> vec_2 = feats->get_hashed_feature_vector(vec_idx2);

    float64_t result = vec_1.sparse_dot(vec_2);
    return result;
}
Exemple #3
0
template<class ST> CFeatures* CDenseFeatures<ST>::create_merged_copy(
		CFeatures* other)
{
	SG_DEBUG("entering %s::create_merged_copy()\n", get_name());
	if (get_feature_type()!=other->get_feature_type() ||
			get_feature_class()!=other->get_feature_class() ||
			strcmp(get_name(), other->get_name()))
	{
		SG_ERROR("%s::create_merged_copy(): Features are of different type!\n",
				get_name());
	}

	CDenseFeatures<ST>* casted=dynamic_cast<CDenseFeatures<ST>* >(other);

	if (!casted)
	{
		SG_ERROR("%s::create_merged_copy(): Could not cast object of %s to "
				"same type as %s\n",get_name(), other->get_name(), get_name());
	}

	if (num_features!=casted->num_features)
	{
		SG_ERROR("%s::create_merged_copy(): Provided feature object has "
				"different dimension than this one\n");
	}

	/* create new feature matrix and copy both instances data into it */
	SGMatrix<ST> data(num_features, num_vectors+casted->get_num_vectors());

	/* copy data of this instance */
	SG_DEBUG("copying matrix of this instance\n");
	memcpy(data.matrix, feature_matrix.matrix,
			num_features*num_vectors*sizeof(ST));

	/* copy data of provided instance */
	SG_DEBUG("copying matrix of provided instance\n");
	memcpy(&data.matrix[num_vectors*num_features],
			casted->feature_matrix.matrix,
			casted->num_features*casted->num_vectors*sizeof(ST));

	/* create new instance and return */
	CDenseFeatures<ST>* result=new CDenseFeatures<ST>(data);

	SG_DEBUG("leaving %s::create_merged_copy()\n", get_name());
	return result;
}
Exemple #4
0
template<class ST> float64_t CDenseFeatures<ST>::dot(int32_t vec_idx1, CDotFeatures* df,
		int32_t vec_idx2)
{
	ASSERT(df);
	ASSERT(df->get_feature_type() == get_feature_type());
	ASSERT(df->get_feature_class() == get_feature_class());
	CDenseFeatures<ST>* sf = (CDenseFeatures<ST>*) df;

	int32_t len1, len2;
	bool free1, free2;

	ST* vec1 = get_feature_vector(vec_idx1, len1, free1);
	ST* vec2 = sf->get_feature_vector(vec_idx2, len2, free2);

	float64_t result = SGVector<ST>::dot(vec1, vec2, len1);

	free_feature_vector(vec1, vec_idx1, free1);
	sf->free_feature_vector(vec2, vec_idx2, free2);

	return result;
}