From 86b07216383f493026973e31bb490e5a8358e76e Mon Sep 17 00:00:00 2001 From: Hougang Liu Date: Mon, 27 May 2019 23:53:51 -0500 Subject: [PATCH] Reverse logic of Less in hyperband v1alpha1 (#592) --- pkg/suggestion/v1alpha1/hyperband_service.go | 6 +++--- pkg/suggestion/v1alpha1/hyperband_service_test.go | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/pkg/suggestion/v1alpha1/hyperband_service.go b/pkg/suggestion/v1alpha1/hyperband_service.go index 8aad4e87f64..9a21a4daa15 100644 --- a/pkg/suggestion/v1alpha1/hyperband_service.go +++ b/pkg/suggestion/v1alpha1/hyperband_service.go @@ -32,7 +32,7 @@ func (b Bracket) Swap(i, j int) { } func (b Bracket) Less(i, j int) bool { - return b[i].value > b[j].value + return b[i].value < b[j].value } type HyperBandParameters struct { @@ -142,9 +142,9 @@ func (h *HyperBandSuggestService) makeChildBracket(ctx context.Context, c api.Ma child := Bracket{} if sconf.OptimizationType == api.OptimizationType_MINIMIZE { - child = parent[len(parent)-n:] - } else if sconf.OptimizationType == api.OptimizationType_MAXIMIZE { child = parent[:n] + } else if sconf.OptimizationType == api.OptimizationType_MAXIMIZE { + child = parent[len(parent)-n:] } gtreq := &api.GetTrialsRequest{ StudyId: studyID, diff --git a/pkg/suggestion/v1alpha1/hyperband_service_test.go b/pkg/suggestion/v1alpha1/hyperband_service_test.go index 13da64073a6..9fb47643bb5 100644 --- a/pkg/suggestion/v1alpha1/hyperband_service_test.go +++ b/pkg/suggestion/v1alpha1/hyperband_service_test.go @@ -300,7 +300,7 @@ func TestSwap(t *testing.T) { func TestLess(t *testing.T) { size := 2 b := getSampleBracket(size) - exp := false + exp := true rtn := b.Less(0, 1) if exp != rtn { @@ -503,7 +503,7 @@ func TestEvalWorkers(t *testing.T) { _, rtn_bracket := h.evalWorkers(context.Background(), mockAPI, "studyId", &p) - exp_bracket := []Evals{{"trial3", 19}, {"trial2", 11}, {"trial1", 3}} + exp_bracket := []Evals{{"trial1", 3}, {"trial2", 11}, {"trial3", 19}} for i, ebkt := range exp_bracket { if ebkt != rtn_bracket[i] {