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

Return GridSearch suggestions in random order. #101

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion sherpa/algorithms/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -332,19 +332,23 @@ class GridSearch(Algorithm):

Args:
num_grid_points (int): number of grid points for continuous / discrete.
random_order (bool): If true, return suggestions in random order.

"""
allows_repetition = True

def __init__(self, num_grid_points=2):
def __init__(self, num_grid_points=2, random_order=True):
self.grid = None
self.num_grid_points = num_grid_points
self.count = 0 # number of sampled configs
self.random_order = random_order

def get_suggestion(self, parameters, results=None, lower_is_better=True):
if self.count == 0:
param_dict = self._get_param_dict(parameters)
self.grid = list(sklearn.model_selection.ParameterGrid(param_dict))
if self.random_order:
random.shuffle(self.grid)

if self.count >= len(self.grid):
return AlgorithmState.DONE
Expand Down