Spearmint Bayesian optimization codebase

Overview

Spearmint

Spearmint is a software package to perform Bayesian optimization. The Software is designed to automatically run experiments (thus the code name spearmint) in a manner that iteratively adjusts a number of parameters so as to minimize some objective in as few runs as possible.

IMPORTANT: Spearmint is under an Academic and Non-Commercial Research Use License. Before using spearmint please be aware of the license. If you do not qualify to use spearmint you can ask to obtain a license as detailed in the license or you can use the older open source code version (which is somewhat outdated) at https://github.com/JasperSnoek/spearmint.

Relevant Publications

Spearmint implements a combination of the algorithms detailed in the following publications:

Practical Bayesian Optimization of Machine Learning Algorithms  
Jasper Snoek, Hugo Larochelle and Ryan Prescott Adams  
Advances in Neural Information Processing Systems, 2012  

Multi-Task Bayesian Optimization  
Kevin Swersky, Jasper Snoek and Ryan Prescott Adams  
Advances in Neural Information Processing Systems, 2013  

Input Warping for Bayesian Optimization of Non-stationary Functions  
Jasper Snoek, Kevin Swersky, Richard Zemel and Ryan Prescott Adams  
International Conference on Machine Learning, 2014  

Bayesian Optimization and Semiparametric Models with Applications to Assistive Technology  
Jasper Snoek, PhD Thesis, University of Toronto, 2013  

Bayesian Optimization with Unknown Constraints
Michael Gelbart, Jasper Snoek and Ryan Prescott Adams
Uncertainty in Artificial Intelligence, 2014

Setting up Spearmint

STEP 1: Installation

  1. Install python, numpy, scipy, pymongo. For academic users, the anaconda distribution is great. Use numpy 1.8 or higher. We use python 2.7.
  2. Download/clone the spearmint code
  3. Install the spearmint package using pip: pip install -e \</path/to/spearmint/root\> (the -e means changes will be reflected automatically)
  4. Download and install MongoDB: https://www.mongodb.org/
  5. Install the pymongo package using e.g., pip pip install pymongo or anaconda conda install pymongo

STEP 2: Setting up your experiment

  1. Create a callable objective function. See ./examples/simple/branin.py as an example
  2. Create a config file. There are 3 example config files in the ../examples directory. Note 1: There are more parameters that can be set in the config files than what is shown in the examples, but these parameters all have default values. Note 2: By default Spearmint assumes your function is noisy (non-deterministic). If it is noise-free, you should set this explicitly as in the ../examples/simple/config.json file.

STEP 3: Running spearmint

  1. Start up a MongoDB daemon instance:
    mongod --fork --logpath <path/to/logfile\> --dbpath <path/to/dbfolder\>
  2. Run spearmint: python main.py \</path/to/experiment/directory\>

STEP 4: Looking at your results
Spearmint will output results to standard out / standard err. You can also load the results from the database and manipulate them directly.

Comments
  • PESM acquisition function takes many times longer than PES

    PESM acquisition function takes many times longer than PES

    Hello,

    I would like to check if it is something to be expected that if I use PESM, it can take many hours to do 50 suggestions, while PES can do it in ca 10 minutes? or maybe it's one of the dependencies causing it? I had some trouble setting up PyGMO and NLOpt on Ubuntu 16.04 and downgraded my system to Ubuntu 14.04 on which everything seemed to compile fine.

    Thanks! Martin

    opened by martinsimon88 19
  • Problem installing Spearmint! and testing the branin example!

    Problem installing Spearmint! and testing the branin example!

    Dear all I'm a new user and trying to install Spearmint package for Bayesian optimization and I have problem using the software. My problem is with the third step that is mentioned in the site:

    STEP 3: Running spearmint

    1. Start up a MongoDB daemon instance: mongod --fork --logpath <path/to/logfile> --dbpath <path/to/dbfolder>
    2. Run spearmint: python main.py </path/to/experiment/directory>)

    I don't know where is the logpath and dbpath for mongod..... Would you please help me to install the package and run the branin example!

    Thank you in advance, Best wishes, Mohammad

    opened by Mehrian 15
  • Problem running branin.py as an example!

    Problem running branin.py as an example!

    Dear all I've installed the spearmint package and mongoDB on Linux. My problem is in the final step, where I want to run main.py for testing branin.py, first I go to this address ("Desktop/Spearmint-master/examples/distributed/") and execute the branin.py Then, in the same address I execute the command " mongod --fork --logpath --dbpath" everything is OK to this step! for running the main.py, first I go back to this address("Desktop/Spearmint-master/Spearmint") and when I execute the command I see the following error!

    Traceback (most recent call last): File "main.py", line 494, in main() File "main.py", line 249, in main options, expt_dir = get_options() File "main.py", line 216, in get_options expt_dir = os.path.realpath(os.path.expanduser(args[0])) IndexError: list index out of range

    I'm wondering where we have to define the branin parameters in the main.py ??? would you please help me to solve the error? Thank you in advance, Mohammad

    opened by Mehrian 11
  • ERROR: child process failed, exited with error number 100

    ERROR: child process failed, exited with error number 100

    Dear all I'm trying to test the branin.py on the cluster (On my laptop every thing is OK), and I have the following error when I try to start mongo using command ; "mongod --fork --logpath --dbpath".

    ERROR: child process failed, exited with error number 100

    I have to mention that, when I type "mongo" on the cluster it says:

    MongoDB shell version: 2.4.9 connecting to: test Server has startup warnings: Mon May 11 13:09:59.173 [initandlisten] Mon May 11 13:09:59.173 [initandlisten] ** WARNING: You are running on a NUMA machine. Mon May 11 13:09:59.173 [initandlisten] ** We suggest launching mongod like this to avoid performance problems: Mon May 11 13:09:59.173 [initandlisten] ** numactl --interleave=all mongod [other options] Mon May 11 13:09:59.173 [initandlisten]

    So, I tried starting mongo using command; "numactl --interleave=all mongod --fork --logpath --dbpath", but didn't see any difference in the output!

    Thanks, Mohammad

    opened by Mehrian 7
  • Is it possible to run Spearmint in some

    Is it possible to run Spearmint in some "manual" mode

    Hello,

    I have been using the Spearmint tool from another codebase (JasperSnoek/spearmint), and I usually use the spearmint-lite interface there. With that interface, I just need to run spearmint-lite.py and it will write the proposed hyperparam choice to a result file. I will then manually run my machine learning application with that proposed hyperparam choice and report back the loss to the result file, and run spearmint-lite.py again to get another proposed hyperparam choice.

    If I understand correctly, in this codebase, I can only talk with Spearmint with a callback python script (something like branin.py), and Spearmint will call branin.py to evaluate each hyperparam choice. Since it's very hard for me to launch my machine learning platform with a python script, and I would rather manually run each experiment, I'm wondering is there any way that I can manually run my experiments?

    Thank you very much!

    opened by cuihenggang 5
  • NaN crash

    NaN crash

    After several successful runs, it seems spearmint crashes with the following output:

    /Users/name/Desktop/external_libraries/Spearmint/spearmint/tasks/task.py:287: RuntimeWarning: invalid value encountered in subtract
      return y - mean
    Fitting GP for main task...
    Traceback (most recent call last):
     File "main.py", line 494, in <module>
       main()
     File "main.py", line 286, in main
       suggested_job = get_suggestion(chooser, resource.tasks, db, expt_dir, options, resource_name)
     File "main.py", line 355, in get_suggestion
       hypers = chooser.fit(task_group, hypers, task_options)
     File "/Users/name/Desktop/external_libraries/Spearmint/spearmint/choosers/default_chooser.py", line 309, in fit
       hypers=hypers.get(task_name, None)
     File "/Users/name/Desktop/external_libraries/Spearmint/spearmint/models/gp.py", line 505, in fit
       self._hypers_list = self._collect_samples(self.mcmc_iters)
     File "/Users/name/Desktop/external_libraries/Spearmint/spearmint/models/gp.py", line 378, in _collect_samples
       sampler.sample(self)
     File "/Users/name/Desktop/external_libraries/Spearmint/spearmint/sampling/slice_sampler.py", line 262, in sample
       params_array, current_ll = slice_sample(params_array, self.logprob, model, **self.sampler_options)
     File "/Users/name/Desktop/external_libraries/Spearmint/spearmint/sampling/mcmc.py", line 354, in slice_sample
       new_x, new_llh = direction_slice(direction, init_x)
     File "/Users/name/Desktop/external_libraries/Spearmint/spearmint/sampling/mcmc.py", line 289, in direction_slice
       llh_s = np.log(npr.rand()) + dir_logprob(0.0)
     File "/Users/name/Desktop/external_libraries/Spearmint/spearmint/sampling/mcmc.py", line 272, in dir_logprob
       return logprob(direction*z + init_x, *logprob_args)
     File "/Users/name/Desktop/external_libraries/Spearmint/spearmint/sampling/slice_sampler.py", line 240, in logprob
       lp += model.log_likelihood()
     File "/Users/name/Desktop/external_libraries/Spearmint/spearmint/models/gp.py", line 538, in log_likelihood
       solve = spla.cho_solve((chol, True), self.observed_values - self.mean.value)
     File "/usr/local/lib/python2.7/site-packages/scipy/linalg/decomp_cholesky.py", line 162, in cho_solve
       b1 = asarray_chkfinite(b)
     File "/usr/local/lib/python2.7/site-packages/numpy/lib/function_base.py", line 613, in asarray_chkfinite
       "array must not contain infs or NaNs")
    ValueError: array must not contain infs or NaNs
    

    My config file is as follows, if helpful:

    {
       "language": "PYTHON",
       "main-file": "stub_optimizing.py",
       "experiment-name": "swingy-monkey-optimization",
       "likelihood": "GAUSSIAN",
       "variables": {
           "height_bucket_div": {
               "type": "FLOAT",
               "size": 1,
               "min": 1,
               "max": 15
           },
           "width_bucket_div": {
               "type": "FLOAT",
               "size": 1,
               "min": 1,
               "max": 10
           },
           "vel_bucket_len": {
               "type": "FLOAT",
               "size": 1,
               "min": 1,
               "max": 30
           },
           "discount": {
               "type": "FLOAT",
               "size": 1,
               "min": 0,
               "max": 1
           },
           "greed_exp": {
               "type": "FLOAT",
               "size": 1,
               "min": 1,
               "max": 3
           }
       }
    }
    
    opened by mylesnovick 5
  • Does the

    Does the "actual value" of a discrete hyperparemeter matter?

    Hi, I'm trying to use Spearmint to optimize my hyperparameters for my machine learning task. I have one hyperparameter variable (among many other hyperparameters, say it's X) that stands for the type of my model (SVM, logistic regression, etc.). For example, if the X==0, it's SVM, and if X==1, it's logistic regression, etc.

    However, I find if I change the range of X, to make it start from 1, (X==1 means SVM, and X==2 means logistic regression), the behavior of Spearmint becomes quite different (i.e., it proposes quite different hyperparameter choices for me to try).

    Intuitively, the actual value range of X shouldn't matter. So I'm wondering is what I see expected, or I did something wrong?

    Thank you!

    opened by cuihenggang 4
  • this commit fixes #32: Simple Case of 1 Optimization Variable

    this commit fixes #32: Simple Case of 1 Optimization Variable

    This commit is a direct application of this idea: https://github.com/HIPS/Spearmint/issues/32#issue-95374628

    Tested on my own 1D problem and works well.

    opened by midak 4
  • Installation on Odyssey (Harvard Cluster) ?

    Installation on Odyssey (Harvard Cluster) ?

    Do folks either doing dev or just using spearmint at Harvard already have a stable installation set up? If so, can I soft link it or something? Or maybe there's a module built? I haven't found one using module avail, but I suppose I could request one via RC.

    opened by DanielNScott 4
  • Error when running 'constrained' example

    Error when running 'constrained' example

    Hi I get the following error when running the 'constrained' example using PESC using the latest origin/PESC code. All other examples appear to work fine for me. It appears to do a single fit but then produces errors when trying to identify the next point to search.

    I looked into the code and it seems model.options doesn't have a key 'binomial_trials'. Also model._one_minus_epsilon is not defined.

    Any help would be appreciated, Thanks.

    ##@##:~/Spearmint$ python spearmint/main.py examples/constrained/
    
    Getting suggestion for y_at_least_x, y_at_most_10, branin...
    
    
    Suggestion:     
                    NAME          TYPE       VALUE
                    ----          ----       -----
                    X             float      6.781006    
                    Y             float      11.715088   
    Submitted job 1 for tasks(s) y_at_least_x, y_at_most_10, branin with local scheduler (process id: 56519).
    Current time: 2015-08-02 17:55:27
    Status: 1 pending, 0 complete.
    ID(s) of pending job(s) for y_at_least_x, y_at_most_10, branin: 1
    Waiting for results...
    
    Fitting GP to 0 data for y_at_least_x task...
    Fitting GP to 1 data for NaN task...
    Fitting GP to 0 data for y_at_most_10 task...
    Fitting GP to 0 data for branin task...
    Computing current best...
    
    No feasible solution found (yet).
    
    Maximum total probability of satisfying constraints = 0.05659
      Probability of satisfying       y_at_least_x constraint: 0.33181
      Probability of satisfying                NaN constraint: 0.49298
      Probability of satisfying       y_at_most_10 constraint: 0.34597
    
    At location:    
                    NAME          TYPE       VALUE
                    ----          ----       -----
                    X             float      6.781006    
                    Y             float      11.715088   
    Traceback (most recent call last):
      File "spearmint/main.py", line 514, in <module>
        main()
      File "spearmint/main.py", line 339, in main
        recommendation = chooser.best()
      File "/Users/##/Spearmint/spearmint/choosers/default_chooser.py", line 820, in best
        val_o, loc_o = self.bestObservedConstrained()
      File "/Users/##/Spearmint/spearmint/choosers/default_chooser.py", line 1242, in bestObservedConstrained
        all_constraints_satisfied = np.all([self.constraintSatisfiedAtObservedInputs(c) for c in self.constraints], axis=0)
      File "/Users/##/Spearmint/spearmint/choosers/default_chooser.py", line 1295, in constraintSatisfiedAtObservedInputs
        sat = values/float(model.options['binomial_trials']) >= model._one_minus_epsilon
    KeyError: 'binomial_trials'
    
    opened by peterzh 4
  • add documentation, some code cleanup, and a bug fix

    add documentation, some code cleanup, and a bug fix

    After seeing Jasper Snoek talk in cambridge I was inspired to try this bayesian optimization package. It seems well written and well commented, but without much documentation. I had a some difficulty trying to understand what all the variables meant and what all the routines were doing. So while I was going through the code in detail I added some documentation for my own benefit. Maybe you guys will appreciate it. But please go over my documentation carefully. The only thing worse then no documentation is incorrect documentation.

    I also made some other changes.

    1. I did a bit of code cleanup, like removing tabs, removing unused imports, changing 2-space indents to 4-space, shortening long lines, etc.
    2. I added a new example for noisy functions. This is simply the branin function with some added noise.
    3. I added a file make_plots.py to the simple branin example. Using your README I was able to easily run the example, but I had no idea what to do then. I didn't know how to access the data or make predictions or find the best guess for the minimum, or show uncertainties. make_plots.py is basically my solution to that, though it may be a bit hacky. You may want to update it if there are more elegant ways of doing this. I wrote it in a general way so it can be called from any experiment directory with a 2-dimensional function (e.g. examples/noisy)
    4. I restructured main.py, separating out the part that reads in the options. I did this mostly because I wanted to re-use it for make_plots.py
    5. I renamed some variables because I found it really hard to know if variable tasks referred to a list of Task objects or a list of task names (strings). This confused me a lot and I only changed a few of the examples.

    Finally, thanks for the great code

    opened by js850 4
  • IndexError

    IndexError

    I want to use spearmint for my research work but I got this error when I tried to imitate the author by running the "python main.py"

    Traceback (most recent call last): File "main.py", line 494, in main() File "main.py", line 249, in main options, expt_dir = get_options() File "main.py", line 216, in get_options expt_dir = os.path.realpath(os.path.expanduser(args[0])) IndexError: list index out of range

    Again, I also want to Know how I can insert my data into spearmint, I want to optimize hyperparameters for time series regression. Thank you

    opened by edward-nketiah 0
  • license?

    license?

    Hi, I'd like to include spearmint here: https://www.microprediction.com/blog/optimize However can you clarify if people contributing to the open source prediction network can use it? The network is intended for any use at all including commercial use. Peter

    opened by microprediction 0
  • uncertainty

    uncertainty

    Hey, I was wondering in which file should I look for the uncertainty values around the expected value of the objective function (of fitted GP) so that I could print them through iterations? Thanks!

    opened by atefehmehrabi 0
  • testing with simple function

    testing with simple function

    i modified the examples/simple/brainin.py script to test a simple function x^2 + y^2. However, when i run main,py, it seems like it continues to optimize what that function was prior..

    opened by JadBatmobile 2
Owner
Formerly: Harvard Intelligent Probabilistic Systems Group -- Now at Princeton
Ryan Adams' research group. Formerly at Harvard, now at Princeton. New Github repositories here: https://github.com/PrincetonLIPS
Formerly: Harvard Intelligent Probabilistic Systems Group -- Now at Princeton
aka "Bayesian Methods for Hackers": An introduction to Bayesian methods + probabilistic programming with a computation/understanding-first, mathematics-second point of view. All in pure Python ;)

Bayesian Methods for Hackers Using Python and PyMC The Bayesian method is the natural approach to inference, yet it is hidden from readers behind chap

Cameron Davidson-Pilon 25.1k Jan 2, 2023
Bayesian-Torch is a library of neural network layers and utilities extending the core of PyTorch to enable the user to perform stochastic variational inference in Bayesian deep neural networks

Bayesian-Torch is a library of neural network layers and utilities extending the core of PyTorch to enable the user to perform stochastic variational inference in Bayesian deep neural networks. Bayesian-Torch is designed to be flexible and seamless in extending a deterministic deep neural network architecture to corresponding Bayesian form by simply replacing the deterministic layers with Bayesian layers.

Intel Labs 210 Jan 4, 2023
LBK 20 Dec 2, 2022
Simple, but essential Bayesian optimization package

BayesO: A Bayesian optimization framework in Python Simple, but essential Bayesian optimization package. http://bayeso.org Online documentation Instal

Jungtaek Kim 74 Dec 5, 2022
Bayesian optimization in PyTorch

BoTorch is a library for Bayesian Optimization built on PyTorch. BoTorch is currently in beta and under active development! Why BoTorch ? BoTorch Prov

null 2.5k Dec 31, 2022
Safe Bayesian Optimization

SafeOpt - Safe Bayesian Optimization This code implements an adapted version of the safe, Bayesian optimization algorithm, SafeOpt [1], [2]. It also p

Felix Berkenkamp 111 Dec 11, 2022
Bayesian Optimization using GPflow

Note: This package is for use with GPFlow 1. For Bayesian optimization using GPFlow 2 please see Trieste, a joint effort with Secondmind. GPflowOpt GP

GPflow 257 Dec 26, 2022
Information-Theoretic Multi-Objective Bayesian Optimization with Continuous Approximations

Information-Theoretic Multi-Objective Bayesian Optimization with Continuous Approximations Requirements The code is implemented in Python and requires

null 1 Nov 3, 2021
Bayesian Optimization Library for Medical Image Segmentation.

bayesmedaug: Bayesian Optimization Library for Medical Image Segmentation. bayesmedaug optimizes your data augmentation hyperparameters for medical im

Şafak Bilici 7 Feb 10, 2022
Genetic Algorithm, Particle Swarm Optimization, Simulated Annealing, Ant Colony Optimization Algorithm,Immune Algorithm, Artificial Fish Swarm Algorithm, Differential Evolution and TSP(Traveling salesman)

scikit-opt Swarm Intelligence in Python (Genetic Algorithm, Particle Swarm Optimization, Simulated Annealing, Ant Colony Algorithm, Immune Algorithm,A

郭飞 3.7k Jan 3, 2023
library for nonlinear optimization, wrapping many algorithms for global and local, constrained or unconstrained, optimization

NLopt is a library for nonlinear local and global optimization, for functions with and without gradient information. It is designed as a simple, unifi

Steven G. Johnson 1.4k Dec 25, 2022
Racing line optimization algorithm in python that uses Particle Swarm Optimization.

Racing Line Optimization with PSO This repository contains a racing line optimization algorithm in python that uses Particle Swarm Optimization. Requi

Parsa Dahesh 6 Dec 14, 2022
A general 3D Object Detection codebase in PyTorch.

Det3D is the first 3D Object Detection toolbox which provides off the box implementations of many 3D object detection algorithms such as PointPillars, SECOND, PIXOR, etc, as well as state-of-the-art methods on major benchmarks like KITTI(ViP) and nuScenes(CBGS).

Benjin Zhu 1.4k Jan 5, 2023
Official codebase for Pretrained Transformers as Universal Computation Engines.

universal-computation Overview Official codebase for Pretrained Transformers as Universal Computation Engines. Contains demo notebook and scripts to r

Kevin Lu 210 Dec 28, 2022
AOT-GAN for High-Resolution Image Inpainting (codebase for image inpainting)

AOT-GAN for High-Resolution Image Inpainting Arxiv Paper | AOT-GAN: Aggregated Contextual Transformations for High-Resolution Image Inpainting Yanhong

Multimedia Research 214 Jan 3, 2023
This is the codebase for Diffusion Models Beat GANS on Image Synthesis.

This is the codebase for Diffusion Models Beat GANS on Image Synthesis.

OpenAI 3k Dec 26, 2022
Official codebase for Decision Transformer: Reinforcement Learning via Sequence Modeling.

Decision Transformer Lili Chen*, Kevin Lu*, Aravind Rajeswaran, Kimin Lee, Aditya Grover, Michael Laskin, Pieter Abbeel, Aravind Srinivas†, and Igor M

Kevin Lu 1.4k Jan 7, 2023
Codebase for the Summary Loop paper at ACL2020

Summary Loop This repository contains the code for ACL2020 paper: The Summary Loop: Learning to Write Abstractive Summaries Without Examples. Training

Canny Lab @ The University of California, Berkeley 44 Nov 4, 2022