# ZOOpt
**Repository Path**: boss-ding/ZOOpt
## Basic Information
- **Project Name**: ZOOpt
- **Description**: ZOOptZOOpt
- **Primary Language**: Unknown
- **License**: MIT
- **Default Branch**: master
- **Homepage**: None
- **GVP Project**: No
## Statistics
- **Stars**: 0
- **Forks**: 0
- **Created**: 2022-09-18
- **Last Updated**: 2022-09-19
## Categories & Tags
**Categories**: Uncategorized
**Tags**: None
## README
# ZOOpt
[](https://github.com/eyounx/ZOOpt/blob/master/LICENSE.txt) [](https://www.travis-ci.org/eyounx/ZOOpt) [](https://zoopt.readthedocs.io/en/latest/?badge=latest) [](https://codecov.io/gh/AlexLiuyuren/ZOOpt)
ZOOpt is a python package for Zeroth-Order Optimization.
Zeroth-order optimization (a.k.a. derivative-free optimization/black-box optimization) does not rely on the gradient of the objective function, but instead, learns from samples of the search space. It is suitable for optimizing functions that are nondifferentiable, with many local minima, or even unknown but only testable.
ZOOpt implements some state-of-the-art zeroth-order optimization methods and their parallel versions. Users only need to add several keywords to use parallel optimization on a single machine. For large-scale distributed optimization across multiple machines, please refer to [Distributed ZOOpt](https://github.com/eyounx/ZOOsrv).
**Documents**: [Tutorial of ZOOpt](http://zoopt.readthedocs.io/en/latest/index.html)
**Citation**:
> **Yu-Ren Liu, Yi-Qi Hu, Hong Qian, Chao Qian, Yang Yu. ZOOpt: Toolbox for Derivative-Free Optimization**. SCIENCE CHINA Information Sciences, 2022. [CORR abs/1801.00329](https://arxiv.org/abs/1801.00329)
(Features in this article are from version 0.2)
## Installation
The easiest way to install ZOOpt is to type `pip install zoopt` in the terminal/command line.
Alternatively, to install ZOOpt by source code, download this repository and sequentially run following commands in your terminal/command line.
```
$ python setup.py build
$ python setup.py install
```
## Quick tutorial for `Dimension2` class
Since release 0.4.1, `Dimension2` class in ZOOpt supports constructing THREE types of dimensions,
i.e.: `ValueType.CONTINUOUS`, `ValueType.DISCRETE`, and `ValueType.GRID`.
For **continuous dimensions**, the arguments should be like `(ValueType.CONTINUOUS, range, float_precision)`.
Where `ValueType.CONTINUOUS` indicates this dimension is continuous.
`range` is a list that indicates the search space, such as `[min, max]` (endpoints are inclusive).
`float_precision` means the precision of this dimension, e.g., if it is set to 1e-6, 0.001, or 10, the answer will be accurate to six decimal places, three decimal places, or tens places.
For **discrete dimensions**, the arguments should be like `(ValueType.DISCRETE, range, has_partial_order)`.
Where `ValueType.DISCRETE` indicates this dimension is discrete.
`range` is also a list that indicates the search space, such as `[min, max]` (endpoints are inclusive), but **ONLY integers can be sampled**.
`has_partial_order` means whether this dimension is ordered. `True` is for an ordered relation and `False` means not.
For **grid dimensions**, the arguments should be like `(ValueType.GRID, grid_list)`.
Where `ValueType.GRID` indicates this dimension is a grid, which is convenient to instance-wise search.
`grid_list` is a list whose values can be *str*, *int*, *float*, etc. All values in this list will be sampled like grid search.
For instance, you can define your own dimensions like:
```python
dim_list = [
(ValueType.CONTINUOUS, [-1, 1], 1e-6),
(ValueType.DISCRETE, [-10, 10], False),
(ValueType.DISCRETE, [10, 100], True),
(ValueType.GRID, [64, 128, 256, 512, 1024]),
(ValueType.GRID, ["relu", "leaky_relu", "tanh", "sigmoid"])
]
dim = Dimension2(dim_list)
```
## A simple example
We define the Ackley function for minimization (note that this function is for arbitrary dimensions, determined by the solution)
```python
import numpy as np
def ackley(solution):
x = solution.get_x()
bias = 0.2
value = -20 * np.exp(-0.2 * np.sqrt(sum([(i - bias) * (i - bias) for i in x]) / len(x))) - \
np.exp(sum([np.cos(2.0*np.pi*(i-bias)) for i in x]) / len(x)) + 20.0 + np.e
return value
```
Ackley function is a classical function with many local minima. In 2-dimension, it looks like (from wikipedia)
![]() |