bayesopt

package module
v0.0.0-...-3fa3062 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 29, 2020 License: MIT Imports: 4 Imported by: 0

README

goptuna-bayesopt

Goptuna sampler for Gaussian Process based bayesian optimization using d4l3k/go-bayesopt. This integration supports SuggestUniform API only.

package main

import (
	"log"
	"math"

	"github.com/c-bata/goptuna"
	bayesopt "github.com/c-bata/goptuna-bayesopt"
)

func objective(trial goptuna.Trial) (float64, error) {
	x1, _ := trial.SuggestUniform("x1", -10, 10)
	x2, _ := trial.SuggestUniform("x2", -10, 10)
	return math.Pow(x1-2, 2) + math.Pow(x2+5, 2), nil
}

func main() {
	relativeSampler := bayesopt.NewSampler()
	study, err := goptuna.CreateStudy(
		"goptuna-example",
		goptuna.StudyOptionRelativeSampler(relativeSampler),
	)
	if err != nil {
		log.Fatal("failed to create study:", err)
	}

	if err = study.Optimize(objective, 50); err != nil {
		log.Fatal("failed to optimize:", err)
	}

	v, _ := study.GetBestValue()
	params, _ := study.GetBestParams()
	log.Printf("Best evaluation=%f (x1=%f, x2=%f)",
		v, params["x1"].(float64), params["x2"].(float64))
}

License

This software is licensed under the MIT license, see LICENSE for more information.

Documentation

Overview

Goptuna integration for d4l3k/go-bayesopt, the library for Gaussian Process based Bayesian Optimization.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Sampler

type Sampler struct {
	// contains filtered or unexported fields
}

Sampler for Gaussian Process based Bayesian Optimization.

func NewSampler

func NewSampler(opts ...SamplerOption) *Sampler

Sampler returns the next search points

func (*Sampler) SampleRelative

func (s *Sampler) SampleRelative(
	study *goptuna.Study,
	trial goptuna.FrozenTrial,
	searchSpace map[string]interface{},
) (map[string]float64, error)

SampleRelative samples multiple dimensional parameters in a given search space.

type SamplerOption

type SamplerOption func(sampler *Sampler)

SamplerOption is a type of function to set change the option.

func SamplerOptionOptimizerOptions

func SamplerOptionOptimizerOptions(opts []bo.OptimizerOption) SamplerOption

SamplerOptionOptimizerOptions sets options for d4l3k/go-bayesopt's optimizer.

func SamplerOptionSeed

func SamplerOptionSeed(seed int64) SamplerOption

SamplerOptionSeed sets seed number.

Directories

Path Synopsis
examples
quadratic command

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL