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
lon = sampler.sample_to_lon(rastrigin, domain)

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.1.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.1.0-py3-none-any.whl (21.9 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: lonkit-0.1.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.1.0.tar.gz
Algorithm Hash digest
SHA256 ac821d7902601d177b78ec96ece1c69f47c4d1811c366aa0f14c98df4fb516d0
MD5 a1faf7ec37ba6d540c966dfd00ec2568
BLAKE2b-256 6674ffb8d7336166a54ab500b76aab5eff0d70f762d8f64b7e28de252096e201

See more details on using hashes here.

Provenance

The following attestation bundles were made for lonkit-0.1.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.1.0-py3-none-any.whl.

File metadata

  • Download URL: lonkit-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 21.9 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.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 9fcb20f7f2cb462ef878fc91fcf195954f09086220f6bc1dfe6cf5023971e639
MD5 85f5a0f83ac2243ab4570536b5a450e4
BLAKE2b-256 a06e31d47bca2f00008e5c06ae02ab531713240008c4f6039a068881bf4ff47a

See more details on using hashes here.

Provenance

The following attestation bundles were made for lonkit-0.1.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