From b1f473e77d155fca0b322e314678e371c93f46c6 Mon Sep 17 00:00:00 2001 From: Wuwei Lin Date: Tue, 15 May 2018 23:07:31 +0800 Subject: [PATCH] Cleanup preprocessors --- src/shogun/preprocessor/DecompressString.cpp | 4 ++-- src/shogun/preprocessor/DependenceMaximization.h | 7 ------- src/shogun/preprocessor/PruneVarSubMean.cpp | 10 ++++++---- src/shogun/preprocessor/SortWordString.cpp | 4 ++-- 4 files changed, 10 insertions(+), 15 deletions(-) diff --git a/src/shogun/preprocessor/DecompressString.cpp b/src/shogun/preprocessor/DecompressString.cpp index 9292de9fd1a..815c574160a 100644 --- a/src/shogun/preprocessor/DecompressString.cpp +++ b/src/shogun/preprocessor/DecompressString.cpp @@ -56,9 +56,9 @@ bool CDecompressString::apply_to_string_features(CFeatures* f) { int32_t len=0; bool free_vec; - ST* vec = sf->get_feature_vector(i, len, free_vec); + auto vec = sf->get_feature_vector(i, len, free_vec); - ST* decompressed=apply_to_string(vec, len); + auto decompressed=apply_to_string(vec, len); sf->free_feature_vector(vec, i, free_vec); sf->cleanup_feature_vector(i); sf->set_feature_vector(i, decompressed, len); diff --git a/src/shogun/preprocessor/DependenceMaximization.h b/src/shogun/preprocessor/DependenceMaximization.h index 1bb57ac9070..d01d6121a2c 100644 --- a/src/shogun/preprocessor/DependenceMaximization.h +++ b/src/shogun/preprocessor/DependenceMaximization.h @@ -114,13 +114,6 @@ class CDependenceMaximization : public CFeatureSelection */ virtual void set_algorithm(EFeatureSelectionAlgorithm algorithm)=0; - /** - * Fit preprocessor into features - * - * @param features the features - */ - virtual void fit(CFeatures* features); - /** * Setter for labels. This method is overridden to internally convert the * labels to a dense feature object and set this feature in the diff --git a/src/shogun/preprocessor/PruneVarSubMean.cpp b/src/shogun/preprocessor/PruneVarSubMean.cpp index 524a5f0e9d0..14518880c3f 100644 --- a/src/shogun/preprocessor/PruneVarSubMean.cpp +++ b/src/shogun/preprocessor/PruneVarSubMean.cpp @@ -106,7 +106,9 @@ SGMatrix CPruneVarSubMean::apply_to_feature_matrix(CFeatures* feature int32_t num_vectors=0; int32_t num_features=0; - float64_t* m=((CDenseFeatures*) features)->get_feature_matrix(num_features, num_vectors); + + auto simple_features = features->as>(); + auto m = simple_features->get_feature_matrix(); SG_INFO("get Feature matrix: %ix%i\n", num_vectors, num_features) SG_INFO("Preprocessing feature matrix\n") @@ -127,11 +129,11 @@ SGMatrix CPruneVarSubMean::apply_to_feature_matrix(CFeatures* feature } } - ((CDenseFeatures*) features)->set_num_features(m_num_idx); - ((CDenseFeatures*) features)->get_feature_matrix(num_features, num_vectors); + simple_features->set_num_features(m_num_idx); + simple_features->get_feature_matrix(num_features, num_vectors); SG_INFO("new Feature matrix: %ix%i\n", num_vectors, num_features) - return ((CDenseFeatures*) features)->get_feature_matrix(); + return simple_features->get_feature_matrix(); } /// apply preproc on single feature vector diff --git a/src/shogun/preprocessor/SortWordString.cpp b/src/shogun/preprocessor/SortWordString.cpp index bf83b444fa5..53484cef916 100644 --- a/src/shogun/preprocessor/SortWordString.cpp +++ b/src/shogun/preprocessor/SortWordString.cpp @@ -48,13 +48,13 @@ bool CSortWordString::apply_to_string_features(CFeatures* f) { int32_t i; auto sf = f->as>(); - int32_t num_vec = sf->get_num_vectors(); + auto num_vec = sf->get_num_vectors(); for (i=0; iget_feature_vector(i, len, free_vec); + auto vec = sf->get_feature_vector(i, len, free_vec); ASSERT(!free_vec) // won't work with non-in-memory string features //CMath::qsort(vec, len);