[PYTHON] How to use discrete values as variables in Scipy optimize

What you want to solve (motivation)

I want to optimize using scipy optimize, but I didn't know how to input a variable that takes only integers such as the number of things, so in that memorandum

solution

I found the answer in the scipy formula. https://docs.scipy.org/doc/scipy-0.14.0/reference/generated/scipy.optimize.brute.html scipy.optimize.brute (Minimize a function over a given range by brute force.) Brute force means to force, and to search for the optimum value by brute force.

scipy.optimize.brute(func, ranges, args=(), Ns=20, full_output=0, finish=<function fmin at 0x2b45cb917e60>, disp=False) However, since this finish further optimizes the surrounding area after brute force, if this is set to None, only the grid defined in ranges will be calculated and the minimum position and the value at that time will be returned to finish. Masu So, if you use this to define slice () so that only integers like (slice (0,15,1), slice (0,10,1)) are taken in ranges, the minimum value is only an integer. To find.

Impressions

To be honest, I understand that you should use np.meshgrid and then use the for statement for brute force, but if it is provided as an API, unnecessary mistakes can be avoided. I think it's okay, so I'd like to use it conveniently.

Recommended Posts

How to use discrete values as variables in Scipy optimize
How to use variables in systemd Unit definition files
How to use classes in Theano
How to use SQLite in Python
How to use Mysql in python
How to use ChemSpider in Python
How to use PubChem in Python
How to use calculated columns in CASTable
[Introduction to Python] How to use class in Python?
How to access environment variables in Python
How to dynamically define variables in Python
How to use Anaconda interpreter in PyCharm
How to handle consecutive values in MySQL
How to use __slots__ in Python class
How to use regular expressions in Python
How to use Map in Android ViewPager
How to use is and == in Python
How to use the C library in Python
How to use Python Image Library in python3 series
Summary of how to use MNIST in Python
How to use tkinter with python in pyenv
How to output "Ketsumaimo" as standard output in Python
Use os.getenv to get environment variables in Python
How to use xml.etree.ElementTree
How to use Python-shell
How to use tf.data
How to use virtualenv
How to use Seaboan
How to use image-match
How to use shogun
How to use Virtualenv
How to use numpy.vectorize
How to use pytest_report_header
How to use partial
How to use Bio.Phylo
How to use SymPy
How to use x-means
How to use WikiExtractor.py
How to use virtualenv
How to use Matplotlib
How to use iptables
How to use numpy
How to use TokyoTechFes2015
How to use venv
How to use Pyenv
How to use list []
How to use python-kabusapi
How to use OptParse
How to use return
How to use dotenv
How to use pyenv-virtualenv
How to use Go.mod
How to use imutils
How to use import
[For beginners] How to use say command in python!
[Python] How to expand variables in a character string
A memorandum on how to use keras.preprocessing.image in Keras
How to use bootstrap in Django generic class view
How to use template engine in pyramid 1 file application
How to use the exists clause in Django's queryset
How to display DataFrame as a table in Markdown