-
Notifications
You must be signed in to change notification settings - Fork 96
Typecheck hyperparameter p3 #21
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
Typecheck hyperparameter p3 #21
Conversation
…ypecheck_hyperparameter_p3 # Conflicts: # ConfigSpace/hyperparameters.py
…ypecheck_hyperparameter_p3 # Conflicts: # ConfigSpace/hyperparameters.py
…o typecheck_hyperparameter_p3 # Conflicts: # ConfigSpace/hyperparameters.py
|
I just pushed some fixes, please fix the remaining bugs. Code looks okay, but needs a little bit of restructuring and cleaning after you fixed the bugs ;) |
change self.check_int to check_int
mfeurer
left a comment
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 looks good. Comments are mostly of cosmetic nature, asking you to remove comments ;)
ConfigSpace/hyperparameters.py
Outdated
| if not (isinstance(value, float) or isinstance(value, int)): | ||
| return False | ||
| # Strange numerical issues! | ||
| # todo: discuss acceptable tolerance (without big tolerance for upper the test fails) |
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.
Tolerance is fine for now, please remove the todo and other comment.
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.
removed
| from functools import reduce | ||
| import numpy as np | ||
|
|
||
|
|
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.
Actually, all these methods are specific to one class, right? If yes, could you please move them to the respective classes?
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 io and np are used in all classes
ConfigSpace/hyperparameters.py
Outdated
|
|
||
| class FloatHyperparameter(NumericalHyperparameter): | ||
| def __init__(self, name, default): | ||
| # todo : type of name and default? |
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.
Yup, they're correct. Please remove the comment.
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.
removed
ConfigSpace/hyperparameters.py
Outdated
| return np.round(float(default), 10) | ||
| @abstractmethod | ||
| def is_legal(self, value: Union[int, float]) -> bool: | ||
| # return isinstance(value, float) or isinstance(value, int) |
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.
Please remove old return statements.
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.
removed
ConfigSpace/hyperparameters.py
Outdated
| # return isinstance(value, float) or isinstance(value, int) | ||
| raise NotImplemented | ||
|
|
||
| # todo : recheck default |
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.
Type correct. Please remove comment.
ConfigSpace/hyperparameters.py
Outdated
|
|
||
| def _transform(self, vector): | ||
|
|
||
| # todo recheck return type...is it list or normal |
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 don't get this comment.
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.
outdated comment...removed
ConfigSpace/hyperparameters.py
Outdated
|
|
||
| def get_value(self, idx): | ||
|
|
||
| # todo : recheck |
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.
correct, please remove comment.
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.
removed
ConfigSpace/hyperparameters.py
Outdated
| return False | ||
|
|
||
| def _sample(self, rs, size=None): | ||
| def _sample(self, rs: np.random, size: Union[int, None] = None) -> int: |
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 as above.
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.
changed to np.random.RandomState
ConfigSpace/hyperparameters.py
Outdated
| return 2 | ||
|
|
||
| def get_neighbors(self, value, number=2, transform = False): | ||
| # todo: recehck...added rs as param otherrwise mismatch with baseclass signature |
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, correct, although it's not used here. Please remove the comment.
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.
removed
test/test_hyperparameters.py
Outdated
| upper = 10 | ||
| f1 = UniformFloatHyperparameter("param", lower, upper, q=0.1, log=True) | ||
|
|
||
| # self.assertTrue(f1.is_legal(3.0)) |
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.
Why are these all commented out?
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.
is_legal was changed to is_legal_uniformfloat but is now reverted back
mfeurer
left a comment
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.
Hi, three minor things, plus, please make sure that the variable rs is actually annotated with np.random.RandomState instead of np.random.
| return True | ||
|
|
||
| def get_num_neighbors(self, value: None=None) -> np.inf: | ||
| def get_num_neighbors(self, value= None) -> np.inf: |
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.
Why did you remove the type declaration here?
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.
mypy doesnt accept None=None
|
|
||
| def check_default(self, default: int) -> int: | ||
| @abstractmethod | ||
| def check_default(self, default) -> int: |
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.
No type definition here.
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 abstract method. in its definition in UniformIntegerHyperparameter type of default is 'Union[int, float]' while in NormalIntegerHyperparameter type of default is 'int' so because of this conflict i removed it form abstract method.
if you want in some different way i can do that for example making it same and then in init of NormalIntegerHyperparameter doing a check to make sure that its only 'int'
ConfigSpace/hyperparameters.py
Outdated
|
|
||
| # todo check if conversion should be done in initiation call or inside class itsel | ||
| def to_uniform(self, z: int = 3) -> 'UniformIntegerHyperparameter': | ||
| def to_uniform(self, z: np.round = 3) -> 'UniformIntegerHyperparameter': |
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 didn't mean the type should be np.round, I meant you should use np.round(int(self.mu - (z * self.sigma))) instead of only int(self.mu - (z * self.sigma)) to make sure that the hyperparameter is rounded correctly to the next int.
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.
fixed
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.
fixed
Remaing mypy errors in hyperparameters.py file: (mixin and value_dict)
hyperparameters.py:208: error: "is_legal" undefined in superclass
hyperparameters.py:211: error: "UniformMixin" has no attribute "upper"
hyperparameters.py:211: error: "UniformMixin" has no attribute "lower"
hyperparameters.py: note: In member "check_default" of class "UniformMixin":
hyperparameters.py:222: error: "check_default" undefined in superclass
hyperparameters.py: note: In member "init" of class "OrdinalHyperparameter":
hyperparameters.py:761: error: Need type annotation for variable
hyperparameters.py:764: error: Cannot determine type of 'value_dict'
hyperparameters.py: note: In member "get_order" of class "OrdinalHyperparameter":
hyperparameters.py:829: error: Cannot determine type of 'value_dict'
hyperparameters.py: note: In member "get_value" of class "OrdinalHyperparameter":
hyperparameters.py:836: error: Cannot determine type of 'value_dict'