From 4c7c94d3cea69224a63dfb0cc314851ae771cf14 Mon Sep 17 00:00:00 2001 From: gf712 Date: Thu, 14 May 2020 12:40:04 +0100 Subject: [PATCH] sigmoid kernel constructors cleanup --- src/shogun/kernel/SigmoidKernel.cpp | 30 ++++++++--------------------- src/shogun/kernel/SigmoidKernel.h | 7 ++----- 2 files changed, 10 insertions(+), 27 deletions(-) diff --git a/src/shogun/kernel/SigmoidKernel.cpp b/src/shogun/kernel/SigmoidKernel.cpp index 16b264e41b6..7ca3dde1ca4 100644 --- a/src/shogun/kernel/SigmoidKernel.cpp +++ b/src/shogun/kernel/SigmoidKernel.cpp @@ -13,27 +13,25 @@ using namespace shogun; SigmoidKernel::SigmoidKernel() : DotKernel() { - init(); + SG_ADD( + &gamma, "gamma", "Scaler for the dot product.", + ParameterProperties::HYPER | ParameterProperties::AUTO, + std::make_shared(this)); + SG_ADD(&coef0, "coef0", "Coefficient 0.", ParameterProperties::HYPER); } SigmoidKernel::SigmoidKernel(int32_t size, float64_t g, float64_t c) - : DotKernel(size) + : SigmoidKernel() { - init(); - + set_cache_size(size); gamma = g; coef0 = c; } SigmoidKernel::SigmoidKernel( const std::shared_ptr& l, const std::shared_ptr& r, int32_t size, float64_t g, float64_t c) - : DotKernel(size) + : SigmoidKernel(size, g, c) { - init(); - - gamma = g; - coef0 = c; - init(l, r); } @@ -51,15 +49,3 @@ bool SigmoidKernel::init(std::shared_ptr l, std::shared_ptr DotKernel::init(l, r); return init_normalizer(); } - -void SigmoidKernel::init() -{ - gamma = 0.0; - coef0 = 0.0; - - SG_ADD( - &gamma, "gamma", "Scaler for the dot product.", - ParameterProperties::HYPER | ParameterProperties::AUTO, - std::make_shared(this)); - SG_ADD(&coef0, "coef0", "Coefficient 0.", ParameterProperties::HYPER); -} diff --git a/src/shogun/kernel/SigmoidKernel.h b/src/shogun/kernel/SigmoidKernel.h index 253be8ff7e2..9f7db15310f 100644 --- a/src/shogun/kernel/SigmoidKernel.h +++ b/src/shogun/kernel/SigmoidKernel.h @@ -87,14 +87,11 @@ class SigmoidKernel: public DotKernel return tanh(gamma*DotKernel::compute(idx_a,idx_b)+coef0); } - private: - void init(); - protected: /** gamma */ - float64_t gamma; + float64_t gamma = 0.0; /** coefficient 0 */ - float64_t coef0; + float64_t coef0 = 0.0; }; } #endif /* _SIGMOIDKERNEL_H__ */