From 15a9a2ff1d4828b312a9e2fe4a3774af80aaf8b5 Mon Sep 17 00:00:00 2001 From: Heiko Strathmann Date: Thu, 21 Jul 2011 15:02:06 +0200 Subject: [PATCH 01/12] better assert --- src/shogun/mathematics/Statistics.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/shogun/mathematics/Statistics.cpp b/src/shogun/mathematics/Statistics.cpp index db78e2448f7..52cf2b998a1 100644 --- a/src/shogun/mathematics/Statistics.cpp +++ b/src/shogun/mathematics/Statistics.cpp @@ -20,7 +20,7 @@ using namespace shogun; float64_t CStatistics::mean(SGVector values) { - ASSERT(values.vlen); + ASSERT(values.vlen>0); ASSERT(values.vector); float64_t sum=0; From 4599e80c41597b02d88c81ae9e6eb5b1c03fb771 Mon Sep 17 00:00:00 2001 From: Heiko Strathmann Date: Thu, 21 Jul 2011 15:02:15 +0200 Subject: [PATCH 02/12] fixed compile error --- src/shogun/mathematics/Math.h | 1 + 1 file changed, 1 insertion(+) diff --git a/src/shogun/mathematics/Math.h b/src/shogun/mathematics/Math.h index b4084c580e5..4e62b66ea6a 100644 --- a/src/shogun/mathematics/Math.h +++ b/src/shogun/mathematics/Math.h @@ -873,6 +873,7 @@ class CMath : public CSGObject /** @deprecated use CStatistics::mean() instead */ static inline float64_t mean(float64_t* vec, int32_t len) { + SG_SDEPRECATED; ASSERT(vec); ASSERT(len>0); From 1eb0e2355284abce73ccd74b1d332e78b0e104ff Mon Sep 17 00:00:00 2001 From: Heiko Strathmann Date: Thu, 21 Jul 2011 16:38:57 +0200 Subject: [PATCH 03/12] removed KernelPerceptron --- src/interfaces/modular/Classifier.i | 2 - src/interfaces/modular/Classifier_includes.i | 1 - src/shogun/classifier/KernelPerceptron.cpp | 60 ---------------- src/shogun/classifier/KernelPerceptron.h | 75 -------------------- 4 files changed, 138 deletions(-) delete mode 100644 src/shogun/classifier/KernelPerceptron.cpp delete mode 100644 src/shogun/classifier/KernelPerceptron.h diff --git a/src/interfaces/modular/Classifier.i b/src/interfaces/modular/Classifier.i index 89004d1bcb5..3755a827bc2 100644 --- a/src/interfaces/modular/Classifier.i +++ b/src/interfaces/modular/Classifier.i @@ -21,7 +21,6 @@ %rename(GNPPSVM) CGNPPSVM; %rename(GPBTSVM) CGPBTSVM; %rename(GaussianNaiveBayes) CGaussianNaiveBayes; -%rename(KernelPerceptron) CKernelPerceptron; %rename(KNN) CKNN; %rename(LDA) CLDA; %rename(LibLinear) CLibLinear; @@ -79,7 +78,6 @@ %include %include %include -%include %include %include %include diff --git a/src/interfaces/modular/Classifier_includes.i b/src/interfaces/modular/Classifier_includes.i index fde1033395f..c8700b49e8e 100644 --- a/src/interfaces/modular/Classifier_includes.i +++ b/src/interfaces/modular/Classifier_includes.i @@ -3,7 +3,6 @@ #include #include #include - #include #include #include #include diff --git a/src/shogun/classifier/KernelPerceptron.cpp b/src/shogun/classifier/KernelPerceptron.cpp deleted file mode 100644 index ff2ab261c65..00000000000 --- a/src/shogun/classifier/KernelPerceptron.cpp +++ /dev/null @@ -1,60 +0,0 @@ -/* - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 3 of the License, or - * (at your option) any later version. - * - * Written (W) 1999-2009 Soeren Sonnenburg - * Copyright (C) 1999-2009 Fraunhofer Institute FIRST and Max-Planck-Society - */ - -#include -#include -#include - -using namespace shogun; - -CKernelPerceptron::CKernelPerceptron() -: CKernelMachine() -{ -} - - -CKernelPerceptron::~CKernelPerceptron() -{ -} - -bool CKernelPerceptron::train(CFeatures* data) -{ - ASSERT(labels); - //CLabels* train_labels=labels->get_int_labels(num_train_labels); - -// -//# compute output activation y = f(w x) -//# If y = t, don't change weights -//# If y != t, update the weights: -// -//w(new) = w(old) + 2 m t x - return false; - -} - -bool CKernelPerceptron::load(FILE* srcfile) -{ - SG_SET_LOCALE_C; - SG_RESET_LOCALE; - return false; -} - -bool CKernelPerceptron::save(FILE* dstfile) -{ - SG_SET_LOCALE_C; - SG_RESET_LOCALE; - return false; -} - - -float64_t CKernelPerceptron::classify_example(int32_t num) -{ - return 0; -} diff --git a/src/shogun/classifier/KernelPerceptron.h b/src/shogun/classifier/KernelPerceptron.h deleted file mode 100644 index 355ff016a52..00000000000 --- a/src/shogun/classifier/KernelPerceptron.h +++ /dev/null @@ -1,75 +0,0 @@ -/* - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 3 of the License, or - * (at your option) any later version. - * - * Written (W) 1999-2009 Soeren Sonnenburg - * Copyright (C) 1999-2009 Fraunhofer Institute FIRST and Max-Planck-Society - */ - -#ifndef _KERNELPERCEPTRON_H___ -#define _KERNELPERCEPTRON_H___ - -#include -#include -#include -#include - -namespace shogun -{ -/** @brief Class KernelPerceptron - - * currently unfinished implementation of a Kernel Perceptron - */ -class CKernelPerceptron : public CKernelMachine -{ - public: - /** constructor */ - CKernelPerceptron(); - virtual ~CKernelPerceptron(); - - /** train kernel perceptron classifier - * - * @param data training data (parameter can be avoided if distance or - * kernel-based classifiers are used and distance/kernels are - * initialized with train data) - * - * @return whether training was successful - */ - virtual bool train(CFeatures* data=NULL); - - /** classify one specific example - * - * @param num which example to classify - * @return classified value - */ - virtual float64_t classify_example(int32_t num); - - /** load KernelPerceptron from file - * - * @param srcfile file to load from - * @return if load was successful - */ - virtual bool load(FILE* srcfile); - - /** save KernelPerceptron to file - * - * @param dstfile file to save to - * @return if save was successful - */ - virtual bool save(FILE* dstfile); - - /** get classifier type - * - * @return classifier type KERNELPERCEPTRON - */ - inline virtual EClassifierType get_classifier_type() - { - return CT_KERNELPERCEPTRON; - } - - /** @return object name */ - inline virtual const char* get_name() const { return "KernelPerceptron"; } -}; -} -#endif From ebad67e9b3dfb23db8ce3cee29da9e7739458e27 Mon Sep 17 00:00:00 2001 From: Heiko Strathmann Date: Thu, 21 Jul 2011 16:40:15 +0200 Subject: [PATCH 04/12] added store_sv_features method to store SV data after training locally some changes go along with this train method now calls train_kernel_machine --- src/shogun/machine/KernelMachine.cpp | 27 +++++++++++++++++++++ src/shogun/machine/KernelMachine.h | 36 ++++++++++++++++++++++++++++ 2 files changed, 63 insertions(+) diff --git a/src/shogun/machine/KernelMachine.cpp b/src/shogun/machine/KernelMachine.cpp index a579288bd0b..15efb98325c 100644 --- a/src/shogun/machine/KernelMachine.cpp +++ b/src/shogun/machine/KernelMachine.cpp @@ -40,8 +40,11 @@ CKernelMachine::CKernelMachine() m_parameters->add(&m_alpha, "m_alpha", "Array of coefficients alpha."); m_parameters->add(&m_svs, "m_svs", "Number of ``support vectors''."); + m_parameters->add(&m_store_sv_features, "store_sv_features", + "Should SV-feature be stored after training?"); m_bias=0.0; + m_store_sv_features=false; } CKernelMachine::~CKernelMachine() @@ -265,3 +268,27 @@ void* CKernelMachine::apply_helper(void* p) return NULL; } + +void CKernelMachine::store_sv_features() +{ + if (!kernel) + SG_ERROR("kernel is needed to store SV features.\n"); + + CFeatures* lhs=kernel->get_lhs(); + CFeatures* rhs=kernel->get_rhs(); + + if (!lhs) + SG_ERROR("kernel lhs is needed to store SV features.\n"); + + /* copy sv feature data */ + CFeatures* sv_features=lhs->copy_subset(m_svs); + SG_UNREF(lhs); + + /* now sv indices are just the identity */ + CMath::range_fill_vector(m_svs.vector, m_svs.vlen, 0); + + /* set new lhs to kernel */ + kernel->init(sv_features, rhs); + + SG_UNREF(rhs); +} diff --git a/src/shogun/machine/KernelMachine.h b/src/shogun/machine/KernelMachine.h index ce6a50761f3..a884a6c798a 100644 --- a/src/shogun/machine/KernelMachine.h +++ b/src/shogun/machine/KernelMachine.h @@ -57,6 +57,17 @@ class CKernelMachine : public CMachine virtual const char* get_name(void) const { return "KernelMachine"; } + + virtual bool train(CFeatures* data=NULL) + { +// bool result=train_kernel_machine(data); + + if (m_store_sv_features) + store_sv_features(); + + return false; + } + /** set kernel * * @param k kernel @@ -332,6 +343,29 @@ class CKernelMachine : public CMachine */ static void* apply_helper(void* p); + /** TODO comment + * + */ + inline void set_store_sv_features(bool store) + { + m_store_sv_features=store; + } + + protected: + /** train classifier + * + * @param data training data (parameter can be avoided if distance or + * kernel-based classifiers are used and distance/kernels are + * initialized with train data) + * + * NOT IMPLEMENTED! + * + * @return whether training was successful + */ + virtual bool train_kernel_machine(CFeatures* data=NULL)=0; + + virtual void store_sv_features(); + protected: /** kernel */ CKernel* kernel; @@ -349,6 +383,8 @@ class CKernelMachine : public CMachine /** array of ``support vectors'' (indices of feature objects) */ SGVector m_svs; + + bool m_store_sv_features; }; } #endif /* _KERNEL_MACHINE_H__ */ From 87d622b4ed714fd2a9b15e677909483dfbce1dcb Mon Sep 17 00:00:00 2001 From: Heiko Strathmann Date: Thu, 21 Jul 2011 16:41:02 +0200 Subject: [PATCH 05/12] added method to copy a subset of features --- src/shogun/features/Features.h | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/src/shogun/features/Features.h b/src/shogun/features/Features.h index 993c9ca5916..642d654cc25 100644 --- a/src/shogun/features/Features.h +++ b/src/shogun/features/Features.h @@ -171,7 +171,11 @@ class CFeatures : public CSGObject * @param num_vectors new number of vectors * @return if reshaping was successful */ - virtual bool reshape(int32_t num_features, int32_t num_vectors) { return false; } + virtual bool reshape(int32_t num_features, int32_t num_vectors) + { + SG_NOTIMPLEMENTED; + return false; + } /** get memory footprint of one feature * @@ -262,6 +266,21 @@ class CFeatures : public CSGObject return m_subset ? m_subset->subset_idx_conversion(idx) : idx; } + /** Creates a new CFeatures instance containing copies of the elements + * which are specified by the provided indices. + * + * This method is needed for a KernelMachine to store its model data. + * NOT IMPLEMENTED! + * + * @param indices indices of feature elements to copy + * @return new CFeatures instance with copies of feature data + */ + virtual CFeatures* copy_subset(SGVector indices) const + { + SG_NOTIMPLEMENTED; + return NULL; + } + private: /** feature properties */ uint64_t properties; From 7a629ffac127f9a3cdc5f7a45adea74a28707f00 Mon Sep 17 00:00:00 2001 From: Heiko Strathmann Date: Thu, 21 Jul 2011 16:47:02 +0200 Subject: [PATCH 06/12] removed debug stuff --- src/shogun/machine/KernelMachine.h | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/shogun/machine/KernelMachine.h b/src/shogun/machine/KernelMachine.h index a884a6c798a..e96c3b06db7 100644 --- a/src/shogun/machine/KernelMachine.h +++ b/src/shogun/machine/KernelMachine.h @@ -60,12 +60,12 @@ class CKernelMachine : public CMachine virtual bool train(CFeatures* data=NULL) { -// bool result=train_kernel_machine(data); + bool result=train_kernel_machine(data); if (m_store_sv_features) store_sv_features(); - return false; + return result; } /** set kernel @@ -362,7 +362,11 @@ class CKernelMachine : public CMachine * * @return whether training was successful */ - virtual bool train_kernel_machine(CFeatures* data=NULL)=0; + virtual bool train_kernel_machine(CFeatures* data=NULL) + { + SG_NOTIMPLEMENTED; + return false; + } virtual void store_sv_features(); From bfa3fad6556bb3d70619c82df635e040f87c6139 Mon Sep 17 00:00:00 2001 From: Heiko Strathmann Date: Thu, 21 Jul 2011 16:48:20 +0200 Subject: [PATCH 07/12] removed KernelPerceptron --- src/shogun/ui/GUIClassifier.cpp | 9 --------- 1 file changed, 9 deletions(-) diff --git a/src/shogun/ui/GUIClassifier.cpp b/src/shogun/ui/GUIClassifier.cpp index c58ecfa38bf..a24c8d60e1c 100644 --- a/src/shogun/ui/GUIClassifier.cpp +++ b/src/shogun/ui/GUIClassifier.cpp @@ -29,7 +29,6 @@ #include #include #include -#include #include @@ -235,12 +234,6 @@ bool CGUIClassifier::new_classifier(char* name, int32_t d, int32_t from_d) SG_INFO("created KRR object %p\n", classifier); } #endif //HAVE_LAPACK - else if (strcmp(name,"KERNELPERCEPTRON")==0) - { - SG_UNREF(classifier); - classifier= new CKernelPerceptron(); - SG_INFO("created Kernel Perceptron object\n") ; - } else if (strcmp(name,"PERCEPTRON")==0) { SG_UNREF(classifier); @@ -1114,7 +1107,6 @@ CLabels* CGUIClassifier::classify() case CT_CPLEXSVM: case CT_GMNPSVM: case CT_GNPPSVM: - case CT_KERNELPERCEPTRON: case CT_LIBSVR: case CT_LIBSVMMULTICLASS: case CT_LIBSVMONECLASS: @@ -1209,7 +1201,6 @@ bool CGUIClassifier::get_trained_classifier( case CT_GPBT: case CT_CPLEXSVM: case CT_GMNPSVM: - case CT_KERNELPERCEPTRON: case CT_LIBSVR: case CT_LIBSVMONECLASS: case CT_SVRLIGHT: From 0c66e74c3b557354c97ad70d520b7494738040cb Mon Sep 17 00:00:00 2001 From: Heiko Strathmann Date: Thu, 21 Jul 2011 16:49:08 +0200 Subject: [PATCH 08/12] removed warning --- src/shogun/structure/SegmentLoss.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/shogun/structure/SegmentLoss.cpp b/src/shogun/structure/SegmentLoss.cpp index 8da30a07f50..7e7636260e3 100644 --- a/src/shogun/structure/SegmentLoss.cpp +++ b/src/shogun/structure/SegmentLoss.cpp @@ -19,7 +19,7 @@ CSegmentLoss::CSegmentLoss() m_segment_loss(1,1,2), m_segment_ids(NULL), m_segment_mask(NULL), - m_num_segment_types(NULL) + m_num_segment_types(0) { } CSegmentLoss::~CSegmentLoss() From 545972e1e9e293165b24ed27c920c4e5c0694699 Mon Sep 17 00:00:00 2001 From: Heiko Strathmann Date: Thu, 21 Jul 2011 17:07:31 +0200 Subject: [PATCH 09/12] forbid subset on lhs when calling apply --- src/shogun/machine/KernelMachine.cpp | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/shogun/machine/KernelMachine.cpp b/src/shogun/machine/KernelMachine.cpp index 15efb98325c..b7635b97df0 100644 --- a/src/shogun/machine/KernelMachine.cpp +++ b/src/shogun/machine/KernelMachine.cpp @@ -209,6 +209,15 @@ float64_t CKernelMachine::apply(int32_t num) { ASSERT(kernel); + /* check that lhs does not have a subset. Might be very bad because of a + * sv index kaboom: the sv indices are the ones for the original training + * data, not for the subset, so better just forbid this */ + CFeatures* lhs=kernel->get_lhs(); + if (lhs && lhs->has_subset()) + SG_ERROR("A subset on the lhs is not allowed when calling apply().\n"); + + SG_UNREF(lhs); + if (kernel->has_property(KP_LINADD) && (kernel->get_is_initialized())) { float64_t score = kernel->compute_optimized(num); From 608d4641c74842a3ad8de4b9e0067db30ad6e265 Mon Sep 17 00:00:00 2001 From: Heiko Strathmann Date: Thu, 21 Jul 2011 17:07:45 +0200 Subject: [PATCH 10/12] added comments --- src/shogun/machine/KernelMachine.h | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/shogun/machine/KernelMachine.h b/src/shogun/machine/KernelMachine.h index e96c3b06db7..c6270eef80b 100644 --- a/src/shogun/machine/KernelMachine.h +++ b/src/shogun/machine/KernelMachine.h @@ -62,6 +62,7 @@ class CKernelMachine : public CMachine { bool result=train_kernel_machine(data); + /* store sv feature data if wanted */ if (m_store_sv_features) store_sv_features(); @@ -343,8 +344,9 @@ class CKernelMachine : public CMachine */ static void* apply_helper(void* p); - /** TODO comment + /** When set, store_sv_features() is called after training * + * @param store whether sv features should be stored after training */ inline void set_store_sv_features(bool store) { @@ -368,6 +370,10 @@ class CKernelMachine : public CMachine return false; } + /** Stores feature data of the SV indices and sets it to the lhs of the + * underlying kernel. Then, all SV indices are set to identity. + * This way, this kernel machine now uses its own data copy for + * classification. */ virtual void store_sv_features(); protected: @@ -388,6 +394,7 @@ class CKernelMachine : public CMachine /** array of ``support vectors'' (indices of feature objects) */ SGVector m_svs; + /** whether sv features should be stored after training */ bool m_store_sv_features; }; } From 4a2bcb739095e9f202f44bb81062b964e95961af Mon Sep 17 00:00:00 2001 From: Heiko Strathmann Date: Thu, 21 Jul 2011 17:09:14 +0200 Subject: [PATCH 11/12] added has_subset method --- src/shogun/features/Features.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/shogun/features/Features.h b/src/shogun/features/Features.h index 642d654cc25..46314ae9e1e 100644 --- a/src/shogun/features/Features.h +++ b/src/shogun/features/Features.h @@ -266,6 +266,8 @@ class CFeatures : public CSGObject return m_subset ? m_subset->subset_idx_conversion(idx) : idx; } + inline bool has_subset() const { return m_subset!=NULL; } + /** Creates a new CFeatures instance containing copies of the elements * which are specified by the provided indices. * From 963da14fdd1aa6673f59559d7d0129e450993f39 Mon Sep 17 00:00:00 2001 From: Heiko Strathmann Date: Thu, 21 Jul 2011 17:09:25 +0200 Subject: [PATCH 12/12] renamed train() to train_kernel_machine() which is private and being called from KernelMachine --- src/shogun/classifier/mkl/MKL.cpp | 2 +- src/shogun/classifier/mkl/MKL.h | 27 +++++++++---------- src/shogun/classifier/mkl/MKLMultiClass.cpp | 2 +- src/shogun/classifier/mkl/MKLMultiClass.h | 19 +++++++------ src/shogun/classifier/svm/CPLEXSVM.cpp | 2 +- src/shogun/classifier/svm/CPLEXSVM.h | 7 ++--- .../classifier/svm/DomainAdaptationSVM.cpp | 4 +-- .../classifier/svm/DomainAdaptationSVM.h | 20 +++++++------- src/shogun/classifier/svm/GMNPSVM.cpp | 2 +- src/shogun/classifier/svm/GMNPSVM.h | 21 ++++++++------- src/shogun/classifier/svm/GNPPSVM.cpp | 2 +- src/shogun/classifier/svm/GNPPSVM.h | 21 ++++++++------- src/shogun/classifier/svm/GPBTSVM.cpp | 2 +- src/shogun/classifier/svm/GPBTSVM.h | 21 ++++++++------- src/shogun/classifier/svm/LaRank.cpp | 2 +- src/shogun/classifier/svm/LaRank.h | 5 ++-- src/shogun/classifier/svm/LibSVM.cpp | 2 +- src/shogun/classifier/svm/LibSVM.h | 21 ++++++++------- .../classifier/svm/LibSVMMultiClass.cpp | 2 +- src/shogun/classifier/svm/LibSVMMultiClass.h | 21 ++++++++------- src/shogun/classifier/svm/LibSVMOneClass.cpp | 2 +- src/shogun/classifier/svm/LibSVMOneClass.h | 21 ++++++++------- src/shogun/classifier/svm/MPDSVM.cpp | 2 +- src/shogun/classifier/svm/MPDSVM.h | 20 +++++++------- src/shogun/classifier/svm/SVMLight.cpp | 2 +- src/shogun/classifier/svm/SVMLight.h | 20 +++++++------- .../classifier/svm/SVMLightOneClass.cpp | 2 +- src/shogun/classifier/svm/SVMLightOneClass.h | 15 ++++++----- src/shogun/classifier/svm/ScatterSVM.cpp | 2 +- src/shogun/classifier/svm/ScatterSVM.h | 21 ++++++++------- src/shogun/regression/KRR.cpp | 6 ++--- src/shogun/regression/KRR.h | 25 ++++++++--------- src/shogun/regression/svr/LibSVR.cpp | 2 +- src/shogun/regression/svr/LibSVR.h | 21 ++++++++------- src/shogun/regression/svr/SVRLight.cpp | 2 +- src/shogun/regression/svr/SVRLight.h | 20 +++++++------- 36 files changed, 198 insertions(+), 190 deletions(-) diff --git a/src/shogun/classifier/mkl/MKL.cpp b/src/shogun/classifier/mkl/MKL.cpp index b44f629de82..6a41328972d 100644 --- a/src/shogun/classifier/mkl/MKL.cpp +++ b/src/shogun/classifier/mkl/MKL.cpp @@ -190,7 +190,7 @@ bool CMKL::check_lpx_status(LPX *lp) } #endif // USE_GLPK -bool CMKL::train(CFeatures* data) +bool CMKL::train_kernel_machine(CFeatures* data) { ASSERT(kernel); ASSERT(labels && labels->get_num_labels()); diff --git a/src/shogun/classifier/mkl/MKL.h b/src/shogun/classifier/mkl/MKL.h index 44fd6e3677b..670e5dab350 100644 --- a/src/shogun/classifier/mkl/MKL.h +++ b/src/shogun/classifier/mkl/MKL.h @@ -133,17 +133,6 @@ class CMKL : public CSVM return svm; } - - /** train MKL classifier - * - * @param data training data (parameter can be avoided if distance or - * kernel-based classifiers are used and distance/kernels are - * initialized with train data) - * - * @return whether training was successful - */ - virtual bool train(CFeatures* data=NULL); - /** set C mkl * * @param C new C_mkl @@ -265,7 +254,20 @@ class CMKL : public CSVM */ virtual void compute_sum_beta(float64_t* sumw); + /** @return object name */ + inline virtual const char* get_name() const { return "MKL"; } + protected: + /** train MKL classifier + * + * @param data training data (parameter can be avoided if distance or + * kernel-based classifiers are used and distance/kernels are + * initialized with train data) + * + * @return whether training was successful + */ + virtual bool train_kernel_machine(CFeatures* data=NULL); + /** check run before starting training (to e.g. check if labeling is * two-class labeling in classification case */ @@ -442,9 +444,6 @@ class CMKL : public CSVM bool check_lpx_status(LPX *lp); #endif - /** @return object name */ - inline virtual const char* get_name() const { return "MKL"; } - protected: /** wrapper SVM */ CSVM* svm; diff --git a/src/shogun/classifier/mkl/MKLMultiClass.cpp b/src/shogun/classifier/mkl/MKLMultiClass.cpp index 408844bd1ee..06f0f237ab5 100644 --- a/src/shogun/classifier/mkl/MKLMultiClass.cpp +++ b/src/shogun/classifier/mkl/MKLMultiClass.cpp @@ -325,7 +325,7 @@ float64_t CMKLMultiClass::getsquarenormofprimalcoefficients( } -bool CMKLMultiClass::train(CFeatures* data) +bool CMKLMultiClass::train_kernel_machine(CFeatures* data) { int numcl=labels->get_num_classes(); ASSERT(kernel); diff --git a/src/shogun/classifier/mkl/MKLMultiClass.h b/src/shogun/classifier/mkl/MKLMultiClass.h index 8c09bd58f80..4f4aec69d70 100644 --- a/src/shogun/classifier/mkl/MKLMultiClass.h +++ b/src/shogun/classifier/mkl/MKLMultiClass.h @@ -49,16 +49,6 @@ class CMKLMultiClass : public CMultiClassSVM */ virtual ~CMKLMultiClass(); - /** train Multiclass MKL classifier - * - * @param data training data (parameter can be avoided if distance or - * kernel-based classifiers are used and distance/kernels are - * initialized with train data) - * - * @return whether training was successful - */ - virtual bool train(CFeatures* data=NULL); - /** get classifier type * * @return classifier type GMNPMKL @@ -158,6 +148,15 @@ class CMKLMultiClass : public CMultiClassSVM const int32_t ind); + /** train Multiclass MKL classifier + * + * @param data training data (parameter can be avoided if distance or + * kernel-based classifiers are used and distance/kernels are + * initialized with train data) + * + * @return whether training was successful + */ + virtual bool train_kernel_machine(CFeatures* data=NULL); protected: diff --git a/src/shogun/classifier/svm/CPLEXSVM.cpp b/src/shogun/classifier/svm/CPLEXSVM.cpp index 7fa60f2ef80..53913924be1 100644 --- a/src/shogun/classifier/svm/CPLEXSVM.cpp +++ b/src/shogun/classifier/svm/CPLEXSVM.cpp @@ -28,7 +28,7 @@ CCPLEXSVM::~CCPLEXSVM() { } -bool CCPLEXSVM::train(CFeatures* data) +bool CCPLEXSVM::train_kernel_machine(CFeatures* data) { bool result = false; CCplex cplex; diff --git a/src/shogun/classifier/svm/CPLEXSVM.h b/src/shogun/classifier/svm/CPLEXSVM.h index 130f221fe3a..c16d3f707ef 100644 --- a/src/shogun/classifier/svm/CPLEXSVM.h +++ b/src/shogun/classifier/svm/CPLEXSVM.h @@ -26,6 +26,9 @@ IGNORE_IN_CLASSLIST class CCPLEXSVM : public CSVM CCPLEXSVM(); virtual ~CCPLEXSVM(); + virtual inline EClassifierType get_classifier_type() { return CT_CPLEXSVM; } + + protected: /** train SVM classifier * * @param data training data (parameter can be avoided if distance or @@ -34,9 +37,7 @@ IGNORE_IN_CLASSLIST class CCPLEXSVM : public CSVM * * @return whether training was successful */ - virtual bool train(CFeatures* data=NULL); - - virtual inline EClassifierType get_classifier_type() { return CT_CPLEXSVM; } + virtual bool train_kernel_machine(CFeatures* data=NULL); }; } #endif diff --git a/src/shogun/classifier/svm/DomainAdaptationSVM.cpp b/src/shogun/classifier/svm/DomainAdaptationSVM.cpp index 28b15776dea..973dbd6460d 100644 --- a/src/shogun/classifier/svm/DomainAdaptationSVM.cpp +++ b/src/shogun/classifier/svm/DomainAdaptationSVM.cpp @@ -78,7 +78,7 @@ bool CDomainAdaptationSVM::is_presvm_sane() } -bool CDomainAdaptationSVM::train(CFeatures* data) +bool CDomainAdaptationSVM::train_kernel_machine(CFeatures* data) { if (data) @@ -111,7 +111,7 @@ bool CDomainAdaptationSVM::train(CFeatures* data) delete[] lin_term; //train SVM - bool success = CSVMLight::train(); + bool success = CSVMLight::train_kernel_machine(); ASSERT(presvm) diff --git a/src/shogun/classifier/svm/DomainAdaptationSVM.h b/src/shogun/classifier/svm/DomainAdaptationSVM.h index 69456f82c02..11a284ec50e 100644 --- a/src/shogun/classifier/svm/DomainAdaptationSVM.h +++ b/src/shogun/classifier/svm/DomainAdaptationSVM.h @@ -49,16 +49,6 @@ class CDomainAdaptationSVM : public CSVMLight * */ void init(CSVM* presvm, float64_t B); - /** train SVM classifier - * - * @param data training data (parameter can be avoided if distance or - * kernel-based classifiers are used and distance/kernels are - * initialized with train data) - * - * @return whether training was successful - */ - virtual bool train(CFeatures* data=NULL); - /** get classifier type * * @return classifier type @@ -106,6 +96,16 @@ class CDomainAdaptationSVM : public CSVMLight */ virtual bool is_presvm_sane(); + /** train SVM classifier + * + * @param data training data (parameter can be avoided if distance or + * kernel-based classifiers are used and distance/kernels are + * initialized with train data) + * + * @return whether training was successful + */ + virtual bool train_kernel_machine(CFeatures* data=NULL); + private: void init(); diff --git a/src/shogun/classifier/svm/GMNPSVM.cpp b/src/shogun/classifier/svm/GMNPSVM.cpp index 815269b6d01..4f78a44ed63 100644 --- a/src/shogun/classifier/svm/GMNPSVM.cpp +++ b/src/shogun/classifier/svm/GMNPSVM.cpp @@ -48,7 +48,7 @@ CGMNPSVM::init(void) m_basealphas = NULL, m_basealphas_y = 0, m_basealphas_x = 0; } -bool CGMNPSVM::train(CFeatures* data) +bool CGMNPSVM::train_kernel_machine(CFeatures* data) { ASSERT(kernel); ASSERT(labels && labels->get_num_labels()); diff --git a/src/shogun/classifier/svm/GMNPSVM.h b/src/shogun/classifier/svm/GMNPSVM.h index 79bc82df88c..fe57ce5f0ab 100644 --- a/src/shogun/classifier/svm/GMNPSVM.h +++ b/src/shogun/classifier/svm/GMNPSVM.h @@ -40,16 +40,6 @@ class CGMNPSVM : public CMultiClassSVM /** default destructor */ virtual ~CGMNPSVM(); - /** train SVM - * - * @param data training data (parameter can be avoided if distance or - * kernel-based classifiers are used and distance/kernels are - * initialized with train data) - * - * @return whether training was successful - */ - virtual bool train(CFeatures* data=NULL); - /** get classifier type * * @return classifier type GMNPSVM @@ -70,6 +60,17 @@ class CGMNPSVM : public CMultiClassSVM /** @return object name */ inline virtual const char* get_name() const { return "GMNPSVM"; } + protected: + /** train SVM + * + * @param data training data (parameter can be avoided if distance or + * kernel-based classifiers are used and distance/kernels are + * initialized with train data) + * + * @return whether training was successful + */ + virtual bool train_kernel_machine(CFeatures* data=NULL); + protected: /** required for CMKLMulticlass * stores the untransformed alphas of this algorithm diff --git a/src/shogun/classifier/svm/GNPPSVM.cpp b/src/shogun/classifier/svm/GNPPSVM.cpp index 3052510e058..8831b62bff9 100644 --- a/src/shogun/classifier/svm/GNPPSVM.cpp +++ b/src/shogun/classifier/svm/GNPPSVM.cpp @@ -29,7 +29,7 @@ CGNPPSVM::~CGNPPSVM() { } -bool CGNPPSVM::train(CFeatures* data) +bool CGNPPSVM::train_kernel_machine(CFeatures* data) { ASSERT(kernel); ASSERT(labels && labels->get_num_labels()); diff --git a/src/shogun/classifier/svm/GNPPSVM.h b/src/shogun/classifier/svm/GNPPSVM.h index f5d1ffc6758..b3a8b673064 100644 --- a/src/shogun/classifier/svm/GNPPSVM.h +++ b/src/shogun/classifier/svm/GNPPSVM.h @@ -33,16 +33,6 @@ class CGNPPSVM : public CSVM virtual ~CGNPPSVM(); - /** train SVM classifier - * - * @param data training data (parameter can be avoided if distance or - * kernel-based classifiers are used and distance/kernels are - * initialized with train data) - * - * @return whether training was successful - */ - virtual bool train(CFeatures* data=NULL); - /** get classifier type * * @return classifier type GNPPSVM @@ -51,6 +41,17 @@ class CGNPPSVM : public CSVM /** @return object name */ inline virtual const char* get_name() const { return "GNPPSVM"; } + + protected: + /** train SVM classifier + * + * @param data training data (parameter can be avoided if distance or + * kernel-based classifiers are used and distance/kernels are + * initialized with train data) + * + * @return whether training was successful + */ + virtual bool train_kernel_machine(CFeatures* data=NULL); }; } #endif diff --git a/src/shogun/classifier/svm/GPBTSVM.cpp b/src/shogun/classifier/svm/GPBTSVM.cpp index 4bab0d7cc20..ceb47171905 100644 --- a/src/shogun/classifier/svm/GPBTSVM.cpp +++ b/src/shogun/classifier/svm/GPBTSVM.cpp @@ -30,7 +30,7 @@ CGPBTSVM::~CGPBTSVM() SG_FREE(model); } -bool CGPBTSVM::train(CFeatures* data) +bool CGPBTSVM::train_kernel_machine(CFeatures* data) { float64_t* solution; /* store the solution found */ QPproblem prob; /* object containing the solvers */ diff --git a/src/shogun/classifier/svm/GPBTSVM.h b/src/shogun/classifier/svm/GPBTSVM.h index cc73348ceab..31928672008 100644 --- a/src/shogun/classifier/svm/GPBTSVM.h +++ b/src/shogun/classifier/svm/GPBTSVM.h @@ -34,16 +34,6 @@ class CGPBTSVM : public CSVM CGPBTSVM(float64_t C, CKernel* k, CLabels* lab); virtual ~CGPBTSVM(); - /** train SVM classifier - * - * @param data training data (parameter can be avoided if distance or - * kernel-based classifiers are used and distance/kernels are - * initialized with train data) - * - * @return whether training was successful - */ - virtual bool train(CFeatures* data=NULL); - /** get classifier type * * @return classifier type GPBT @@ -53,6 +43,17 @@ class CGPBTSVM : public CSVM /** @return object name */ inline virtual const char* get_name() const { return "GPBTSVM"; } + protected: + /** train SVM classifier + * + * @param data training data (parameter can be avoided if distance or + * kernel-based classifiers are used and distance/kernels are + * initialized with train data) + * + * @return whether training was successful + */ + virtual bool train_kernel_machine(CFeatures* data=NULL); + protected: /** SVM model */ struct svm_model* model; diff --git a/src/shogun/classifier/svm/LaRank.cpp b/src/shogun/classifier/svm/LaRank.cpp index 20e8dc8938a..dd6b0c38a8e 100644 --- a/src/shogun/classifier/svm/LaRank.cpp +++ b/src/shogun/classifier/svm/LaRank.cpp @@ -602,7 +602,7 @@ CLaRank::~CLaRank () destroy(); } -bool CLaRank::train(CFeatures* data) +bool CLaRank::train_kernel_machine(CFeatures* data) { tau = 0.0001; diff --git a/src/shogun/classifier/svm/LaRank.h b/src/shogun/classifier/svm/LaRank.h index 3c9683d1b89..bf5a9b3d4f9 100644 --- a/src/shogun/classifier/svm/LaRank.h +++ b/src/shogun/classifier/svm/LaRank.h @@ -320,9 +320,6 @@ namespace shogun virtual ~CLaRank (); - bool train(CFeatures* data); - - // LEARNING FUNCTION: add new patterns and run optimization steps // selected with adaptative schedule virtual int32_t add (int32_t x_id, int32_t yi); @@ -361,6 +358,8 @@ namespace shogun void set_tau(float64_t t) { tau=t; }; float64_t get_tau() { return tau; }; + protected: + bool train_kernel_machine(CFeatures* data); private: /* diff --git a/src/shogun/classifier/svm/LibSVM.cpp b/src/shogun/classifier/svm/LibSVM.cpp index 80e1ebbf792..f4b4053a6bf 100644 --- a/src/shogun/classifier/svm/LibSVM.cpp +++ b/src/shogun/classifier/svm/LibSVM.cpp @@ -29,7 +29,7 @@ CLibSVM::~CLibSVM() } -bool CLibSVM::train(CFeatures* data) +bool CLibSVM::train_kernel_machine(CFeatures* data) { struct svm_node* x_space; diff --git a/src/shogun/classifier/svm/LibSVM.h b/src/shogun/classifier/svm/LibSVM.h index 9e7dafdbe12..95c149395b9 100644 --- a/src/shogun/classifier/svm/LibSVM.h +++ b/src/shogun/classifier/svm/LibSVM.h @@ -40,16 +40,6 @@ class CLibSVM : public CSVM virtual ~CLibSVM(); - /** train SVM classifier - * - * @param data training data (parameter can be avoided if distance or - * kernel-based classifiers are used and distance/kernels are - * initialized with train data) - * - * @return whether training was successful - */ - virtual bool train(CFeatures* data=NULL); - /** get classifier type * * @return classifier type LIBSVM @@ -59,6 +49,17 @@ class CLibSVM : public CSVM /** @return object name */ inline virtual const char* get_name() const { return "LibSVM"; } + protected: + /** train SVM classifier + * + * @param data training data (parameter can be avoided if distance or + * kernel-based classifiers are used and distance/kernels are + * initialized with train data) + * + * @return whether training was successful + */ + virtual bool train_kernel_machine(CFeatures* data=NULL); + protected: /** SVM problem */ svm_problem problem; diff --git a/src/shogun/classifier/svm/LibSVMMultiClass.cpp b/src/shogun/classifier/svm/LibSVMMultiClass.cpp index 7956165d05f..468c5945b50 100644 --- a/src/shogun/classifier/svm/LibSVMMultiClass.cpp +++ b/src/shogun/classifier/svm/LibSVMMultiClass.cpp @@ -28,7 +28,7 @@ CLibSVMMultiClass::~CLibSVMMultiClass() //SG_PRINT("deleting LibSVM\n"); } -bool CLibSVMMultiClass::train(CFeatures* data) +bool CLibSVMMultiClass::train_kernel_machine(CFeatures* data) { struct svm_node* x_space; diff --git a/src/shogun/classifier/svm/LibSVMMultiClass.h b/src/shogun/classifier/svm/LibSVMMultiClass.h index 4aa0b4190e8..8f2e23beb39 100644 --- a/src/shogun/classifier/svm/LibSVMMultiClass.h +++ b/src/shogun/classifier/svm/LibSVMMultiClass.h @@ -34,16 +34,6 @@ class CLibSVMMultiClass : public CMultiClassSVM CLibSVMMultiClass(float64_t C, CKernel* k, CLabels* lab); virtual ~CLibSVMMultiClass(); - /** train multiclass SVM classifier - * - * @param data training data (parameter can be avoided if distance or - * kernel-based classifiers are used and distance/kernels are - * initialized with train data) - * - * @return whether training was successful - */ - virtual bool train(CFeatures* data=NULL); - /** get classifier type * * @return classifier type LIBSVMMULTICLASS @@ -53,6 +43,17 @@ class CLibSVMMultiClass : public CMultiClassSVM /** @return object name */ inline virtual const char* get_name() const { return "LibSVMMultiClass"; } + protected: + /** train multiclass SVM classifier + * + * @param data training data (parameter can be avoided if distance or + * kernel-based classifiers are used and distance/kernels are + * initialized with train data) + * + * @return whether training was successful + */ + virtual bool train_kernel_machine(CFeatures* data=NULL); + protected: /** SVM problem */ svm_problem problem; diff --git a/src/shogun/classifier/svm/LibSVMOneClass.cpp b/src/shogun/classifier/svm/LibSVMOneClass.cpp index a1ddb25f700..2daa1eb02f5 100644 --- a/src/shogun/classifier/svm/LibSVMOneClass.cpp +++ b/src/shogun/classifier/svm/LibSVMOneClass.cpp @@ -29,7 +29,7 @@ CLibSVMOneClass::~CLibSVMOneClass() SG_FREE(model); } -bool CLibSVMOneClass::train(CFeatures* data) +bool CLibSVMOneClass::train_kernel_machine(CFeatures* data) { ASSERT(kernel); if (data) diff --git a/src/shogun/classifier/svm/LibSVMOneClass.h b/src/shogun/classifier/svm/LibSVMOneClass.h index ce5265f16dc..7d24b40cdce 100644 --- a/src/shogun/classifier/svm/LibSVMOneClass.h +++ b/src/shogun/classifier/svm/LibSVMOneClass.h @@ -34,16 +34,6 @@ class CLibSVMOneClass : public CSVM CLibSVMOneClass(float64_t C, CKernel* k); virtual ~CLibSVMOneClass(); - /** train SVM - * - * @param data training data (parameter can be avoided if distance or - * kernel-based classifiers are used and distance/kernels are - * initialized with train data) - * - * @return whether training was successful - */ - virtual bool train(CFeatures* data=NULL); - /** get classifier type * * @return classifier type LIBSVMONECLASS @@ -53,6 +43,17 @@ class CLibSVMOneClass : public CSVM /** @return object name */ inline virtual const char* get_name() const { return "LibSVMOneClass"; } + protected: + /** train SVM + * + * @param data training data (parameter can be avoided if distance or + * kernel-based classifiers are used and distance/kernels are + * initialized with train data) + * + * @return whether training was successful + */ + virtual bool train_kernel_machine(CFeatures* data=NULL); + protected: /** SVM problem */ svm_problem problem; diff --git a/src/shogun/classifier/svm/MPDSVM.cpp b/src/shogun/classifier/svm/MPDSVM.cpp index acf54493a82..9598dc3f419 100644 --- a/src/shogun/classifier/svm/MPDSVM.cpp +++ b/src/shogun/classifier/svm/MPDSVM.cpp @@ -29,7 +29,7 @@ CMPDSVM::~CMPDSVM() { } -bool CMPDSVM::train(CFeatures* data) +bool CMPDSVM::train_kernel_machine(CFeatures* data) { ASSERT(labels); ASSERT(kernel); diff --git a/src/shogun/classifier/svm/MPDSVM.h b/src/shogun/classifier/svm/MPDSVM.h index b2655902160..b00580ad345 100644 --- a/src/shogun/classifier/svm/MPDSVM.h +++ b/src/shogun/classifier/svm/MPDSVM.h @@ -32,16 +32,6 @@ class CMPDSVM : public CSVM CMPDSVM(float64_t C, CKernel* k, CLabels* lab); virtual ~CMPDSVM(); - /** train SVM classifier - * - * @param data training data (parameter can be avoided if distance or - * kernel-based classifiers are used and distance/kernels are - * initialized with train data) - * - * @return whether training was successful - */ - virtual bool train(CFeatures* data=NULL); - /** get classifier type * * @return classifier type MPD @@ -52,6 +42,16 @@ class CMPDSVM : public CSVM inline virtual const char* get_name() const { return "MPDSVM"; } protected: + /** train SVM classifier + * + * @param data training data (parameter can be avoided if distance or + * kernel-based classifiers are used and distance/kernels are + * initialized with train data) + * + * @return whether training was successful + */ + virtual bool train_kernel_machine(CFeatures* data=NULL); + /** compute H * * @param i index of H diff --git a/src/shogun/classifier/svm/SVMLight.cpp b/src/shogun/classifier/svm/SVMLight.cpp index 5655f9954fb..f4a772a4a96 100644 --- a/src/shogun/classifier/svm/SVMLight.cpp +++ b/src/shogun/classifier/svm/SVMLight.cpp @@ -172,7 +172,7 @@ CSVMLight::~CSVMLight() delete[] primal; } -bool CSVMLight::train(CFeatures* data) +bool CSVMLight::train_kernel_machine(CFeatures* data) { //certain setup params mkl_converged=false; diff --git a/src/shogun/classifier/svm/SVMLight.h b/src/shogun/classifier/svm/SVMLight.h index f041a0acc31..11c0a280f25 100644 --- a/src/shogun/classifier/svm/SVMLight.h +++ b/src/shogun/classifier/svm/SVMLight.h @@ -246,16 +246,6 @@ class CSVMLight : public CSVM /** init SVM */ void init(); - /** train SVM classifier - * - * @param data training data (parameter can be avoided if distance or - * kernel-based classifiers are used and distance/kernels are - * initialized with train data) - * - * @return whether training was successful - */ - virtual bool train(CFeatures* data=NULL); - /** get classifier type * * @return classifier type LIGHT @@ -654,6 +644,16 @@ class CSVMLight : public CSVM float64_t *optimize_qp( QP *qp,float64_t *epsilon_crit, int32_t nx, float64_t *threshold, int32_t& svm_maxqpsize); + /** train SVM classifier + * + * @param data training data (parameter can be avoided if distance or + * kernel-based classifiers are used and distance/kernels are + * initialized with train data) + * + * @return whether training was successful + */ + virtual bool train_kernel_machine(CFeatures* data=NULL); + protected: /** model */ MODEL* model; diff --git a/src/shogun/classifier/svm/SVMLightOneClass.cpp b/src/shogun/classifier/svm/SVMLightOneClass.cpp index 327fa4486de..d3aeda3cb08 100644 --- a/src/shogun/classifier/svm/SVMLightOneClass.cpp +++ b/src/shogun/classifier/svm/SVMLightOneClass.cpp @@ -48,7 +48,7 @@ CSVMLightOneClass::CSVMLightOneClass() { } -bool CSVMLightOneClass::train(CFeatures* data) +bool CSVMLightOneClass::train_kernel_machine(CFeatures* data) { //certain setup params mkl_converged=false; diff --git a/src/shogun/classifier/svm/SVMLightOneClass.h b/src/shogun/classifier/svm/SVMLightOneClass.h index 3f02c4d2645..5d9856f7992 100644 --- a/src/shogun/classifier/svm/SVMLightOneClass.h +++ b/src/shogun/classifier/svm/SVMLightOneClass.h @@ -41,6 +41,13 @@ class CSVMLightOneClass: public CSVMLight /** default destructor */ virtual ~CSVMLightOneClass() { } + /** get classifier type + * + * @return classifier type LIGHTONECLASS + */ + virtual inline EClassifierType get_classifier_type() { return CT_LIGHTONECLASS; } + + protected: /** train one class svm * * @param data training data (parameter can be avoided if distance or @@ -49,13 +56,7 @@ class CSVMLightOneClass: public CSVMLight * * @return whether training was successful */ - virtual bool train(CFeatures* data=NULL); - - /** get classifier type - * - * @return classifier type LIGHTONECLASS - */ - virtual inline EClassifierType get_classifier_type() { return CT_LIGHTONECLASS; } + virtual bool train_kernel_machine(CFeatures* data=NULL); }; } #endif //USE_SVMLIGHT diff --git a/src/shogun/classifier/svm/ScatterSVM.cpp b/src/shogun/classifier/svm/ScatterSVM.cpp index f97568b8558..d9656a62a3e 100644 --- a/src/shogun/classifier/svm/ScatterSVM.cpp +++ b/src/shogun/classifier/svm/ScatterSVM.cpp @@ -44,7 +44,7 @@ CScatterSVM::~CScatterSVM() delete[] norm_wcw; } -bool CScatterSVM::train(CFeatures* data) +bool CScatterSVM::train_kernel_machine(CFeatures* data) { ASSERT(labels && labels->get_num_labels()); m_num_classes = labels->get_num_classes(); diff --git a/src/shogun/classifier/svm/ScatterSVM.h b/src/shogun/classifier/svm/ScatterSVM.h index 78ac3597fdb..61e1d9b1d06 100644 --- a/src/shogun/classifier/svm/ScatterSVM.h +++ b/src/shogun/classifier/svm/ScatterSVM.h @@ -70,16 +70,6 @@ class CScatterSVM : public CMultiClassSVM /** default destructor */ virtual ~CScatterSVM(); - /** train SVM classifier - * - * @param data training data (parameter can be avoided if distance or - * kernel-based classifiers are used and distance/kernels are - * initialized with train data) - * - * @return whether training was successful - */ - virtual bool train(CFeatures* data=NULL); - /** get classifier type * * @return classifier type LIBSVM @@ -102,6 +92,17 @@ class CScatterSVM : public CMultiClassSVM /** @return object name */ inline virtual const char* get_name() const { return "ScatterSVM"; } + protected: + /** train SVM classifier + * + * @param data training data (parameter can be avoided if distance or + * kernel-based classifiers are used and distance/kernels are + * initialized with train data) + * + * @return whether training was successful + */ + virtual bool train_kernel_machine(CFeatures* data=NULL); + private: void compute_norm_wc(); virtual bool train_no_bias_libsvm(); diff --git a/src/shogun/regression/KRR.cpp b/src/shogun/regression/KRR.cpp index 583643626ba..46ef27bcd40 100644 --- a/src/shogun/regression/KRR.cpp +++ b/src/shogun/regression/KRR.cpp @@ -40,7 +40,7 @@ CKRR::~CKRR() delete[] alpha; } -bool CKRR::train(CFeatures* data) +bool CKRR::train_kernel_machine(CFeatures* data) { delete[] alpha; @@ -96,7 +96,7 @@ bool CKRR::save(FILE* dstfile) return false; } -CLabels* CKRR::classify() +CLabels* CKRR::apply() { ASSERT(kernel); @@ -127,7 +127,7 @@ CLabels* CKRR::classify() return output; } -float64_t CKRR::classify_example(int32_t num) +float64_t CKRR::apply(int32_t num) { ASSERT(kernel); diff --git a/src/shogun/regression/KRR.h b/src/shogun/regression/KRR.h index d341befb11b..5835fa698a2 100644 --- a/src/shogun/regression/KRR.h +++ b/src/shogun/regression/KRR.h @@ -72,28 +72,18 @@ class CKRR : public CKernelMachine */ inline void set_tau(float64_t t) { tau = t; }; - /** train regression - * - * @param data training data (parameter can be avoided if distance or - * kernel-based regressors are used and distance/kernels are - * initialized with train data) - * - * @return whether training was successful - */ - virtual bool train(CFeatures* data=NULL); - /** classify regression * * @return resulting labels */ - virtual CLabels* classify(); + virtual CLabels* apply(); /** classify one example * * @param num which example to classify * @return result */ - virtual float64_t classify_example(int32_t num); + virtual float64_t apply(int32_t num); /** load regression from file * @@ -121,6 +111,17 @@ class CKRR : public CKernelMachine /** @return object name */ inline virtual const char* get_name() const { return "KRR"; } + protected: + /** train regression + * + * @param data training data (parameter can be avoided if distance or + * kernel-based regressors are used and distance/kernels are + * initialized with train data) + * + * @return whether training was successful + */ + virtual bool train_kernel_machine(CFeatures* data=NULL); + private: /** alpha */ float64_t *alpha; diff --git a/src/shogun/regression/svr/LibSVR.cpp b/src/shogun/regression/svr/LibSVR.cpp index baa6cd3f9f4..39d7e2c1803 100644 --- a/src/shogun/regression/svr/LibSVR.cpp +++ b/src/shogun/regression/svr/LibSVR.cpp @@ -35,7 +35,7 @@ CLibSVR::~CLibSVR() SG_FREE(model); } -bool CLibSVR::train(CFeatures* data) +bool CLibSVR::train_kernel_machine(CFeatures* data) { ASSERT(kernel); ASSERT(labels && labels->get_num_labels()); diff --git a/src/shogun/regression/svr/LibSVR.h b/src/shogun/regression/svr/LibSVR.h index 10caca99214..13d91308a20 100644 --- a/src/shogun/regression/svr/LibSVR.h +++ b/src/shogun/regression/svr/LibSVR.h @@ -64,16 +64,6 @@ class CLibSVR : public CSVM CLibSVR(float64_t C, float64_t epsilon, CKernel* k, CLabels* lab); virtual ~CLibSVR(); - /** train regression - * - * @param data training data (parameter can be avoided if distance or - * kernel-based regressor are used and distance/kernels are - * initialized with train data) - * - * @return whether training was successful - */ - virtual bool train(CFeatures* data=NULL); - /** get classifier type * * @return classifie type LIBSVR @@ -82,6 +72,17 @@ class CLibSVR : public CSVM /** @return object name */ inline virtual const char* get_name() const { return "LibSVR"; } + + protected: + /** train regression + * + * @param data training data (parameter can be avoided if distance or + * kernel-based regressor are used and distance/kernels are + * initialized with train data) + * + * @return whether training was successful + */ + virtual bool train_kernel_machine(CFeatures* data=NULL); protected: /** SVM problem */ svm_problem problem; diff --git a/src/shogun/regression/svr/SVRLight.cpp b/src/shogun/regression/svr/SVRLight.cpp index 7c1ed1f51b9..f885fe6eb1e 100644 --- a/src/shogun/regression/svr/SVRLight.cpp +++ b/src/shogun/regression/svr/SVRLight.cpp @@ -59,7 +59,7 @@ CSVRLight::CSVRLight() { } -bool CSVRLight::train(CFeatures* data) +bool CSVRLight::train_kernel_machine(CFeatures* data) { //certain setup params verbosity=1; diff --git a/src/shogun/regression/svr/SVRLight.h b/src/shogun/regression/svr/SVRLight.h index 67980949c96..1ea88193a5f 100644 --- a/src/shogun/regression/svr/SVRLight.h +++ b/src/shogun/regression/svr/SVRLight.h @@ -77,16 +77,6 @@ class CSVRLight: public CSVMLight /** default destructor */ virtual ~CSVRLight() { } - /** train regression - * - * @param data training data (parameter can be avoided if distance or - * kernel-based regressors are used and distance/kernels are - * initialized with train data) - * - * @return whether training was successful - */ - virtual bool train(CFeatures* data=NULL); - /** get classifier type * * @return classifier type SVRLIGHT @@ -240,6 +230,16 @@ class CSVRLight: public CSVMLight return kernel->kernel(i, j); } + /** train regression + * + * @param data training data (parameter can be avoided if distance or + * kernel-based regressors are used and distance/kernels are + * initialized with train data) + * + * @return whether training was successful + */ + virtual bool train_kernel_machine(CFeatures* data=NULL); + /** number of train elements */ int32_t num_vectors; };