Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SigmoidKernel constructors cleanup #5031

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 8 additions & 22 deletions src/shogun/kernel/SigmoidKernel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<params::GammaFeatureNumberInit>(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<DotFeatures>& l, const std::shared_ptr<DotFeatures>& r, int32_t size, float64_t g, float64_t c)
: DotKernel(size)
: SigmoidKernel(size, g, c)
{
init();

gamma = g;
coef0 = c;

init(l, r);
}

Expand All @@ -51,15 +49,3 @@ bool SigmoidKernel::init(std::shared_ptr<Features> l, std::shared_ptr<Features>
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<params::GammaFeatureNumberInit>(this));
SG_ADD(&coef0, "coef0", "Coefficient 0.", ParameterProperties::HYPER);
}
7 changes: 2 additions & 5 deletions src/shogun/kernel/SigmoidKernel.h
Original file line number Diff line number Diff line change
Expand Up @@ -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__ */