Skip to content

Conversation

@smohsinali
Copy link
Contributor

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'

@mfeurer
Copy link
Contributor

mfeurer commented Jan 25, 2017

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
@coveralls
Copy link

coveralls commented Jan 26, 2017

Coverage Status

Coverage decreased (-0.1%) to 67.228% when pulling f921ef5 on smohsinali:typecheck_hyperparameter_p3 into 4aa95af on automl:master.

Copy link
Contributor

@mfeurer mfeurer left a 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 ;)

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)
Copy link
Contributor

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.

Copy link
Contributor Author

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


Copy link
Contributor

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?

Copy link
Contributor Author

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


class FloatHyperparameter(NumericalHyperparameter):
def __init__(self, name, default):
# todo : type of name and default?
Copy link
Contributor

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

removed

return np.round(float(default), 10)
@abstractmethod
def is_legal(self, value: Union[int, float]) -> bool:
# return isinstance(value, float) or isinstance(value, int)
Copy link
Contributor

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

removed

# return isinstance(value, float) or isinstance(value, int)
raise NotImplemented

# todo : recheck default
Copy link
Contributor

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.


def _transform(self, vector):

# todo recheck return type...is it list or normal
Copy link
Contributor

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

outdated comment...removed


def get_value(self, idx):

# todo : recheck
Copy link
Contributor

Choose a reason for hiding this comment

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

correct, please remove comment.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

removed

return False

def _sample(self, rs, size=None):
def _sample(self, rs: np.random, size: Union[int, None] = None) -> int:
Copy link
Contributor

Choose a reason for hiding this comment

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

same as above.

Copy link
Contributor Author

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

return 2

def get_neighbors(self, value, number=2, transform = False):
# todo: recehck...added rs as param otherrwise mismatch with baseclass signature
Copy link
Contributor

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

removed

upper = 10
f1 = UniformFloatHyperparameter("param", lower, upper, q=0.1, log=True)

# self.assertTrue(f1.is_legal(3.0))
Copy link
Contributor

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?

Copy link
Contributor Author

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

@coveralls
Copy link

coveralls commented Jan 30, 2017

Coverage Status

Coverage decreased (-0.03%) to 67.302% when pulling 18f5620 on smohsinali:typecheck_hyperparameter_p3 into 4aa95af on automl:master.

Copy link
Contributor

@mfeurer mfeurer left a 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:
Copy link
Contributor

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?

Copy link
Contributor Author

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:
Copy link
Contributor

Choose a reason for hiding this comment

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

No type definition here.

Copy link
Contributor Author

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'


# 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':
Copy link
Contributor

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

fixed

Copy link
Contributor Author

Choose a reason for hiding this comment

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

fixed

@coveralls
Copy link

coveralls commented Jan 31, 2017

Coverage Status

Coverage decreased (-0.03%) to 67.302% when pulling d06086c on smohsinali:typecheck_hyperparameter_p3 into 4aa95af on automl:master.

@mfeurer mfeurer merged commit 1943118 into automl:master Jan 31, 2017
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.

3 participants