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

SG_ADD refactor #4417

Merged
merged 7 commits into from Nov 21, 2018
Merged

SG_ADD refactor #4417

merged 7 commits into from Nov 21, 2018

Conversation

gf712
Copy link
Member

@gf712 gf712 commented Nov 16, 2018

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:

  • MS_NOT_AVAILABLE()); -> ParameterProperties());
  • MS_AVAILABLE()); -> ParameterProperties::HYPER);
  • MS_AVAILABLE, GRADIENT_AVAILABLE); -> ParameterProperties::HYPER | ParameterProperties::GRADIENT);

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.

Gil added 2 commits November 16, 2018 15:01
* 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
Copy link
Member

@karlnapf karlnapf left a 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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Weclome to SGObject ;)

Copy link
Member Author

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

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());
Copy link
Member

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.

@@ -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__))
Copy link
Member

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)

Copy link
Member Author

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);
Copy link
Member

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());
Copy link
Member

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

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());
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hyper

@@ -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());
Copy link
Member

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

Copy link
Member Author

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?

Copy link
Member

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());
Copy link
Member

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());
Copy link
Member

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);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice!

{ \
this->m_parameters->add(param, name, description); \
this->watch_param( \
name, param, AnyParameterProperties()); \
Copy link
Member

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");
Copy link
Member

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());
Copy link
Member

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());
Copy link
Member

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()) \
Copy link
Member

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()) \
Copy link
Member

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

@karlnapf karlnapf merged commit b5345f5 into shogun-toolbox:develop Nov 21, 2018
@gf712 gf712 deleted the sg_add_refactor branch November 21, 2018 17:22
@karlnapf
Copy link
Member

BTW this passed all of our CI
https://dev.azure.com/shogunml/shogun/_build/results?buildId=91

Try to keep an eye on the output of this after any patch is merged (until we have the pre-merge builds back)

@gf712
Copy link
Member Author

gf712 commented Nov 30, 2018

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?

@karlnapf
Copy link
Member

Sorry what do you mean? :)

@gf712
Copy link
Member Author

gf712 commented Nov 30, 2018

We still have these in the code:

/** model selection availability */
enum EModelSelectionAvailability
{
	MS_NOT_AVAILABLE = 0,
	MS_AVAILABLE = 1,
};

/** gradient availability */
enum EGradientAvailability
{
	GRADIENT_NOT_AVAILABLE = 0,
	GRADIENT_AVAILABLE = 1
};

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?

@karlnapf
Copy link
Member

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?

@gf712
Copy link
Member Author

gf712 commented Nov 30, 2018

GPL compiles fine! And the tests pass.

gf712 pushed a commit to gf712/shogun-gpl that referenced this pull request Nov 30, 2018
* 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
@karlnapf
Copy link
Member

cool thanks!

gf712 pushed a commit to gf712/shogun-gpl that referenced this pull request Nov 30, 2018
* 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
gf712 pushed a commit to gf712/shogun-gpl that referenced this pull request Dec 3, 2018
* 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
gf712 pushed a commit to gf712/shogun-gpl that referenced this pull request Dec 3, 2018
* 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
gf712 pushed a commit to gf712/shogun-gpl that referenced this pull request Dec 3, 2018
* 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
gf712 pushed a commit to gf712/shogun-gpl that referenced this pull request Dec 3, 2018
* 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
vigsterkr pushed a commit to vigsterkr/shogun that referenced this pull request Mar 9, 2019
* 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
ktiefe pushed a commit to ktiefe/shogun that referenced this pull request Jul 30, 2019
* 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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants