Skip to content

Commit

Permalink
Fix interval_size in CVTArchive and SlidingBoundariesArchive (#452)
Browse files Browse the repository at this point in the history
## Description

<!-- Provide a brief description of the PR's purpose here. -->

Previously, SlidingBoundariesArchive updated the lower_bounds and
upper_bounds but not the interval_size. CVTArchive did not have an
interval_size property at all.

## Status

- [x] I have read the guidelines in

[CONTRIBUTING.md](https://github.com/icaros-usc/pyribs/blob/master/CONTRIBUTING.md)
- [x] I have formatted my code using `yapf`
- [x] I have tested my code by running `pytest`
- [x] I have linted my code with `pylint`
- [x] I have added a one-line description of my change to the changelog
in
      `HISTORY.md`
- [x] This PR is ready to go
  • Loading branch information
btjanaka committed Jan 27, 2024
1 parent 05cd524 commit 47dcfe5
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 0 deletions.
1 change: 1 addition & 0 deletions HISTORY.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@

#### Improvements

- Fix interval_size in CVTArchive and SlidingBoundariesArchive ({pr}`452`)
- Allow overriding ES in sphere example ({pr}`439`)
- Use NumPy SeedSequence in emitters ({pr}`431`, {pr}`440`)
- Use numbers types when checking arguments ({pr}`419`)
Expand Down
7 changes: 7 additions & 0 deletions ribs/archives/_cvt_archive.py
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,7 @@ def __init__(self,
ranges = list(zip(*ranges))
self._lower_bounds = np.array(ranges[0], dtype=self.dtype)
self._upper_bounds = np.array(ranges[1], dtype=self.dtype)
self._interval_size = self._upper_bounds - self._lower_bounds

# Apply default args for k-means. Users can easily override these,
# particularly if they want higher quality clusters.
Expand Down Expand Up @@ -259,6 +260,12 @@ def upper_bounds(self):
"""(measure_dim,) numpy.ndarray: Upper bound of each dimension."""
return self._upper_bounds

@property
def interval_size(self):
"""(measure_dim,) numpy.ndarray: The size of each dim (upper_bounds -
lower_bounds)."""
return self._interval_size

@property
def samples(self):
"""(num_samples, measure_dim) numpy.ndarray: The samples used in
Expand Down
1 change: 1 addition & 0 deletions ribs/archives/_sliding_boundaries_archive.py
Original file line number Diff line number Diff line change
Expand Up @@ -454,6 +454,7 @@ def add_single(self, solution, objective, measures, **fields):
self._upper_bounds = np.array([
bound[dim] for bound, dim in zip(self._boundaries, self._dims)
])
self._interval_size = self._upper_bounds - self._lower_bounds
else:
add_info = ArchiveBase.add_single(self, **new_data)
return add_info
1 change: 1 addition & 0 deletions tests/archives/cvt_archive_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ def test_samples_bad_shape(use_kd_tree):
def test_properties_are_correct(data):
assert np.all(data.archive.lower_bounds == [-1, -1])
assert np.all(data.archive.upper_bounds == [1, 1])
assert np.all(data.archive.interval_size == [2, 2])

points = [[0.5, 0.5], [-0.5, 0.5], [-0.5, -0.5], [0.5, -0.5]]
unittest.TestCase().assertCountEqual(data.archive.samples.tolist(), points)
Expand Down

0 comments on commit 47dcfe5

Please sign in to comment.