d4l3k/go-bayesopt

UniformParams sometimes given as all zero values, even when Min is present

mediocregopher opened this issue · 0 comments

Example:

	var (
		a        = bayesopt.UniformParam{Name: "a", Min: 2, Max: 500}
		b        = bayesopt.UniformParam{Name: "b", Min: 0, Max: 100}
		c        = bayesopt.UniformParam{Name: "c", Min: 0, Max: 100}
		d        = bayesopt.UniformParam{Name: "d", Min: 0.01, Max: 1}
		e        = bayesopt.UniformParam{Name: "e", Min: 0, Max: 1000}
		bayesOpt = bayesopt.New([]bayesopt.Param{a, b, c, d, e})
	)

	bestParams, _, _ := bayesOpt.Optimize(
		func(params map[bayesopt.Param]float64) float64 {
			if params[a] == 0 {
				panic(fmt.Sprintf("params are all zero: %+v", params))
			}
			return params[a]
		},
	)

	log.Printf("bestParams:%+v", bestParams)

On latest master, using go 1.21.8, this more often than not panics at the if params[a] == 0 check:

panic: params are all zero: map[{Name:a Max:500 Min:2}:0 {Name:b Max:100 Min:0}:0 {Name:c Max:100 Min:0}:0 {Name:d Max:1 Min:0.01}:0 {Name:e Max:1000 Min:0}:0]

goroutine 1 [running]:
main.main.func1(0xc000385260)
        /tmp/tmp.yINnICZSgY/main.go:23 +0x165
github.com/d4l3k/go-bayesopt.(*Optimizer).Optimize(0xc0000c6000, 0xc0000be180)
        /home/mediocregopher/go/pkg/mod/github.com/d4l3k/go-bayesopt@v0.0.0-20191110222447-8506d3040732/bayesopt.go:348 +0x1f9
main.main()
        /tmp/tmp.yINnICZSgY/main.go:20 +0x379
exit status 2

The a param should never be zero, as it has a Min of 2. In fact all the params are zero, which makes me think there's definitely some kind of bug in the optimizer.

Interestingly the issue doesn't seem to happen on go 1.19.4, or if it does it's very rare. So perhaps some change in the scheduler is causing a race condition? I've tried building with -race but that hasn't popped up with anything.

Not sure if this project is still being maintained, but if so any help here would be much appreciated.