paulknysh / blackbox Goto Github PK
View Code? Open in Web Editor NEWA Python module for parallel optimization of expensive black-box functions
License: MIT License
A Python module for parallel optimization of expensive black-box functions
License: MIT License
It will freeze in Python 3. I suggest labeling the project Python 2.
Is there a way to limit parameters to integers only? I'm currently rounding the parameter in the objective function, but this leads to the same value being evaluated multiple times.
For a high dimensional problem, one naive approach is to calculate all the partial derivative in parallel then apply SGD or other algorithm. Have you compare this naive approach with your method, say in term of numbers of function calls and convergence rate.
Thank you for providing this very useful toolbox!
When I try to use it for my optimization problem, it starts out quite well but it raises an error after having evaluated around half of the batches:
File "/Users/philipp/miniconda3/lib/python3.6/site-packages/black_box/blackbox.py", line 106, in search_min
points[n+batch*i:n+batch*(i+1), -1] = list(e.map(f, list(map(cubetobox, points[n+batch*i:n+batch*(i+1), 0:-1]))))/fmax
TypeError: unsupported operand type(s) for /: 'NoneType' and 'float'
It seems, that the map somehow returns a NoneType
. I couldn't find the reason for it. Do you have any suggestions?
Unfortunately, I can not provide a MWE, since my cost-function is a very advanced black-box.
The function is called with:
fit_par = bb.search_min(f=cost_function, domain=bounds_list, budget=50, batch=4, resfile = 'bb_output.csv')
Tried this on a Linux and MacOs Machine.
I am working in a anaconda environment with
Python 3.7.9
black-box 1.0.2
Upon further investigation I discorvered, that there is a nan
appearing at the last position of all the sublists in the points
list. Could this be the problem and how could this have happened?
For completeness, my domain
is
[[1000000000.0, 30000000000.0],
[1000000000.0, 30000000000.0],
[2e+18, 5e+18],
[-1e-07, 3e-07],
[10000.0, 100000.0],
[-5000.0, 5000.0],
[10000.0, 100000.0],
[-5000.0, 5000.0]]
It could be a good idea to have a pool
argument which take an object with a map
method.
That way, it will be easy to use other multiprocessing tools like ipyparallel, dask.distributed or pathos.
See abcpmc for a similar implementation.
Hello Paul.
Is it possible to pass function arguments to the solver?
For example, my function is defined as:
def func(x,*parms):
And then with the scipy minimize I can pass the parameters with the args= argument:
minimize(func, Initial_Guesses, method = 'SLSQP', bounds = Bounds, args=Parms )
I looked at the code but did not see a way to pass this argument.
Thanks
Thanks for a great piece of code! Have you considered typing it?
That would make it easier to use and to improve on :)
Hello Paul,
Thank you for this nice piece of code ๐
Is it possible to feed the algorithm with an initial guess ? Or can you think of some clues to implement this ?
So I have a really long running function, and as a result, I am exploring a broad range of parameter settings (n is large, m is 0). But if it turns out I am not happy with the exploratory performance of this sweep, then I would like to go back, use those results, and run again to explore points near the top performers (n = 0, m is large).
My objective function execution time is quite variable. This means nodes in the cluster (once there is a cluster) will be idle a lot of the time.
Is there a way to improve this?
It is obviously trivial to fix it for the first pass, but not for the second pass...
The sample code from the readme fails on my Python 3.10.5 install.
result = bb.minimize(f=fun, # given function
domain=[[-5, 5], [-5, 5]], # ranges of each parameter
budget=20, # total number of function calls available
batch=4 # number of calls that will be evaluated in parallel
)
print(result["best_x"])
print(result["best_f"])
Leads to:
INFO evaluating batch 1/5 (samples 1..4/20) 10-06 10:54:00
INFO evaluating batch 2/5 (samples 5..8/20) 10-06 10:54:04
INFO evaluating batch 3/5 (samples 9..12/20) 10-06 10:54:09
Traceback (most recent call last):
File "Optimierung_Logistikkosten_BlackBox.py", line 273, in <module>
main()
File "Optimierung_Logistikkosten_BlackBox.py", line 208, in main
result = bb.minimize(f=fun, # given function
File "\blackbox\blackbox.py", line 86, in minimize
v1 = compute_volume_unit_ball(d)
File "\blackbox\blackbox.py", line 165, in compute_volume_unit_ball
v1 = np.pi ** (d / 2) / np.math.factorial(d / 2)
TypeError: 'float' object cannot be interpreted as an integer
Note that I have redacted the path information.
I would like to use Blackbox as a part of my reactive-transport modeling tool for calibration. How would you like me to cite you in my Github project?
Does it support constrained optimization?
Hi,
This package is great. Have you considered uploading it on PyPi to make its use even easier?
Hi!
I have a hard function, that includes max
and min
and some conversions. I am getting the following error after few steps:
File "/home/vzinoviev/ttf_DALI/training_toolbox/ssd_detector/blackbox_opt.py", line 124, in <module>
main()
File "/home/vzinoviev/ttf_DALI/training_toolbox/ssd_detector/blackbox_opt.py", line 113, in main
resfile='output.csv') # text file where results will be saved
File "/home/vzinoviev/ttf_DALI/training_toolbox/ssd_detector/blackbox.py", line 123, in search
fit = rbf(points, T)
File "/home/vzinoviev/ttf_DALI/training_toolbox/ssd_detector/blackbox.py", line 212, in rbf
sol = np.linalg.solve(M, v)
File "/home/vzinoviev/ttf_DALI/venv/lib/python3.6/site-packages/numpy/linalg/linalg.py", line 390, in solve
r = gufunc(a, b, signature=signature, extobj=extobj)
File "/home/vzinoviev/ttf_DALI/venv/lib/python3.6/site-packages/numpy/linalg/linalg.py", line 89, in _raise_linalgerror_singular
raise LinAlgError("Singular matrix")
numpy.linalg.linalg.LinAlgError: Singular matrix```
Hello.
I am running some simulations and I am trying to optimize for some parameter. The simulation fails sometimes when I give a large value of m, n (say m=n=100) by giving an error related to a singular matrix. I want to find out for what parameters I am getting this singular matrix. Is there any way I can find the parameters for which the optimization is failing? It would work for me even if I can store all the parameters before optimization crashes due to a singular matrix error for a particular scenario. Thanks.
I replaced Monte Carlo (for minimizing fit) with a SLSQP method from scipy.optimize library. The code now should be able to handle high dimensional cases.
Let me know if there are any issues.
I'm looking for an adaptation of your method to allow joint constraints on parameters, not individually (i.e. range of value for each params).
For instance:
param1 + param2 + param3 <1
0<param1<1
0<param2<1
0<param3<1
I can constraint range values of param1, param2 and param3 in [0, 1] but not the sum ?
Thank you
Hello,
Do you have a comparison with scipy's minimize function (https://docs.scipy.org/doc/scipy-0.18.1/reference/generated/scipy.optimize.minimize.html#scipy.optimize.minimize), maybe even using the different methods?
I have created a simulation (https://github.com/pedvide/simetuc) that takes from 1s to maybe 1000s to solve. optimization of the few (1-5) free parameters is painfully slow for the longer simulations, so I'm interested in any improvement!
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.