I tried using Bayesian Optimization in Python

https://github.com/fmfn/BayesianOptimization

I tried using this Bayesian optimization. I needed a little ingenuity, so I'll leave it.

There is only maximize

optimizer.maximize(
    init_points=2,
    n_iter=3,
)

From the README. It seemed that only maximize was provided as an optimization method. What I wanted to do was optimize the search ranking (I want to hit at the top of the ranking), so I simply added a minus to the ranking and optimized it.

optimizer = BayesianOptimization(
    f=foo,
    pbounds=pbounds,
)

It means that the return value of this foo is negative. There may be a way on the maximize or ʻoptimizer` side, but I couldn't find it.

The arguments of the function to be optimized are limited

def foo(x, y):
    return -x ** 2 - (y - 1) ** 2 + 1

This is the function to be optimized.

pbounds = {'x': (2, 4), 'y': (-3, 3)}

It is a mechanism that gives a range of arguments like this and goes to find the optimum value in it. At my point, I wanted to give another argument like foo (x, y, z), and if I let maximize feed it as it is, an error occurred. As a countermeasure, I made z a global variable and forcibly passed it. I don't know if it's correct.

Precautions when determining the composite ratio of two values

This has nothing to do with Bayesian optimization, but when deciding the optimal composition ratio of x and y, I first wrote as follows.

def foo(a):
   return a*x+y 

so,

pbounds = {'a': (0, 100)}

What did you do? It's no good.

def foo(a):
   return a*x+(100-a)*y 

thus

pbounds = {'a': (0, 100)}

This worked.

Recommended Posts

I tried using Bayesian Optimization in Python
I tried Bayesian optimization!
[Python] I tried using OpenPose
I tried using TradeWave (BitCoin system trading in Python)
Bayesian optimization package GPyOpt in Python
I tried using Thonny (Python / IDE)
I tried Line notification in Python
[Python] I tried using YOLO v3
Python in optimization
I tried to make a stopwatch using tkinter in python
I tried to implement PLSA in Python
I tried to implement PLSA in Python 2
I tried using UnityCloudBuild API from Python
I tried to implement ADALINE in Python
I tried to implement PPO in Python
I tried using parameterized
I tried using argparse
I tried using mimesis
I tried using anytree
I tried using aiomysql
I tried Python> autopep8
I tried using coturn
I tried using Pipenv
I tried using matplotlib
I tried using "Anvil".
I tried using Hubot
I tried using ESPCN
I tried using openpyxl
I tried using Ipython
I tried using PyCaret
I tried using cron
I tried using ngrok
I tried using face_recognition
I tried using Jupyter
I tried using PyCaret
I tried using Heapq
I tried using doctest
I tried Python> decorator
I tried using folium
I tried using jinja2
I tried using folium
I tried using time-window
I implemented Robinson's Bayesian Spam Filter in python
vprof --I tried using the profiler for Python
I tried web scraping using python and selenium
I tried object detection using Python and OpenCV
I tried playing a typing game in Python
I tried simulating the "birthday paradox" in Python
I tried the least squares method in Python
I tried using mecab with python2.7, ruby2.3, php7
[Memo] I tried a pivot table in Python
I tried to implement TOPIC MODEL in Python
I tried reading a CSV file using Python
I tried using the Datetime module by Python
I tried non-blocking I / O Eventlet behavior in Python
I tried adding a Python3 module in C
I tried to implement selection sort in python
I tried to implement Bayesian linear regression by Gibbs sampling in python
I tried fp-growth with python
I tried scraping with Python
I wrote python in Japanese