« Back to top page

Lévy Flight Sampler

A sampler based on Lévy-flight random walks. Lévy flights naturally balance local exploitation with occasional large jumps that escape local optima, mimicking the foraging strategy observed in many animals.

Class or Function Names

  • LevyFlightSampler

Overview

This sampler proposes new hyperparameter candidates by taking a Lévy-flight step from the current best trial. A Lévy flight is a random walk whose step lengths follow a heavy-tailed (Lévy stable) distribution: most steps are small, enabling fine local search, but occasional large steps jump far away, helping to escape shallow local optima.

The step is computed via the Mantegna algorithm, an efficient closed-form approximation of the Lévy stable distribution that requires only standard Gaussian random variates.

When to use

SituationRecommendation
Unimodal or smooth landscapes✅ Converges faster than random search
Multi-modal with many shallow optima✅ Large Lévy jumps escape local optima
Highly discontinuous / black-box⚠️ Pair with a large n_trials budget
Categorical-heavy search spaces⚠️ Categorical params fall back to random

Key parameters

ParameterDefaultEffect
beta1.5Tail heaviness of the Lévy distribution. Range (0, 2]; 2 ≈ Gaussian, 1 ≈ Cauchy
step_scale0.1Step size as a fraction of each parameter’s range
seedNoneRNG seed for reproducibility

Installation

pip install optunahub numpy

Or install dependencies directly from the registry:

pip install -r https://hub.optuna.org/samplers/levy_flight_sampler/requirements.txt

Example

import optuna
import optunahub


def objective(trial):
    x = trial.suggest_float("x", -5, 5)
    y = trial.suggest_float("y", -5, 5)
    return (x - 1.5) ** 2 + (y + 2.0) ** 2


mod = optunahub.load_module("samplers/levy_flight_sampler")
sampler = mod.LevyFlightSampler(beta=1.5, step_scale=0.1, seed=42)
study = optuna.create_study(sampler=sampler)
study.optimize(objective, n_trials=100)

print(study.best_params)
print(study.best_value)

See example.py for a full comparison against TPESampler on the Rosenbrock benchmark.

Algorithm Details

  1. Initialization — first two trials use random sampling to establish an initial best.
  2. Lévy step — for each parameter p with range [low, high]:
    • Draw u ~ N(0, σ²) and v ~ N(0, 1) using the Mantegna sigma for beta.
    • Step length = step_scale × (high − low) × u / |v|^(1/beta).
    • Clip new value to [low, high].
  3. FallbackCategoricalDistribution and unknown distributions use RandomSampler.

The Mantegna sigma is:

σ = ( Γ(1+β) · sin(πβ/2) / (Γ((1+β)/2) · β · 2^((β−1)/2)) )^(1/β)

References

Package
samplers/levy_flight_sampler
Author
Aditya Chopra
License
MIT License
Verified Optuna version
  • 3.6.0
  • 4.0.0
  • 4.8.0
Dependencies (.txt)
  • numpy
Last update
2026-04-20
Discussions & Issues
Create a discussion
Create a bug report