Add HilbertGridSearchOptimizer for space-filling curve traversal #70
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Fixes: #65
Motivation
The current grid-search implementation in Gradient-Free-Optimizers, as noted in issue #65, starts traversal from a corner of the search space and follows paths close to previously explored points. This leads to poor exploration when the number of iterations is much smaller than the search space size, limiting the algorithm’s ability to effectively cover n-dimensional spaces. By introducing a Hilbert curve-based traversal, this PR aims to improve exploration by generating points in a space-filling manner, ensuring better coverage across all dimensions, particularly for high-dimensional problems with limited iterations
Description of the changes
This PR adds a new HilbertGridSearchOptimizer class that uses a Hilbert curve to traverse the search space, addressing the exploration limitations outlined in issue #65. The changes include:
New File: Created hilbert_grid_search.py with the HilbertGridSearchOptimizer class:
Inherits from BaseOptimizer, maintaining consistency with OrthogonalGridSearchOptimizer and DiagonalGridSearchOptimizer.
Implements a hilbert_move method that generates grid points along a Hilbert curve using the numpy-hilbert-curve package’s decode function.
Supports the step_size parameter to skip points and filters out-of-bounds coordinates for non-cubic grids.
Uses conv2pos to convert indices to search space positions, ensuring compatibility with existing logic.
Updated grid_search.py:
Added import: from .hilbert_grid_search import HilbertGridSearchOptimizer.
Modified the GridSearchOptimizer class to support a new "hilbert" direction, instantiating HilbertGridSearchOptimizer when selected.