Skip to content

lonpy

Local Optima Networks for Continuous Optimization

lonpy

lonpy is a Python library for constructing, analyzing, and visualizing Local Optima Networks (LONs) for continuous optimization problems.

What are Local Optima Networks?

Local Optima Networks (LONs) are graph-based models that capture the global structure of fitness landscapes. They help researchers and practitioners understand:

  • Landscape topology: How local optima are distributed and connected
  • Search difficulty: Whether the landscape has a single funnel or multiple competing basins
  • Algorithm behavior: How optimization algorithms navigate between local optima

Key Features

  • Basin-Hopping Sampling


    Efficient exploration of fitness landscapes using configurable Basin-Hopping with customizable perturbation strategies

  • LON Construction


    Automatic construction of Local Optima Networks from sampling data with support for both LON and CMLON representations

  • Rich Metrics


    Compute landscape metrics including funnel analysis, neutrality measures, and global optima strength

  • Beautiful Visualizations


    2D and 3D plots with support for animated GIFs showing the landscape structure

Quick Example

import numpy as np
from lonpy import compute_lon, LONVisualizer

# Define the Rastrigin function
def rastrigin(x):
    return 10 * len(x) + np.sum(x**2 - 10 * np.cos(2 * np.pi * x))

# Build the LON
lon = compute_lon(
    rastrigin,
    dim=2,
    lower_bound=-5.12,
    upper_bound=5.12,
    n_runs=20,
    seed=42
)

# Analyze
metrics = lon.compute_metrics()
print(f"Found {lon.n_vertices} local optima")
print(f"Landscape has {metrics['n_funnels']} funnels")

# Visualize
viz = LONVisualizer()
viz.plot_3d(lon, output_path="landscape.png")

Installation

pip install lonpy

Next Steps