45 initialize_parameters();
51 SG_ADD(&m_target_dim,
"target_dim",
"target dimension",
57 SG_ADD(&m_num_remove,
"num_remove",
"number or percentage of features to "
83 m_subset->remove_all_subsets();
95 index_t num_features=get_num_features(features);
96 SG_DEBUG(
"Initial number of features %d!\n", num_features);
99 while (num_features>m_target_dim)
103 adapt_params(features);
107 for (
index_t i=0; i<num_features; ++i)
108 measures[i]=compute_measures(features, i);
122 to_remove=m_num_remove;
124 to_remove=num_features*m_num_remove*0.01;
126 index_t can_remove=num_features-m_target_dim;
132 index_t orig_remove=m_num_remove;
135 if (to_remove>can_remove)
137 m_num_remove=can_remove;
138 SG_DEBUG(
"Can only remove %d features in this iteration!\n",
150 features=remove_feats(features, argsorted);
154 if (to_remove>can_remove)
156 m_policy=orig_policy;
157 m_num_remove=orig_remove;
161 num_features=get_num_features(features);
162 SG_DEBUG(
"Current number of features %d!\n", num_features);
166 ASSERT(m_subset->get_size()==m_target_dim);
178 m_subset->remove_all_subsets();
181 REQUIRE(features,
"Features cannot be NULL!\n");
183 "Number of feature vectors has to be positive!\n");
184 REQUIRE(m_target_dim>0,
"Target dimension (%d) has to be positive! Set "
185 "a higher number via set_target_dim().\n", m_target_dim);
187 index_t num_features=get_num_features(features);
188 REQUIRE(num_features>0,
"Invalid number of features (%d)! Most likely "
189 "feature selection cannot be performed for %s!\n",
190 num_features, features->
get_name());
191 REQUIRE(num_features>m_target_dim,
192 "Number of original features (dimensions of the feature vectors) "
193 "(%d) has to be greater that the target dimension (%d)!\n",
194 num_features, m_target_dim);
204 return apply_backward_elimination(feats_copy);
206 SG_ERROR(
"Specified algorithm not yet supported!\n");
229 if (m_subset->has_subsets())
233 inds[i]=m_subset->subset_idx_conversion(i);
243 REQUIRE(features,
"Features not initialized!\n");
252 REQUIRE(d_feats,
"Type mismatch for dense features!\n");
258 REQUIRE(s_feats,
"Type mismatch for sparse features!\n");
262 SG_ERROR(
"Number of features not available for %s!\n",
273 m_target_dim=target_dim;
297 m_num_remove=num_remove;
virtual const char * get_name() const =0
virtual void adapt_params(CFeatures *features)
The class DenseFeatures implements dense feature matrices.
int32_t get_num_features() const
SGVector< index_t > get_selected_feats()
The class Labels models labels, i.e. class assignments of objects.
virtual CSGObject * clone()
Template class SparseFeatures implements sparse matrices.
virtual int32_t get_num_vectors() const =0
virtual EPreprocessorType get_type() const
EFeatureClass
shogun feature class
class to add subset support to another class. A CSubsetStackStack instance should be added and wrappe...
Template class CFeatureSelection, base class for all feature selection preprocessors which select a s...
static void qsort(T *output, int32_t size)
void display_vector(const char *name="vector", const char *prefix="") const
void set_num_remove(index_t num_remove)
EFeatureSelectionAlgorithm get_algorithm() const
virtual void set_labels(CLabels *labels)
virtual CFeatures * apply_backward_elimination(CFeatures *features)
Class SGObject is the base class of all shogun objects.
int32_t get_num_features() const
virtual void precompute()
EFeatureRemovalPolicy get_policy() const
static SGVector< index_t > argsort(SGVector< T > vector)
virtual EFeatureClass get_feature_class()
virtual EFeatureClass get_feature_class() const =0
EFeatureType
shogun feature type
virtual EFeatureType get_feature_type()
all of classes and functions are contained in the shogun namespace
index_t get_num_features(CFeatures *features) const
The class Features is the base class of all feature objects.
EFeatureSelectionAlgorithm
Class Preprocessor defines a preprocessor interface.
void set_target_dim(index_t target_dim)
virtual ~CFeatureSelection()
virtual CFeatures * apply(CFeatures *features)
index_t get_num_remove() const
CLabels * get_labels() const
index_t get_target_dim() const