Skip to content

Commit

Permalink
Merge branch 'master' into Refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
cxhernandez authored Apr 18, 2019
2 parents fe13306 + 9b7d948 commit 384469b
Show file tree
Hide file tree
Showing 6 changed files with 46 additions and 23 deletions.
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
language: c
dist: xenial
sudo: false

env:
Expand Down
11 changes: 7 additions & 4 deletions devtools/travis-ci/build_docs.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,17 @@ conda create --yes -n docenv python=$CONDA_PY
source activate docenv
conda install -yq --use-local osprey


# Install doc requirements
conda install --yes --file docs/requirements.txt


# We don't use conda for these:
# sphinx_rtd_theme's latest releases are not available
# neither is msmb_theme
# neither is sphinx > 1.3.1 (fix #1892 autodoc problem)
pip install -I sphinx==1.3.5 sphinx_rtd_theme==0.1.9 msmb_theme==1.2.0

# Install doc requirements
conda install --yes --file docs/requirements.txt
pip install -I sphinx==1.3.5
pip install -I sphinx_rtd_theme==0.1.9 msmb_theme==1.2.0

# Make docs
cd docs && make html && cd -
Expand Down
2 changes: 1 addition & 1 deletion devtools/travis-ci/install_miniconda.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,4 @@ export PATH=$HOME/miniconda3/bin:$PATH

conda install -yq python=$CONDA_PY
conda update -yq conda
conda install -yq conda-build jinja2
conda install -yq conda-build jinja2 conda-verify
2 changes: 1 addition & 1 deletion docs/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
# Include python so this file isn't empty
python
numpydoc
numpydoc=0.7
2 changes: 1 addition & 1 deletion osprey/fit_estimator.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ def fit_and_score_estimator(estimator, parameters, cv, X, y=None, scoring=None,
"""Fit and score an estimator with cross-validation
This function is basically a copy of sklearn's
grid_search._BaseSearchCV._fit(), which is the core of the GridSearchCV
model_selection._BaseSearchCV._fit(), which is the core of the GridSearchCV
fit() method. Unfortunately, that class does _not_ return the training
set scores, which we want to save in the database, and because of the
way it's written, you can't change it by subclassing or monkeypatching.
Expand Down
51 changes: 35 additions & 16 deletions osprey/strategies.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,8 @@ def is_repeated_suggestion(params, history):
-------
is_repeated_suggestion : bool
"""
if any(params == hparams and hstatus == 'SUCCEEDED' for hparams, hscore, hstatus in history):
if any(params == hparams and hstatus == 'SUCCEEDED'
for hparams, hscore, hstatus in history):
return True
else:
return False
Expand Down Expand Up @@ -189,8 +190,10 @@ def suggest(self, history, searchspace):
if isinstance(var, EnumVariable):
# get the index in the choices of the parameter, and use
# that.
matches = [i for i, c in enumerate(var.choices)
if c == params[var.name]]
matches = [
i for i, c in enumerate(var.choices)
if c == params[var.name]
]
assert len(matches) == 1
vals[var.name] = matches
else:
Expand All @@ -204,13 +207,19 @@ def suggest(self, history, searchspace):
'idxs': dict((k, [i]) for k in hp_searchspace.keys()),
'tid': i,
'vals': vals,
'workdir': None},
'workdir': None
},
'result': result,
'tid': i,
# bunch of fixed fields that hyperopt seems to require
'owner': None, 'spec': None, 'state': 2, 'book_time': None,
'exp_key': None, 'refresh_time': None, 'version': 0
})
'owner': None,
'spec': None,
'state': 2,
'book_time': None,
'exp_key': None,
'refresh_time': None,
'version': 0
})

trials.refresh()
chosen_params_container = []
Expand All @@ -224,8 +233,12 @@ def mock_fn(x):
chosen_params_container.append(x)
return 0

fmin(fn=mock_fn, algo=suggest, space=hp_searchspace, trials=trials,
max_evals=len(trials.trials)+1,

fmin(fn=mock_fn,
algo=tpe.suggest,
space=hp_searchspace,
trials=trials,
max_evals=len(trials.trials) + 1,
**self._hyperopt_fmin_random_kwarg(random))
chosen_params = chosen_params_container[0]

Expand All @@ -238,15 +251,19 @@ def _hyperopt_fmin_random_kwarg(random):
kwargs = {'rstate': random, 'allow_trials_fmin': False}
elif 'rseed' in inspect.getargspec(fmin).args:
# 0.0.2 version uses different argument
kwargs = {'rseed': random.randint(2**32-1)}
kwargs = {'rseed': random.randint(2**32 - 1)}
return kwargs


class Bayes(BaseStrategy):
short_name = 'bayes'
# TODO : n_iter, max_iter should be in acquisition params

def __init__(self, kernels=None, acquisition=None, surrogate=None, seed=None, seeds=1, n_iter=50, max_feval=5E4, max_iter=1E5):
def __init__(self,
acquisition=None,
seed=None,
seeds=1,
max_feval=5E4,
max_iter=1E5):
self.seed = seed
self.seeds = seeds
self.max_feval = max_feval
Expand Down Expand Up @@ -288,8 +305,7 @@ def _get_data(self, history, searchspace):
raise RuntimeError('unrecognized status: %s' % status)

return (np.array(X).reshape(-1, self.n_dims),
np.array(Y).reshape(-1, 1),
np.array(V).reshape(-1, 1),
np.array(Y).reshape(-1, 1), np.array(V).reshape(-1, 1),
np.array(ignore).reshape(-1, self.n_dims))

def _from_unit(self, result, searchspace):
Expand Down Expand Up @@ -350,9 +366,12 @@ def suggest(self, history, searchspace):
# Convert searchspace to param_grid
if self.param_grid is None:
if not all(isinstance(v, EnumVariable) for v in searchspace):
raise RuntimeError("GridSearchStrategy is defined only for all-enum search space")
raise RuntimeError(
"GridSearchStrategy is defined only for all-enum search space"
)

self.param_grid = ParameterGrid(dict((v.name, v.choices) for v in searchspace))
self.param_grid = ParameterGrid(
dict((v.name, v.choices) for v in searchspace))

# NOTE: there is no way of signaling end of parameters to be searched against
# so user should pick correctly number of evaluations
Expand Down

0 comments on commit 384469b

Please sign in to comment.