-
-
Notifications
You must be signed in to change notification settings - Fork 1k
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
SG_ADD refactor #4417
SG_ADD refactor #4417
Conversation
* with the new AnyParameterProperties we can clean up the macros a bit and have a single macro with four parameters * inside the macro we still have exactly the same process
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A few initial comments. Main change is I think we should make default properties less verbose
@@ -4,7 +4,8 @@ | |||
* Authors: Heiko Strathmann, Soeren Sonnenburg, Sergey Lisitsyn, | |||
* Giovanni De Toni, Jacob Walker, Thoralf Klein, Chiyuan Zhang, | |||
* Fernando Iglesias, Sanuj Sharma, Roman Votyakov, Yuyu Zhang, | |||
* Viktor Gal, Bjoern Esser, Evangelos Anagnostopoulos, Pan Deng | |||
* Viktor Gal, Bjoern Esser, Evangelos Anagnostopoulos, Pan Deng, | |||
* Gil Hoben |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Weclome to SGObject ;)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Haha yes, I thought I would discretely add myself to the list :D
src/shogun/classifier/LDA.cpp
Outdated
SG_ADD(&m_bdc_svd, "m_bdc_svd", "Use BDC-SVD algorithm", MS_NOT_AVAILABLE); | ||
"Method used for LDA calculation", ParameterProperties()); | ||
SG_ADD(&m_gamma, "m_gamma", "Regularization parameter", ParameterProperties::HYPER); | ||
SG_ADD(&m_bdc_svd, "m_bdc_svd", "Use BDC-SVD algorithm", ParameterProperties()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Mmmh. This is not nice, it would be better if this default was done automatically.
I didn't realise this before, but I think it means we have to have SG_ADD3 (default properties) and SG_ADD4(user specified properties) as macros cannot do default parameters.
src/shogun/base/SGObject.h
Outdated
@@ -59,50 +60,18 @@ template <class T> class SGStringList; | |||
* Macros for registering parameters/model selection parameters | |||
******************************************************************************/ | |||
|
|||
#ifdef _MSC_VER | |||
|
|||
#define VA_NARGS(...) INTERNAL_EXPAND_ARGS_PRIVATE(INTERNAL_ARGS_AUGMENTER(__VA_ARGS__)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
While it would be good to get rid of this thing, I think we still need to keep it (see below on default properties)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK, I will bring this back and add a SG_ADD3!
SG_ADD(&m_gamma, "m_gamma", "Regularization parameter", MS_AVAILABLE); | ||
SG_ADD(&m_bdc_svd, "m_bdc_svd", "Use BDC-SVD algorithm", MS_NOT_AVAILABLE); | ||
"Method used for LDA calculation", ParameterProperties()); | ||
SG_ADD(&m_gamma, "m_gamma", "Regularization parameter", ParameterProperties::HYPER); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is quite nice now
@@ -22,17 +22,17 @@ CPluginEstimate::CPluginEstimate(float64_t pos_pseudo, float64_t neg_pseudo) | |||
{ | |||
SG_ADD( | |||
&m_pos_pseudo, "pos_pseudo", "pseudo count for positive class", | |||
MS_NOT_AVAILABLE); | |||
ParameterProperties()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
again, would be good if default was taken if just nothing was provided
src/shogun/classifier/mkl/MKL.cpp
Outdated
SG_ADD(&C_mkl, "C_mkl", "C mkl", ParameterProperties()); | ||
SG_ADD(&mkl_norm, "mkl_norm", "norm used in mkl", ParameterProperties()); | ||
SG_ADD(&ent_lambda, "ent_lambda", "elastic net sparsity trade-off parameter", ParameterProperties()); | ||
SG_ADD(&mkl_block_norm, "mkl_block_norm", "mkl sparse trade-off parameter", ParameterProperties()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
hyper
src/shogun/machine/LinearMachine.cpp
Outdated
@@ -35,11 +35,11 @@ void CLinearMachine::init() | |||
bias = 0; | |||
features = NULL; | |||
|
|||
SG_ADD(&m_w, "w", "Parameter vector w.", MS_NOT_AVAILABLE); | |||
SG_ADD(&bias, "bias", "Bias b.", MS_NOT_AVAILABLE); | |||
SG_ADD(&m_w, "w", "Parameter vector w.", ParameterProperties()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
things like this would be MODEL
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Both the weight and bias right?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes. We dont need to fix all the wrongly added parameter in this PR though, just put a few examples in
@@ -68,7 +68,7 @@ CStructuredLabels* CLinearStructuredOutputMachine::apply_structured(CFeatures* d | |||
|
|||
void CLinearStructuredOutputMachine::register_parameters() | |||
{ | |||
SG_ADD(&m_w, "m_w", "Weight vector", MS_NOT_AVAILABLE); | |||
SG_ADD(&m_w, "m_w", "Weight vector", ParameterProperties()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
model
@@ -19,10 +19,10 @@ using namespace shogun; | |||
COnlineLinearMachine::COnlineLinearMachine() | |||
: CMachine(), bias(0), features(NULL) | |||
{ | |||
SG_ADD(&m_w, "m_w", "Parameter vector w.", MS_NOT_AVAILABLE); | |||
SG_ADD(&bias, "bias", "Bias b.", MS_NOT_AVAILABLE); | |||
SG_ADD(&m_w, "m_w", "Parameter vector w.", ParameterProperties()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
model, you get the hang :)
@@ -52,7 +52,7 @@ CGaussianLikelihood::CGaussianLikelihood(float64_t sigma) : CLikelihoodModel() | |||
void CGaussianLikelihood::init() | |||
{ | |||
m_log_sigma=0.0; | |||
SG_ADD(&m_log_sigma, "log_sigma", "Observation noise in log domain", MS_AVAILABLE, GRADIENT_AVAILABLE); | |||
SG_ADD(&m_log_sigma, "log_sigma", "Observation noise in log domain", ParameterProperties::HYPER | ParameterProperties::GRADIENT); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nice!
also refactored the SG_ADD calls respectively
{ \ | ||
this->m_parameters->add(param, name, description); \ | ||
this->watch_param( \ | ||
name, param, AnyParameterProperties()); \ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes this is good
@@ -49,9 +49,9 @@ void CLDA::init() | |||
|
|||
SG_ADD( | |||
(machine_int_t*)&m_method, "m_method", | |||
"Method used for LDA calculation", ParameterProperties()); | |||
"Method used for LDA calculation"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yep, much cleaner
SG_ADD(&m_nullspace_shift, "nullspace_shift", | ||
"nullspace finding regularization shift",MS_NOT_AVAILABLE); | ||
"nullspace finding regularization shift",ParameterProperties()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
missed one here :)
SG_ADD(&m_squishing_rate, "quishing_rate", | ||
"squishing rate",MS_NOT_AVAILABLE); | ||
"squishing rate",ParameterProperties()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
and here
description, ms_available, gradient_available)); \ | ||
if (ms_available) \ | ||
this->watch_param(name, param, pprop); \ | ||
if (pprop.get_model_selection()) \ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note for later: we can already start to get rid of the model_selection_parameters
field and instead make the code work with any. Definitely a sub-task in all this refactoring ... but more on it later
this->m_model_selection_parameters->add(param, name, description); \ | ||
if (gradient_available) \ | ||
if (pprop.get_gradient()) \ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same for those gradient parameters
BTW this passed all of our CI Try to keep an eye on the output of this after any patch is merged (until we have the pre-merge builds back) |
Yes, I saw that. I think it's because of the multiple constructors, which also have defaults, led to something we didn't expect. So might be worth removing the constructors which accept the old enums since they shouldn't be required anymore? |
Sorry what do you mean? :) |
We still have these in the code:
Might be worth removing this with an update of the hash for the latest commit on the GPL repo? I am not sure we are talking about the same thing though. I thought you meant you expected some tests to have failed because the GPL repo hasn't been updated yet on the shogun repo? Which they should have, because GPL still uses the old SG_ADD, right? |
ah I see now. GPL should compile, could you check/make sure? removing these might cause a lot of compile errors, we should eventually do that (as I said, the modelselection parameters should be removed as well), but maybe for now let's focus on one thing? |
GPL compiles fine! And the tests pass. |
* Replaced the SG_ADD macro calls with the new ParameterProperties enum class * this was done in the same way as in PR shogun-toolbox/shogun#4417
cool thanks! |
* Replaced the SG_ADD macro calls with the new ParameterProperties enum class * this was done in the same way as in PR shogun-toolbox/shogun#4417
* Replaced the SG_ADD macro calls with the new ParameterProperties enum class * this was done in the same way as in PR shogun-toolbox/shogun#4417
* Replaced the SG_ADD macro calls with the new ParameterProperties enum class * this was done in the same way as in PR shogun-toolbox/shogun#4417
* Replaced the SG_ADD macro calls with the new ParameterProperties enum class * this was done in the same way as in PR shogun-toolbox/shogun#4417
* Replaced the SG_ADD macro calls with the new ParameterProperties enum class * this was done in the same way as in PR shogun-toolbox/shogun#4417
* replaced variable macro with a single macro [ci skip] * with the new AnyParameterProperties we can clean up the macros a bit and have a single macro with four parameters * inside the macro we still have exactly the same process * refactored all SG_ADD macros to use ParameterProperties [ci skip] * added SG_ADD3 for default parameters [ci skip] also refactored the SG_ADD calls respectively
* replaced variable macro with a single macro [ci skip] * with the new AnyParameterProperties we can clean up the macros a bit and have a single macro with four parameters * inside the macro we still have exactly the same process * refactored all SG_ADD macros to use ParameterProperties [ci skip] * added SG_ADD3 for default parameters [ci skip] also refactored the SG_ADD calls respectively
Now that we can register parameter properties with a single enum we don't need to have several SG_ADD macros with variable number of parameters.
I replaced with a regular expression the following expressions in the whole project:
We would have to do the same with the code in the GPL submodule.
Sorry about the large commit, it just seemed like replacing everything with a regex was the simplest!
I also tested the code locally to make sure it works fine, and passed the tests.