-
Notifications
You must be signed in to change notification settings - Fork 3.8k
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
[MRG] check duplicate params #961
Conversation
wxchan
commented
Oct 3, 2017
- check params which are alias to each other and print warnings
- add get_parameter function to let user check current parameters, easy to debug
@wxchan I think this solution is too heavy. Maybe we can refactor the whole config class, for example, we can put all parameters into a unordered_map, and retrieve the value by using its names. |
python-package/lightgbm/basic.py
Outdated
@@ -1397,6 +1397,50 @@ def reset_parameter(self, params): | |||
self.handle, | |||
c_str(params_str))) | |||
|
|||
def get_parameter(self, is_output_raw=False): |
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.
I think that get_parameter
in python API is needed anyway, but please update docstring with the aim of uniformity with other docstrings.
"""Get parameters of Booster.
Parameters
----------
is_output_raw : bool, optional (default=False)
Whether to output raw string.
Returns
-------
param : dict or string
Parameters of Booster.
If ``is_output_raw=False``, dictionary of parameters with string key and string value;
otherwise, string of parameters as concat of "key:value".
"""
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.
I already revert this. Looking for better solution.
@guolinke I agree. But what's your solution to save different types of values in unordered_map, a common way for me is std::variant, but it's not supported until c++17. |
@guolinke btw, there may be some bug in python categorical feature, is Dataset and Booster using the same Overall Config in c_api now? |
@wxchan there using the different configs. BTW, we can define a class, e.g. And we can parse all these types when read a parameter, and retrieve the type we need. |
@wxchan another solution is using multi maps. for example, unordered_map::<string, int> int_map; and using another map to check its types. However, my concern is such a dynamic solution may cause the performance issue. Can we simplify the GetParam and make it automatically ? |
@guolinke one possible solution is to save params to a map in GetInt/GetDouble/GetBool/GetString or KeyAliasTransform. I can revert get_parameter if there is no good solutions now. |
@guolinke if they are using overall config, when using get_parameter, I can only get parameters from overall config of Booster? How can I know whether overall config of Dataset is working? |
@wxchan currently, Dataset class doesn't store the parameters. The parameters are used temporarily when constructing Dataset. |
@guolinke so with get_parameter, the result might not be the actual parameters used for datasets? |
@wxchan yeah. So you may need to store a IOConfig in the Dataset class. |
clean codes
This reverts commit ec1d8dd.
@guolinke I revert get_parameter first, you can review other part. |
@wxchan |
include/LightGBM/config.h
Outdated
if (alias != alias_table.end()) { // found alias | ||
auto alias_set = tmp_map.find(alias->second); | ||
if (alias_set != tmp_map.end()) { // alias already set | ||
// set priority alphabetically to ensure reproducible behavior |
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.
maybe using the strlen for the priority is better? since users often use the short names.
include/LightGBM/config.h
Outdated
@@ -81,6 +81,7 @@ struct ConfigBase { | |||
const std::unordered_map<std::string, std::string>& params, | |||
const std::string& name, bool* out); | |||
|
|||
static void KVIntoMap(std::unordered_map<std::string, std::string>& params, const char* kv); |
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.
KV2Map ?
* add get params clean codes * check duplicate params * Revert "add get params" This reverts commit ec1d8dd. * set priority by length & check duplicate * rename function