11 #ifndef DENSESUBSETFEATURES_H__
12 #define DENSESUBSETFEATURES_H__
22 template<
class ST>
class CDenseFeatures;
23 template<
class ST>
class SGVector;
35 :m_fea(fea), m_idx(idx) {
SG_REF(m_fea); set_generic<ST>(); }
41 virtual const char*
get_name()
const {
return "DenseSubsetFeatures"; }
76 return m_fea->get_feature_type();
87 return m_fea->get_feature_class();
98 return m_fea->get_num_vectors();
124 SG_ERROR(
"Require DenseSubsetFeatures of the same kind to perform dot\n")
127 SG_ERROR(
"Cannot dot vectors of different length\n")
129 SGVector<ST> vec1 = m_fea->get_feature_vector(vec_idx1);
130 SGVector<ST> vec2 = dsf->m_fea->get_feature_vector(vec_idx2);
133 for (int32_t i=0; i < m_idx.
vlen; ++i)
134 sum += vec1[m_idx[i]] * vec2[dsf->m_idx[i]];
147 if (m_idx.
vlen != vec2_len)
148 SG_ERROR(
"Cannot dot vectors of different length\n")
149 SGVector<ST> vec1 = m_fea->get_feature_vector(vec_idx1);
152 for (int32_t i=0; i < vec2_len; ++i)
153 sum += vec1[m_idx[i]] * vec2[i];
168 if (m_idx.
vlen != vec2_len)
169 SG_ERROR(
"Cannot add_to_dense_vec vectors of different length\n")
171 SGVector<ST> vec1 = m_fea->get_feature_vector(vec_idx1);
174 for (int32_t i=0; i < vec2_len; ++i)
175 vec2[i] += alpha *
CMath::abs(vec1[m_idx[i]]);
179 for (int32_t i=0; i < vec2_len; ++i)
180 vec2[i] += alpha * vec1[m_idx[i]];
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 void free_feature_iterator(void *iterator)
#define SG_NOTIMPLEMENTED
virtual int32_t get_dim_feature_space() const
Features that support dot products among other operations.
EFeatureClass
shogun feature class
void set_subset_idx(SGVector< int32_t > idx)
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 ~CDenseSubsetFeatures()
virtual int32_t get_nnz_features_for_vector(int32_t num)
virtual EFeatureClass get_feature_class() const
virtual void * get_feature_iterator(int32_t vector_index)
virtual float64_t dot(int32_t vec_idx1, CDotFeatures *df, int32_t vec_idx2)
EFeatureType
shogun feature type
virtual bool get_next_feature(int32_t &index, float64_t &value, void *iterator)
all of classes and functions are contained in the shogun namespace
The class Features is the base class of all feature objects.
virtual int32_t get_num_vectors() const
virtual const char * get_name() const
virtual EFeatureType get_feature_type() const
CDenseSubsetFeatures(CDenseFeatures< ST > *fea, SGVector< int32_t > idx)
void set_features(CDenseFeatures< ST > *fea)
virtual CFeatures * duplicate() const