Skip to main content

ctrl-freak

PyPI Python License

An extensible genetic algorithm framework for single and multi-objective optimization, built on pure numpy.

Installation

uv add ctrl-freak

or:

pip install ctrl-freak

Quick Start

import numpy as np
from ctrl_freak import nsga2, ga

# === Multi-Objective: NSGA-II ===
def init(rng):
    return rng.uniform(0, 1, size=5)

def evaluate_multi(x):
    f1 = x[0]
    f2 = 1 - np.sqrt(x[0]) + x[1:]@x[1:]
    return np.array([f1, f2])

def crossover(p1, p2):
    return (p1 + p2) / 2

def mutate(x):
    return np.clip(x + np.random.normal(0, 0.1, size=x.shape), 0, 1)

result = nsga2(
    init=init,
    evaluate=evaluate_multi,
    crossover=crossover,
    mutate=mutate,
    pop_size=100,
    n_generations=50,
    seed=42,
)

# Extract Pareto front
pareto_front = result.pareto_front
print(f"Found {len(pareto_front)} Pareto-optimal solutions")

# === Single-Objective: Standard GA ===
def evaluate_single(x):
    return float(np.sum(x ** 2))  # Sphere function

result = ga(
    init=init,
    evaluate=evaluate_single,
    crossover=crossover,
    mutate=mutate,
    pop_size=100,
    n_generations=100,
    seed=42,
)

print(f"Best fitness: {result.best[1]:.6f}")

Features

  • Single-objective optimization with ga().
  • Multi-objective optimization with nsga2().
  • Pluggable parent-selection and survival strategies.
  • Pure numpy primitives for Pareto dominance, non-dominated sorting, and crowding distance.
  • Parallel evaluation through n_workers.

See the full documentation for API details, user contracts, examples, and extension points.

Benchmarks

ctrl-freak ships a validation benchmark suite that checks ga() and nsga2() against pymoo and DEAP on standard problems with known optima. With the genetic algorithm held identical across all three libraries (ported SBX, aligned mutation and selection, identical evaluation budget), ctrl-freak's results are statistically indistinguishable from both baselines on the single-objective error metrics (all six functions) and on multi-objective convergence (ZDT1, ZDT2, ZDT3, and DTLZ2). On the two hardest problems (ZDT4, ZDT6) none of the three libraries converges at this budget, and ctrl-freak is at least as good as both. The goal is parity, not superiority.

See the canonical report in benchmarks/README.md and the citable Validation page.

Links

Download files

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

Source Distribution

ctrl_freak-0.2.1.tar.gz (24.7 kB view details)

Uploaded Source

Built Distribution

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

ctrl_freak-0.2.1-py3-none-any.whl (38.3 kB view details)

Uploaded Python 3

File details

Details for the file ctrl_freak-0.2.1.tar.gz.

File metadata

  • Download URL: ctrl_freak-0.2.1.tar.gz
  • Upload date:
  • Size: 24.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.9.0

File hashes

Hashes for ctrl_freak-0.2.1.tar.gz
Algorithm Hash digest
SHA256 e3a2cd6c452c386541090b7146aa0936027922ac9bda55edde7e0b76d54acf72
MD5 572459f3d41cf2fef787b0c6de037ed9
BLAKE2b-256 ad6ffceacccc7b7141c0f072096857417861ac7295d87eab998f0b777ec098d6

See more details on using hashes here.

File details

Details for the file ctrl_freak-0.2.1-py3-none-any.whl.

File metadata

  • Download URL: ctrl_freak-0.2.1-py3-none-any.whl
  • Upload date:
  • Size: 38.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.9.0

File hashes

Hashes for ctrl_freak-0.2.1-py3-none-any.whl
Algorithm Hash digest
SHA256 7c659abd2b0705a2af90613d822adefa6dbe267164500111128061e2bb32378d
MD5 3f473840f89d4ad3ea89c404b5085e04
BLAKE2b-256 1cd9b1d3bdb264f5478ae0239c82a932c3272482817c1ce0c7492711207e6330

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 Sentry Error logging StatusPage Status page