Skip to content

Commit

Permalink
Rewrite min_post_range test to using fitted GPClassificationModel (#477)
Browse files Browse the repository at this point in the history
Summary:

The test_finish_criteria test uses the MonotonicRejectionGP alongside many mocks. This seems really brittle meaning that it fails when very subtle things changes in the model (and is seemingly impossible to debug and maintain).

The min_post_range finish condition actually cares about the values of the model so we move this out of that test into its own acutally using a model we fit (GPClassificationModel) so that we can test it easier.

Reviewed By: crasanders

Differential Revision: D67066880
  • Loading branch information
JasonKChow authored and facebook-github-bot committed Dec 16, 2024
1 parent 1144806 commit 4d39911
Showing 1 changed file with 34 additions and 4 deletions.
38 changes: 34 additions & 4 deletions tests/test_strategy.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,10 +142,40 @@ def test_finish_criteria(self):
self.strat.finished
) # not enough difference between posterior min/max

for _ in range(50):
self.strat.gen()
self.strat.add_data(np.r_[0.0, 0.0], [0])
self.assertTrue(self.strat.finished)
def test_min_post_range(self):
seed = 1
torch.manual_seed(seed)
np.random.seed(seed)
lb = [0]
ub = [1]

self.strat = Strategy(
model=GPClassificationModel(
lb=lb,
ub=ub,
inducing_point_method=AutoAllocator(
bounds=torch.stack([torch.tensor(lb), torch.tensor(ub)])
),
),
generator=SobolGenerator(lb=lb, ub=ub),
min_asks=10,
lb=lb,
ub=ub,
stimuli_per_trial=1,
outcome_types=["binary"],
min_post_range=0.3,
)

loops = 0
while not self.strat.finished:
points = self.strat.gen(1)
response = int(np.random.rand() < points)
self.strat.add_data(points, torch.tensor([response]))
loops += 1

if loops > 50:
self.fail("min_post_range didn't finish even after 50 loops.")
break

def test_max_asks(self):
self.strat.max_asks = 50
Expand Down

0 comments on commit 4d39911

Please sign in to comment.