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

Metadata

Release files for ctrl-freak 0.2.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for ctrl-freak 0.2.1
File Size Uploaded
ctrl_freak-0.2.1.tar.gz 24.7 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for ctrl-freak 0.2.1
File Interpreter ABI Platform
ctrl_freak-0.2.1-py3-none-any.whl Python 3 none any Details

Total release size: 63.0 kB

Release files / ctrl_freak-0.2.1.tar.gz

Download URL ctrl_freak-0.2.1.tar.gz
Size 24.7 kB
Tags Source
SHA-256 checksum
How to use checksums
e3a2cd6c452c386541090b7146aa0936027922ac9bda55edde7e0b76d54acf72
BLAKE2b-256 checksum
How to use checksums
ad6ffceacccc7b7141c0f072096857417861ac7295d87eab998f0b777ec098d6
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.9.0

Release files / ctrl_freak-0.2.1-py3-none-any.whl

Download URL ctrl_freak-0.2.1-py3-none-any.whl
Size 38.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
7c659abd2b0705a2af90613d822adefa6dbe267164500111128061e2bb32378d
BLAKE2b-256 checksum
How to use checksums
1cd9b1d3bdb264f5478ae0239c82a932c3272482817c1ce0c7492711207e6330
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.9.0

Release history Release notifications | RSS feed

This release

0.2.1 This release

2 release files

0.2.0

2 release files

0.1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page