{"id":13413362,"url":"https://github.com/c-bata/goptuna","last_synced_at":"2025-04-04T23:09:53.800Z","repository":{"id":35845409,"uuid":"198627422","full_name":"c-bata/goptuna","owner":"c-bata","description":"A hyperparameter optimization framework, inspired by Optuna.","archived":false,"fork":false,"pushed_at":"2024-08-30T10:50:49.000Z","size":16171,"stargazers_count":265,"open_issues_count":19,"forks_count":22,"subscribers_count":9,"default_branch":"main","last_synced_at":"2025-03-28T22:14:05.977Z","etag":null,"topics":["bandit-algorithms","bayesian-optimization","blackbox-optimization","evolution-strategies"],"latest_commit_sha":null,"homepage":"https://pkg.go.dev/github.com/c-bata/goptuna","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/c-bata.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2019-07-24T12:03:05.000Z","updated_at":"2025-03-28T19:23:01.000Z","dependencies_parsed_at":"2024-11-30T14:02:00.725Z","dependency_job_id":"ade3d39e-10e7-451a-9b34-afaba2e3efcc","html_url":"https://github.com/c-bata/goptuna","commit_stats":{"total_commits":635,"total_committers":4,"mean_commits":158.75,"dds":0.06299212598425197,"last_synced_commit":"bf143026200bbb4105eb8bc604eae54cc634edd0"},"previous_names":[],"tags_count":16,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/c-bata%2Fgoptuna","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/c-bata%2Fgoptuna/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/c-bata%2Fgoptuna/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/c-bata%2Fgoptuna/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/c-bata","download_url":"https://codeload.github.com/c-bata/goptuna/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247261612,"owners_count":20910108,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["bandit-algorithms","bayesian-optimization","blackbox-optimization","evolution-strategies"],"created_at":"2024-07-30T20:01:38.620Z","updated_at":"2025-04-04T23:09:53.779Z","avatar_url":"https://github.com/c-bata.png","language":"Go","readme":"# Goptuna\n\n![Software License](https://img.shields.io/badge/license-MIT-brightgreen.svg?style=flat-square)\n[![GoDoc](https://godoc.org/github.com/c-bata/goptuna?status.svg)](https://godoc.org/github.com/c-bata/goptuna)\n[![Go Report Card](https://goreportcard.com/badge/github.com/c-bata/goptuna)](https://goreportcard.com/report/github.com/c-bata/goptuna)\n\nDecentralized hyperparameter optimization framework, inspired by [Optuna](https://github.com/optuna/optuna) [1].\nThis library is particularly designed for machine learning, but everything will be able to optimize if you can define the objective function\n(e.g. Optimizing the number of goroutines of your server and the memory buffer size of the caching systems).\n\n**Supported algorithms:**\n\nGoptuna supports various state-of-the-art Bayesian optimization, evolution strategies and Multi-armed bandit algorithms.\nAll algorithms are implemented in pure Go and continuously benchmarked on GitHub Actions.\n\n* Random search\n* TPE: Tree-structured Parzen Estimators [2]\n* CMA-ES: Covariance Matrix Adaptation Evolution Strategy [3]\n* IPOP-CMA-ES: CMA-ES with increasing population size [4]\n* BIPOP-CMA-ES: BI-population CMA-ES [5]\n* Median Stopping Rule [6]\n* ASHA: Asynchronous Successive Halving Algorithm (Optuna flavored version) [1,7,8]\n* Quasi-monte carlo sampling based on Sobol sequence [10, 11]\n\n**Projects using Goptuna:**\n\n* [Kubeflow/Katib: Kubernetes-based system for hyperparameter tuning and neural architecture search.](https://github.com/kubeflow/katib)\n* [c-bata/goptuna-bayesopt: Goptuna sampler for Gaussian Process based bayesian optimization using d4l3k/go-bayesopt.](https://github.com/c-bata/goptuna-bayesopt) [9]\n* [c-bata/goptuna-isucon9q: Applying bayesian optimization for the parameters of MySQL, Nginx and Go web applications.](https://github.com/c-bata/goptuna-isucon9q)\n* (If you have a project which uses Goptuna and want your own project to be listed here, please submit a GitHub issue.)\n\n\n## Installation\n\nYou can integrate Goptuna in wide variety of Go projects because of its portability of pure Go.\n\n```console\n$ go get -u github.com/c-bata/goptuna\n```\n\n## Usage\n\nGoptuna supports Define-by-Run style API like Optuna.\nYou can dynamically construct the search spaces.\n\n### Basic usage\n\n```go\npackage main\n\nimport (\n    \"log\"\n    \"math\"\n\n    \"github.com/c-bata/goptuna\"\n    \"github.com/c-bata/goptuna/tpe\"\n)\n\n// ① Define an objective function which returns a value you want to minimize.\nfunc objective(trial goptuna.Trial) (float64, error) {\n    // ② Define the search space via Suggest APIs.\n    x1, _ := trial.SuggestFloat(\"x1\", -10, 10)\n    x2, _ := trial.SuggestFloat(\"x2\", -10, 10)\n    return math.Pow(x1-2, 2) + math.Pow(x2+5, 2), nil\n}\n\nfunc main() {\n    // ③ Create a study which manages each experiment.\n    study, err := goptuna.CreateStudy(\n        \"goptuna-example\",\n        goptuna.StudyOptionSampler(tpe.NewSampler()))\n    if err != nil { ... }\n\n    // ④ Evaluate your objective function.\n    err = study.Optimize(objective, 100)\n    if err != nil { ... }\n\n    // ⑤ Print the best evaluation parameters.\n    v, _ := study.GetBestValue()\n    p, _ := study.GetBestParams()\n    log.Printf(\"Best value=%f (x1=%f, x2=%f)\",\n        v, p[\"x1\"].(float64), p[\"x2\"].(float64))\n}\n```\n\nLink: [Go Playground](https://play.golang.org/p/y95gek9UTPM)\n\nFurthermore, I recommend you to use RDB storage backend for following purposes.\n\n* Continue from where we stopped in the previous optimizations.\n* Scale studies to tens of workers that connecting to the same RDB storage.\n* Check optimization results via a built-in dashboard.\n\n\n### Built-in Web Dashboard\n\nYou can check optimization results by built-in web dashboard.\n\n* SQLite3: `$ goptuna dashboard --storage sqlite:///example.db` (See [here](./_examples/simple_rdb/check_sqlite3.sh) for details).\n* MySQL: `$ goptuna dashboard --storage mysql://goptuna:password@127.0.0.1:3306/yourdb` (See [here](./_examples/simple_rdb/check_mysql.sh) for details)\n\n| Manage optimization results | Interactive live-updating graphs |\n| --------------------------- | -------------------------------- |\n| \u003cimg width=\"750\" alt=\"state-of-the-art-algorithms\" src=\"https://user-images.githubusercontent.com/5564044/97099702-4107be80-16cf-11eb-9d97-f5ceec98ce52.gif\"\u003e | \u003cimg width=\"750\" alt=\"visualization\" src=\"https://user-images.githubusercontent.com/5564044/97099797-66e19300-16d0-11eb-826c-6977e3941fb0.gif\"\u003e |\n\n### Advanced Usage\n\n\u003cdetails\u003e\n\n\u003csummary\u003eParallel optimization with multiple goroutine workers\u003c/summary\u003e\n\n``Optimize`` method of ``goptuna.Study`` object is designed as the goroutine safe.\nSo you can easily optimize your objective function using multiple goroutine workers.\n\n```go\npackage main\n\nimport ...\n\nfunc main() {\n    study, _ := goptuna.CreateStudy(...)\n\n    eg, ctx := errgroup.WithContext(context.Background())\n    study.WithContext(ctx)\n    for i := 0; i \u003c 5; i++ {\n        eg.Go(func() error {\n            return study.Optimize(objective, 100)\n        })\n    }\n    if err := eg.Wait(); err != nil { ... }\n    ...\n}\n```\n\n[full source code](./_examples/concurrency/main.go)\n\n\u003c/details\u003e\n\n\u003cdetails\u003e\n\n\u003csummary\u003eDistributed optimization using MySQL\u003c/summary\u003e\n\nThere is no complicated setup to use RDB storage backend.\nFirst, setup MySQL server like following to share the optimization result.\n\n```console\n$ docker pull mysql:8.0\n$ docker run \\\n  -d \\\n  --rm \\\n  -p 3306:3306 \\\n  -e MYSQL_USER=goptuna \\\n  -e MYSQL_DATABASE=goptuna \\\n  -e MYSQL_PASSWORD=password \\\n  -e MYSQL_ALLOW_EMPTY_PASSWORD=yes \\\n  --name goptuna-mysql \\\n  mysql:8.0\n```\n\nThen, create a study object using Goptuna CLI.\n\n```console\n$ goptuna create-study --storage mysql://goptuna:password@localhost:3306/yourdb --study yourstudy\nyourstudy\n```\n\n```mysql\n$ mysql --host 127.0.0.1 --port 3306 --user goptuna -ppassword -e \"SELECT * FROM studies;\"\n+----------+------------+-----------+\n| study_id | study_name | direction |\n+----------+------------+-----------+\n|        1 | yourstudy  | MINIMIZE  |\n+----------+------------+-----------+\n1 row in set (0.00 sec)\n```\n\nFinally, run the Goptuna workers which contains following code.\nYou can execute distributed optimization by just executing this script from multiple server instances.\n\n```go\npackage main\n\nimport ...\n\nfunc main() {\n    db, _ := gorm.Open(mysql.Open(\"goptuna:password@tcp(localhost:3306)/yourdb?parseTime=true\"), \u0026gorm.Config{\n        Logger: logger.Default.LogMode(logger.Silent),\n    })\n    storage := rdb.NewStorage(db)\n    defer db.Close()\n\n    study, _ := goptuna.LoadStudy(\n        \"yourstudy\",\n        goptuna.StudyOptionStorage(storage),\n        ...,\n    )\n    _ = study.Optimize(objective, 50)\n    ...\n}\n```\n\nFull source code is available [here](./_examples/simple_rdb/main.go).\n\n\u003c/details\u003e\n\n\u003cdetails\u003e\n\n\u003csummary\u003eReceive notifications of each trials\u003c/summary\u003e\n\nYou can receive notifications of each trials via channel.\nIt can be used for logging and any notification systems.\n\n```go\npackage main\n\nimport ...\n\nfunc main() {\n    trialchan := make(chan goptuna.FrozenTrial, 8)\n    study, _ := goptuna.CreateStudy(\n        ...\n        goptuna.StudyOptionIgnoreObjectiveErr(true),\n        goptuna.StudyOptionSetTrialNotifyChannel(trialchan),\n    )\n\n    var wg sync.WaitGroup\n    wg.Add(2)\n    go func() {\n        defer wg.Done()\n        err = study.Optimize(objective, 100)\n        close(trialchan)\n    }()\n    go func() {\n        defer wg.Done()\n        for t := range trialchan {\n            log.Println(\"trial\", t)\n        }\n    }()\n    wg.Wait()\n    if err != nil { ... }\n    ...\n}\n```\n\n[full source code](./_examples/trialnotify/main.go)\n\n\u003c/details\u003e\n\n## Links\n\nReferences:\n\n* [1] [T. Akiba, S. Sano, T. Yanase, T. Ohta, and M. Koyama, Optuna: A Next-generation Hyperparameter Optimization Framework, KDD, 2019.](https://dl.acm.org/citation.cfm?id=3330701)\n* [2] [J. Bergstra, R. Bardenet, Y. Bengio, and B. Kégl, Algorithms for hyper-parameter optimization. NeurIPS, 2011.](https://papers.nips.cc/paper/4443-algorithms-for-hyper-parameter-optimization.pdf)\n* [3] [N. Hansen, The CMA Evolution Strategy: A Tutorial. arXiv:1604.00772, 2016.](https://arxiv.org/abs/1604.00772)\n* [4] [A. Auger and N. Hansen, A restart CMA evolution strategy with increasing population size, CEC, 2005.](https://sci2s.ugr.es/sites/default/files/files/TematicWebSites/EAMHCO/contributionsCEC05/auger05ARCMA.pdf)\n* [5] [N. Hansen, Benchmarking a BI-Population CMA-ES on the BBOB-2009 Function Testbed, GECCO Workshop, 2009.](https://hal.inria.fr/inria-00382093/document)\n* [6] [D. Golovin, B. Sonik, S. Moitra, G. Kochanski, J. Karro, and D.Sculley, Google Vizier: A service for black-box optimization. KDD, 2017.](http://www.kdd.org/kdd2017/papers/view/google-vizier-a-service-for-black-box-optimization)\n* [7] [K. Jamieson and T. Ameet, Non-stochastic best arm identification and hyperparameter optimization, AISTATS, 2016.](http://proceedings.mlr.press/v51/jamieson16.pdf)\n* [8] [L. Li, K. Jamieson, A. Rostamizadeh, E. Gonina, M. Hardt, B. Recht, and A. Talwalkar, Massively parallel hyperparameter tuning, arXiv:1810.05934, 2018.](https://arxiv.org/abs/1810.05934)\n* [9] [J. Snoek, H. Larochelle, and R. Adams. Practical Bayesian optimization of machine learning algorithms. NeurIPS, 2012.](https://arxiv.org/abs/1206.2944)\n* [10] [S. Joe and F. Y. Kuo, Remark on Algorithm 659: Implementing Sobol's quasirandom sequence generator, ACM Trans, 2003.](https://dl.acm.org/doi/10.1145/641876.641879)\n* [11] [S. Kucherenko, D. Albrecht, and A. Saltelli, Exploring multi-dimensional spaces: A comparison of latin hypercube and quasi monte carlo sampling techniques, arXiv:1505.02350, 2015.](https://arxiv.org/abs/1505.02350)\n\nPresentations:\n\n* :jp: [Goptuna Distributed Bayesian Optimization Framework at Go Conference 2019 Autumn](https://www.slideshare.net/c-bata/goptuna-distributed-bayesian-optimization-framework-at-go-conference-2019-autumn-187538495)\n\nBlog posts:\n\n* [Practical bayesian optimization using Goptuna](https://c-bata.medium.com/practical-bayesian-optimization-in-go-using-goptuna-edf97195fcb5).\n\nStatus:\n\n* [godoc.org](http://godoc.org/github.com/c-bata/goptuna)\n* [gocover.io](https://gocover.io/github.com/c-bata/goptuna)\n* [goreportcard.com](https://goreportcard.com/report/github.com/c-bata/goptuna)\n\n## License\n\nThis software is licensed under the MIT license, see [LICENSE](./LICENSE) for more information.\n","funding_links":[],"categories":["Machine Learning","AutoML","Profiling","Scheduling","机器学习","Relational Databases"],"sub_categories":["Search and Analytic Databases","Profiling","Advanced Console UIs","检索及分析资料库","SQL 查询语句构建库"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fc-bata%2Fgoptuna","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fc-bata%2Fgoptuna","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fc-bata%2Fgoptuna/lists"}