{"id":32191246,"url":"https://github.com/probprog/bopp","last_synced_at":"2025-12-12T01:21:25.574Z","repository":{"id":57713276,"uuid":"75326470","full_name":"probprog/bopp","owner":"probprog","description":"BOPP: Bayesian Optimization for Probabilistic Programs","archived":false,"fork":false,"pushed_at":"2017-11-09T19:06:35.000Z","size":422,"stargazers_count":114,"open_issues_count":2,"forks_count":18,"subscribers_count":7,"default_branch":"master","last_synced_at":"2025-10-22T01:35:39.539Z","etag":null,"topics":["bayesian-inference","bayesian-optimization","probabilistic-programming"],"latest_commit_sha":null,"homepage":"","language":"Clojure","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/probprog.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2016-12-01T19:41:57.000Z","updated_at":"2024-09-05T00:11:40.000Z","dependencies_parsed_at":"2022-09-05T22:50:22.734Z","dependency_job_id":null,"html_url":"https://github.com/probprog/bopp","commit_stats":null,"previous_names":["twgr/bopp"],"tags_count":4,"template":false,"template_full_name":null,"purl":"pkg:github/probprog/bopp","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/probprog%2Fbopp","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/probprog%2Fbopp/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/probprog%2Fbopp/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/probprog%2Fbopp/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/probprog","download_url":"https://codeload.github.com/probprog/bopp/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/probprog%2Fbopp/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":280365541,"owners_count":26318384,"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","status":"online","status_checked_at":"2025-10-21T02:00:06.614Z","response_time":58,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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":["bayesian-inference","bayesian-optimization","probabilistic-programming"],"created_at":"2025-10-22T01:35:45.580Z","updated_at":"2025-10-22T01:35:47.071Z","avatar_url":"https://github.com/probprog.png","language":"Clojure","readme":"# BOPP: Bayesian Optimization for Probabilistic Programs\n\nSee our [NIPS Spotlight video](https://www.youtube.com/watch?v=gVzV-NxKa9U) for TLDR.\n\nLatest release: bopp \"0.1.5\"\n\nBOPP is a package for automated marginal maximum a posteriori inference (MMAP) based around the\nprobabilistic programming system [Anglican](http://www.robots.ox.ac.uk/~fwood/anglican).  The\nuser only needs to write their model in the same manner as existing Anglican programs and by using\nthe `defopt` construct instead of `defquery`, select the variables to be optimized, with the\nrest marginalized out.  It can also be used as a means of exploiting the target source code\nto improve Bayesian optimization, delivering things such as automatic domain scaling,\nunbounded optimization, and implicit constraint satisfaction including equality constraints.\nThe key idea is to use a series of code transformations to extract from the original program\nall the things that are needed to carry out the MMAP problem, such as the target function itself\nand a program for optimizing the acquisition function subject to the implicit constraints.  These\nare then passed to our other package [Deodorant](http://github.com/probprog/deodorant), which uses\nthese to solve the problem probabilistic programs creates for BO.\nThe following paper should be referred to for full algorithmic details and we ask that you cite this paper if you\nuse BOPP in your work.\n\nRainforth, T., Le, T. A., van de Meent, J.-W., Osborne, M. A., \u0026 Wood, F. (2016). Bayesian Optimization for Probabilistic Programs. In Advances in Neural Information Processing Systems.\n\n```\n@incollection{rainforth2016bayesian,\n    title = {Bayesian Optimization for Probabilistic Programs},\n    author = {Rainforth, Tom and Le, Tuan Anh and van de Meent, Jan-Willem and Osborne, Michael A and Wood, Frank},\n    booktitle = {Advances in Neural Information Processing Systems 29},\n    pages = {280--288},\n    year = {2016},\n    url = {http://papers.nips.cc/paper/6421-bayesian-optimization-for-probabilistic-programs.pdf}\n}\n```\n\n## Installation ##\n\nTo use BOPP in your own [Leiningen](http://leiningen.org/) projects, just include the dependency in your `project.clj`:\n```\n(defproject foo\n  ...\n  :dependencies [...\n                 [bopp \"0.1.5\"]\n                 ...])\n```\n\nIn your Clojure files, remember to require functions from `core.clj`, e.g.:\n```\n(ns bar\n  (require [bopp.core :refer :all]))\n```\nThe full documentation can be found [here](https://probprog.github.io/bopp/). Checkout [core/defopt](https://probprog.github.io/bopp/bopp.core.html#var-defopt) and [core/doopt](https://probprog.github.io/bopp/bopp.core.html#var-doopt) in particular.\n\nThough BOPP currently runs of a snapshot of Anglican that means you don't need to install Anglican explicitly, is does have the same requirements in terms of java, Leiningen etc  and so we refer the reader to http://www.robots.ox.ac.uk/~fwood/anglican/usage/index.html and recommend that users follow section 2 in the user start up guide.  We also recommend that you familiarize yourself on the syntax of Anglican through the\nprovided link, as this is the same syntax as Anglican, with the addition of the forms `defopt` and `doopt`.\n\n## Usage ##\n\n### Defining target programs ###\n\nBOPP targets are specified using the macro `defopt`.  This is identical to `defquery` in [Anglican](http://www.robots.ox.ac.uk/~fwood/anglican) except that it takes as an extra input of the target variables to be optimized. BOPP will optimize the evidence of the program with respect to the variables, whilst marginalizing out over the others.\nFor example:\n\n```lisp\n(defopt simple-bimodal [y] [theta]\n  (let [x (sample (normal 0 1))\n        theta (sample (normal x 0.5))]\n    (observe (normal (sqrt (* theta theta)) 0.5) y)))\n```\n\nspecifies a model where we wish to optimize `theta`, marginalizing out `x`.  \n\nThere are a couple of small restrictions\non the programs that can be specified to ensure that they constitute valid target programs, namely:\n\n1. Each target variable must be bound to a value directly by a sample statement with fixed measure-type distribution argument (i.e. not a weird `defdist` distribution object).\n2. The program must be written such that any possible execution trace binds each optimization variable exactly once.\n3. Although any target variable may be lexically multiply bound, it must have the same base measure in all possible execution traces.\n\nDon't worry, if this doesn't make too much sense, BOPP catches violations of these automatically and gives you\nand error telling you what you violated. Please see the [paper](http://papers.nips.cc/paper/6421-bayesian-optimization-for-probabilistic-programs) and [supplementary material](http://www.robots.ox.ac.uk/~twgr/assets/pdf/rainforth2016BOPP.pdf) for more information.\n\n### Running BOPP ###\n\nCalling BOPP is super simple, just call\n\n`(doopt algorithm opt-query opt-query-args num-samples args)`\n\nwhere\n- `algorithm` = Inference algorithm used for estimating the marginal [`:smc`, `:pcascade`, `:importance`]\n- `opt-query` = Query to be optimized, defined by defopt.\n- `opt-query-args` = Fixed inputs of opt-query-args (y in earlier example)\n- `num-samples` = Number of samples for constructing the estimator of the marginal.\n- `args` = Optional arguments as key-value pairs.  See docstring for `doopt`. Note that, by default, \nthe arguments are setup for speed rather per iteration performance.  If you wish to run bopp as\nper the setup in the paper, or have a problem where the inference is particularly expensive, you\nshould include in the option list `:speed-option :careful`.\n\nThis returns a lazy infinite sequence of samples.  Call `take` on this will convert it\nto a fixed number of outputs.  Note that as BOPP is a GP based BO scheme, scaling in N is quite poor\nand practically limited to around 400-500.\n\n### Examples ###\n\nA number of worksheets are provided to give example usage in different cases.  These can be accessed in a Gorilla REPL by running\n`lein gorilla` from the base folder and going through worksheets in the `worksheets/` folder.  You can also see (but not run) an example worksheet without installing BOPP [here](http://www.robots.ox.ac.uk/~fwood/anglican/examples/viewer/?source=github\u0026user=probprog\u0026repo=bopp\u0026path=worksheets/chaos.clj).\n\n## License ##\n\nCopyright © Tom Rainforth, Tuan Anh Le, Jan-Willem van de Meent, Michael Osborne and Frank Wood\n\nBOPP is free software: you can redistribute it and/or modify\nit under the terms of the GNU General Public License as published by\nthe Free Software Foundation, either version 3 of the License, or\n(at your option) any later version.\n\nBOPP is distributed in the hope that it will be useful,\nbut WITHOUT ANY WARRANTY; without even the implied warranty of\nMERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\nGNU General Public License for more details.\n\nYou should have received a copy of the [GNU General Public License](gpl-3.0.txt) along with BOPP.  If not, see [http://www.gnu.org/licenses/](http://www.gnu.org/licenses/).\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fprobprog%2Fbopp","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fprobprog%2Fbopp","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fprobprog%2Fbopp/lists"}