Getting started in Python Code
Dragonfly can beimported in python code via themaximise_function orminimise_function functions inthe main library.
The main APIs for Dragonfly are declared indragonfly/__init__.py and defined in thedragonfly/apis directory.For their definitions and arguments, seedragonfly/apis/opt.py anddragonfly/apis/moo.py.
You can import the main API in python code via,
from dragonfly import minimise_function, maximise_functionfunc = lambda x: x ** 4 - x**2 + 0.1 * xdomain = [[-10, 10]]max_capital = 100min_val, min_pt, history = minimise_function(func, domain, max_capital)print(min_val, min_pt)max_val, max_pt, history = maximise_function(lambda x: -func(x), domain, max_capital)print(max_val, max_pt)Here,func is the function to be maximised,domain is the domain over whichfunc is to be optimised,andmax_capital is the capital available for optimisation.In simple sequential settings,max_capital is simply the maximum number of evaluationstofunc, but it can also be used to specify an available time budget and other formsof resource constraints. Themaximise_function returns history along with the optimumvalueand the corresponding optimum point.history.query_points contains the points queried bythealgorithm andhistory.query_vals contains the function values.
The domain can be specified via a JSON file or in code.Seehere,here,here,here,here,here,here,here,andherefor more detailed examples.You can run them via, for example,
$ python examples/synthetic/branin/in_code_demo.py$ python examples/tree_reg/in_code_demo.py
Multiobjective optimisation
Similarly, you can import the multi-objective optimisation APIs in python code via,
from dragonfly import multiobjective_maximise_functions...pareto_max_values, pareto_points, history = multiobjective_maximise_functions(funcs, domain, max_capital)pareto_min_values, pareto_points, history = multiobjective_minimise_functions(funcs, domain, max_capital)Here,funcs is a list of functions to be maximised,domain is the domain andmax_capital is the capital available for optimisation.pareto_values are thePareto optimalfunction values andpareto_points are the corresponding points indomain.Seehereandherefor examples.
Neural Architecture Search
Dragonfly has APIs for defining neural network architectures, defining distancesbetween them, and also implements theNASBOT algorithm,which uses Bayesian optimisation and optimal transport for neural architecture search.You will first need to install the following dependencies.Cython will also requirea C++ library already installed in the system.
$ pip install cython POTBelow is an architecture search demo on a synthetic function.See theexamples/nas directory for demos of NASBOT in using some largedatasets.
$ cd examples$ dragonfly-script.py --config synthetic/syn_cnn_1/config.json --options options_files/options_example.txt