Skip to main content

Local Optima Networks (LONs) for continuous optimization - Python implementation

Project description

lonkit

PyPI version Python 3.10+ Open In Colab

Local Optima Networks for Continuous Optimization

lonkit is a Python library for constructing, analyzing, and visualizing Local Optima Networks (LONs) for continuous optimization problems. LONs provide a powerful way to understand the structure of fitness landscapes, revealing how local optima are connected and how difficult it may be to find global optima.

Features

  • Basin-Hopping Sampling: Efficient exploration of fitness landscapes using configurable Basin-Hopping
  • LON Construction: Automatic construction of Local Optima Networks from sampling data
  • CMLON Support: Compressed Monotonic LONs for cleaner landscape analysis
  • Rich Metrics: Compute landscape metrics including funnel analysis and neutrality
  • Beautiful Visualizations: 2D and 3D plots with support for animated GIFs

Installation

pip install lonkit

Or install from source:

git clone https://github.com/helix-agh/lonkit.git
cd lonkit
pip install -e .

Quick Start

import numpy as np
from lonkit import compute_lon, LONVisualizer, BasinHoppingSamplerConfig

# Define an objective function
def rastrigin(x: np.ndarray) -> float:
    return 10 * len(x) + np.sum(x**2 - 10 * np.cos(2 * np.pi * x))

# Construct the LON
config = BasinHoppingSamplerConfig(
    n_runs=20,
    n_iter_no_change=500,
    seed=42
)
lon = compute_lon(
    rastrigin,
    dim=2,
    lower_bound=-5.12,
    upper_bound=5.12,
    config=config
)

metrics = lon.compute_metrics()
print(f"Number of funnels: {metrics['n_funnels']}")
print(f"Global funnels: {metrics['n_global_funnels']}")

# Visualize
viz = LONVisualizer()
viz.plot_2d(lon, output_path="lon_2d.png")
viz.plot_3d(lon, output_path="lon_3d.png")

Compressed Monotonic LONs (CMLONs)

CMLONs are a compressed representation where nodes with equal fitness that are connected get merged. This provides a cleaner view of the landscape's funnel structure.

# Convert LON to CMLON
cmlon = lon.to_cmlon()

# Analyze CMLON-specific metrics
cmlon_metrics = cmlon.compute_metrics()

Custom Sampling Configuration

from lonkit import BasinHoppingSampler, BasinHoppingSamplerConfig

config = BasinHoppingSamplerConfig(
    n_runs=50,                   # Number of independent runs
    n_iter_no_change=1000,       # Stop after this many consecutive non-improving perturbations
    step_size=0.05,              # Perturbation size
    step_mode="percentage",      # "percentage" or "fixed"
    coordinate_precision=4,      # Precision for identifying optima
    fitness_precision=None,      # Precision for fitness values (None = full double)
    seed=42                      # For reproducibility
)

sampler = BasinHoppingSampler(config)

# Define search domain
domain = [(-5.12, 5.12), (-5.12, 5.12)]

# Run sampling
result = sampler.sample(rastrigin, domain)
lon = sampler.sample_to_lon(result)

Documentation

For full documentation, visit: https://helix-agh.github.io/lonkit

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

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

lonkit-0.2.0.tar.gz (2.7 MB view details)

Uploaded Source

Built Distribution

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

lonkit-0.2.0-py3-none-any.whl (23.7 kB view details)

Uploaded Python 3

File details

Details for the file lonkit-0.2.0.tar.gz.

File metadata

  • Download URL: lonkit-0.2.0.tar.gz
  • Upload date:
  • Size: 2.7 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for lonkit-0.2.0.tar.gz
Algorithm Hash digest
SHA256 1f4710489d20760ffac5e845be1500383c7585cb7d51e956510e8f10952e081a
MD5 45af6f39c1c6474cd66b316efb8a3ab0
BLAKE2b-256 659e7a9387287404cfeeb1abe63de8bd25a9b3dd707d86f698029a3274309b69

See more details on using hashes here.

Provenance

The following attestation bundles were made for lonkit-0.2.0.tar.gz:

Publisher: publish.yml on helix-agh/lonkit

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file lonkit-0.2.0-py3-none-any.whl.

File metadata

  • Download URL: lonkit-0.2.0-py3-none-any.whl
  • Upload date:
  • Size: 23.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for lonkit-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 3914b5cd3206f784a9a0d78b6e2d60a4d2f6d11c8cc8bfdc4ed655231845aa1f
MD5 7f650483d4000a8390c62b714e621950
BLAKE2b-256 dc991c2f7a4723b550e2051b7751ab00efb97b815bcad76492dfa0cfc42a6111

See more details on using hashes here.

Provenance

The following attestation bundles were made for lonkit-0.2.0-py3-none-any.whl:

Publisher: publish.yml on helix-agh/lonkit

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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