From 2e405b1a2153ad4ae7543eb14899228d3f10acb0 Mon Sep 17 00:00:00 2001 From: Wuwei Lin Date: Fri, 18 May 2018 22:00:17 +0800 Subject: [PATCH] Remove DimensionReductionPreprocessor --- .../DimensionReductionPreprocessor.cpp | 114 ---------------- .../DimensionReductionPreprocessor.h | 122 ------------------ 2 files changed, 236 deletions(-) delete mode 100644 src/shogun/preprocessor/DimensionReductionPreprocessor.cpp delete mode 100644 src/shogun/preprocessor/DimensionReductionPreprocessor.h diff --git a/src/shogun/preprocessor/DimensionReductionPreprocessor.cpp b/src/shogun/preprocessor/DimensionReductionPreprocessor.cpp deleted file mode 100644 index 332d8eeb595..00000000000 --- a/src/shogun/preprocessor/DimensionReductionPreprocessor.cpp +++ /dev/null @@ -1,114 +0,0 @@ -#include -#include -#include -#include - -using namespace shogun; - -namespace shogun -{ -CDimensionReductionPreprocessor::CDimensionReductionPreprocessor() -: CDensePreprocessor() -{ - m_target_dim = 1; - m_distance = new CEuclideanDistance(); - m_kernel = new CLinearKernel(); - m_converter = NULL; - - initialize_parameters(); -} - -CDimensionReductionPreprocessor::CDimensionReductionPreprocessor(CEmbeddingConverter* converter) -: CDensePreprocessor() -{ - SG_REF(converter); - m_target_dim = 1; - m_distance = new CEuclideanDistance(); - m_kernel = new CLinearKernel(); - m_converter = converter; - - initialize_parameters(); -} - -CDimensionReductionPreprocessor::~CDimensionReductionPreprocessor() -{ - SG_UNREF(m_distance); - SG_UNREF(m_kernel); - SG_UNREF(m_converter); -} - -SGMatrix CDimensionReductionPreprocessor::apply_to_feature_matrix(CFeatures* features) -{ - if (m_converter) - { - m_converter->set_target_dim(m_target_dim); - CDenseFeatures* embedding = m_converter->embed(features); - SGMatrix embedding_feature_matrix = - embedding->get_feature_matrix(); - ((CDenseFeatures*)features)->set_feature_matrix(embedding_feature_matrix); - delete embedding; - return embedding_feature_matrix; - } - else - { - SG_WARNING("Converter to process was not set.\n") - return features->as>()->get_feature_matrix(); - } -} - -void CDimensionReductionPreprocessor::cleanup() -{ - -} - -EPreprocessorType CDimensionReductionPreprocessor::get_type() const { return P_DIMENSIONREDUCTIONPREPROCESSOR; }; - -void CDimensionReductionPreprocessor::set_target_dim(int32_t dim) -{ - ASSERT(dim>0) - m_target_dim = dim; -} - -int32_t CDimensionReductionPreprocessor::get_target_dim() const -{ - return m_target_dim; -} - -void CDimensionReductionPreprocessor::set_distance(CDistance* distance) -{ - SG_REF(distance); - SG_UNREF(m_distance); - m_distance = distance; -} - -CDistance* CDimensionReductionPreprocessor::get_distance() const -{ - SG_REF(m_distance); - return m_distance; -} - -void CDimensionReductionPreprocessor::set_kernel(CKernel* kernel) -{ - SG_REF(kernel); - SG_UNREF(m_kernel); - m_kernel = kernel; -} - -CKernel* CDimensionReductionPreprocessor::get_kernel() const -{ - SG_REF(m_kernel); - return m_kernel; -} - -void CDimensionReductionPreprocessor::initialize_parameters() -{ - SG_ADD((CSGObject**)&m_converter, "converter", - "embedding converter used to apply to data", MS_AVAILABLE); - SG_ADD(&m_target_dim, "target_dim", - "target dimensionality of preprocessor", MS_AVAILABLE); - SG_ADD((CSGObject**)&m_distance, "distance", - "distance to be used for embedding", MS_AVAILABLE); - SG_ADD((CSGObject**)&m_kernel, "kernel", - "kernel to be used for embedding", MS_AVAILABLE); -} -} diff --git a/src/shogun/preprocessor/DimensionReductionPreprocessor.h b/src/shogun/preprocessor/DimensionReductionPreprocessor.h deleted file mode 100644 index a6e453d3400..00000000000 --- a/src/shogun/preprocessor/DimensionReductionPreprocessor.h +++ /dev/null @@ -1,122 +0,0 @@ -/* - * This software is distributed under BSD 3-clause license (see LICENSE file). - * - * Authors: Sergey Lisitsyn, Soeren Sonnenburg, Evgeniy Andreev, Evan Shelhamer, - * Yuyu Zhang, Elijah Rippeth - */ - -#ifndef DIMENSIONREDUCTIONPREPROCESSOR_H_ -#define DIMENSIONREDUCTIONPREPROCESSOR_H_ - -#include - -#include -#include -#include -#include - -namespace shogun -{ - -class CFeatures; -class CDistance; -class CKernel; - -/** @brief the class DimensionReductionPreprocessor, a base - * class for preprocessors used to lower the dimensionality of given - * simple features (dense matrices). - */ -class CDimensionReductionPreprocessor: public CDensePreprocessor -{ -public: - - /** default constructor */ - CDimensionReductionPreprocessor(); - - /** convenience constructor converting any embeddingconverter into a - * dimensionreduction preprocessor - * - * @param converter embedding converter - */ - CDimensionReductionPreprocessor(CEmbeddingConverter* converter); - - /** destructor */ - virtual ~CDimensionReductionPreprocessor(); - - /** cleanup - * set empty by default, should be defined if dimension reduction - * preprocessor should free some resources - */ - virtual void cleanup(); - - /** apply preproc to feature matrix - * by default does nothing, returns given features' matrix - */ - virtual SGMatrix apply_to_feature_matrix(CFeatures* features); - - /** apply preproc to feature vector - * by default does nothing, returns given feature vector - */ - virtual SGVector apply_to_feature_vector(SGVector vector) - { - return vector; - } - - /** get name */ - virtual const char* get_name() const { return "DimensionReductionPreprocessor"; }; - - /** get type */ - virtual EPreprocessorType get_type() const; - - /** setter for target dimension - * @param dim target dimension - */ - void set_target_dim(int32_t dim); - - /** getter for target dimension - * @return target dimension - */ - int32_t get_target_dim() const; - - /** setter for distance - * @param distance distance to set - */ - void set_distance(CDistance* distance); - - /** getter for distance - * @return distance - */ - CDistance* get_distance() const; - - /** setter for kernel - * @param kernel kernel to set - */ - void set_kernel(CKernel* kernel); - - /** getter for kernel - * @return kernel - */ - CKernel* get_kernel() const; - -private: - - /** default init */ - void initialize_parameters(); - -protected: - - /** target dim of dimensionality reduction preprocessor */ - int32_t m_target_dim; - - /** distance to be used */ - CDistance* m_distance; - - /** kernel to be used */ - CKernel* m_kernel; - - /** embedding converter to be used */ - CEmbeddingConverter* m_converter; -}; -} - -#endif /* DIMENSIONREDUCTIONPREPROCESSOR_H_ */