Zeroth-order optimisation solvers with Gaussian and sphere random oracles
Project description
ZoSolvers
Zeroth-order optimisation solvers with Gaussian and sphere random oracles.
ZoSolvers provides gradient-free solvers for minimisation and minimax problems. When the gradient of the objective is unavailable — because the function is non-differentiable, comes from a black-box simulator, or is too expensive to differentiate — ZoSolvers estimates it using random directional perturbations.
📖 Full documentation: ZoSolvers Manual (PDF)
Install
pip install ZoSolvers
Requirements: Python ≥ 3.10, NumPy ≥ 2.2, Matplotlib ≥ 3.7
Features
- Two oracle types — Gaussian (
u ~ N(0, B⁻¹)) and sphere (uniform on the unit sphere), both with optional preconditioning via a precision matrixB - Four solvers — ZOGD, ZOEGm (minimisation), ZOGDA, ZOEGmm (minimax)
- Three finite-difference methods — forward, backward, centered
- Flexible mini-batching — fixed number of oracle samples per step, or a growing schedule (
t="iteration") - Constrained problems — pass any projection function
- Early stopping — based on relative function decrease or oracle norm
- Efficient sampling — Cholesky factorisation cached at construction; diagonal
Bhandled without matrix inversion
Quick Start
Minimisation
import numpy as np
from ZoSolvers.minimisation import ZO_gauss_min
def f(x):
return x[0]**2 + x[1]**2 + x[0]*x[1]
x0 = np.array([5.0, -5.0])
opt = ZO_gauss_min(f, x0, h=1e-2, mu=1e-5, N=2000, t=10)
# Zeroth-order gradient descent
x_traj = opt.ZOGD(method="center")
# Zeroth-order extra-gradient
x_traj = opt.ZOEGm(method="center", gamma=1.0)
Minimax
from ZoSolvers.minimax import ZO_gauss_minmax
def f(x, y):
return x[0]**2 + x[1]**2 - y[0]**2 - y[1]**2 + x[0]*y[1]
x0 = np.array([5.0, -5.0])
y0 = np.array([3.0, -3.0])
opt = ZO_gauss_minmax(f, x0, y0, h=1e-3, tau=1, mu=1e-8, N=10000, t=5)
# Gradient descent-ascent
x_traj, y_traj = opt.ZOGDA(method="center")
# Extra-gradient
x_traj, y_traj = opt.ZOEGmm(method="center", gamma=0.8)
Sphere Oracle and Precision Matrix
B = np.array([[10.0, 0.5],
[0.5, 2.0]])
opt = ZO_gauss_min(f, x0, h=1e-2, mu=1e-5, N=2000, t=10,
B=B, oracle_type="sphere")
x_traj = opt.ZOGD(method="center")
Box-Constrained Problem
proj = lambda x: np.clip(x, -3.0, 3.0)
opt = ZO_gauss_min(f, x0, h=1e-2, mu=1e-5, N=2000, t=10, proj=proj)
x_traj = opt.ZOGD(method="center")
Solvers
| Solver | Class | Problem | Description |
|---|---|---|---|
ZOGD |
ZO_gauss_min |
Minimisation | Zeroth-order gradient descent |
ZOEGm |
ZO_gauss_min |
Minimisation | Zeroth-order extra-gradient |
ZOGDA |
ZO_gauss_minmax |
Minimax | Zeroth-order gradient descent-ascent |
ZOEGmm |
ZO_gauss_minmax |
Minimax | Zeroth-order extra-gradient minimax |
Key Parameters
| Parameter | Description |
|---|---|
h |
Step size |
mu |
Smoothing parameter for finite differences |
N |
Maximum number of iterations |
t |
Oracle samples per step (int or "iteration" for growing schedule) |
B |
Precision matrix shaping the perturbation distribution (None = identity) |
oracle_type |
"gaussian" or "sphere" |
proj |
Projection onto the feasible set (None = unconstrained) |
tau |
(Minimax) Step-size ratio: x-step = h/tau, y-step = h |
gamma |
(Extra-gradient) Second-stride scale factor |
Package Structure
ZoSolvers/
├── src/ZoSolvers/
│ ├── minimisation.py # ZO_gauss_min
│ ├── minimax.py # ZO_gauss_minmax
│ └── utils.py # shared utilities
├── tests/
│ ├── min_test.py # pytest suite for minimisation
│ ├── minimax_test.py # pytest suite for minimax
│ ├── demo_min.py # minimisation demo with plots
│ └── demo_minimax.py # minimax demo with plots
├── Docs/
│ └── ZoSolvers_Manual.pdf
└── pyproject.toml
Running the Demos
poetry run python tests/demo_min.py
poetry run python tests/demo_minimax.py
Running the Tests
poetry run pytest tests/ -v
License
MIT
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file zosolvers-0.1.1.tar.gz.
File metadata
- Download URL: zosolvers-0.1.1.tar.gz
- Upload date:
- Size: 5.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/2.1.2 CPython/3.10.12 Linux/6.8.0-110-generic
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
bad0cfcf3a4191c691ae985b87fa54bfc8cab6c3364420b37627978428b44ffa
|
|
| MD5 |
65c91f8e42fc2bd5a80a67ab559778f7
|
|
| BLAKE2b-256 |
95fd0d05945f6d997a2694e8eb504e18f0bb7c50eba3f2e306d9b56afe3ca914
|
File details
Details for the file zosolvers-0.1.1-py3-none-any.whl.
File metadata
- Download URL: zosolvers-0.1.1-py3-none-any.whl
- Upload date:
- Size: 8.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/2.1.2 CPython/3.10.12 Linux/6.8.0-110-generic
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
186017c0275551bea52f913ae3ac505d6527325eb6425cd3e48bb0553b88a8e0
|
|
| MD5 |
32ba38cebadc6d502ef3ad634a670b2e
|
|
| BLAKE2b-256 |
8ff2871e838a5067f8472891a8aa0b431e37f8a93742ac093a2f3d971a7d6944
|