Skip to main content

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)


Features

  • Two oracle types — Gaussian (u ~ N(0, B⁻¹)) and sphere (uniform on the unit sphere), both with optional preconditioning via a precision matrix B
  • 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 B handled without matrix inversion

Installation

From wheel (system-wide):

pip install dist/zosolvers-0.1.0-py3-none-any.whl

From source with Poetry:

git clone https://github.com/amirali78frz/ZoSolvers.git
cd ZoSolvers
poetry install

Requirements: Python ≥ 3.10, NumPy ≥ 2.2, Matplotlib ≥ 3.7


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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

zosolvers-0.1.0.tar.gz (5.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

zosolvers-0.1.0-py3-none-any.whl (8.1 kB view details)

Uploaded Python 3

File details

Details for the file zosolvers-0.1.0.tar.gz.

File metadata

  • Download URL: zosolvers-0.1.0.tar.gz
  • Upload date:
  • Size: 5.8 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

Hashes for zosolvers-0.1.0.tar.gz
Algorithm Hash digest
SHA256 fdeaa6dc684a7261b6635eb85158bf2e8040d2f764d948be590d7dd3c9fd3831
MD5 734a50d5d904442381be1db191281b43
BLAKE2b-256 4bed64f1dc3bb1f546ce88c4040667e080aab6f3abc43b1cff8a3dce4f74492b

See more details on using hashes here.

File details

Details for the file zosolvers-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: zosolvers-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 8.1 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

Hashes for zosolvers-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 4e464cd793e75cc8240146a3b5d5d35967dfef835038b23984ca525f71cb661f
MD5 189725865f7784d96b2372ed03086965
BLAKE2b-256 d8fa1af134ec700daa94a9d6736ee196efad58c8f6035eff9d406fd3385a6e0f

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page