Skip to main content

PyPI version Python 3.14+ License GitHub issues CI

🧬 Pikaia

Welcome to Pikaia — a Python package for evolutionary algorithms, genetic programming, and AI-driven optimization. This package is designed for researchers, students, and practitioners interested in evolutionary computation and data analysis.


✨ Key Features

  • 🧬 Evolutionary simulation for data analysis
  • 📊 Built-in plotting and visualization
  • 🧩 Modular, extensible strategy system — 9 gene strategies (Dominant, Selfish, Kin-Altruistic, Altruistic, Reward Hard, Reward Easy, Valuation Blend, Sell, None) and 6 organism strategies (Balanced, Altruistic, Kin-Selfish, Selfish, Buy, None)
  • ⚡ D-matrix accelerated iteration mode — typically 30–80× faster than standard iterative mode
  • 📝 Jupyter notebook examples included
  • 🔬 Scientific approach, ready for research and teaching
  • ✅ 99% test coverage across the pikaia package

📚 Table of Contents


📖 Documentation

Resource Description
Tutorial Step-by-step first analysis — from raw data to ranked results
Overview Conceptual explanation: replicator equation, strategies, D-matrix
Contributor Guide How to add new strategies and extend pikaia
API Reference Auto-generated API docs

🚀 Installation

Install the package using pip:

pip install pikaia

(back to top)


🛠️ Local Development

For local development, we recommend using UV, a fast Python package installer and resolver.

Prerequisites

Clone the repository and navigate to the project directory:

git clone https://github.com/danube-ai/pikaia.git
cd pikaia

Install UV

Install UV using the official installer:

curl -LsSf https://astral.sh/uv/install.sh | sh

For more installation options, visit the UV installation guide.

Set up a Local Environment

  1. Create a virtual environment:

    uv venv
    
  2. Sync the dependencies (including development and notebook extras):

    uv sync --extra dev --extra examples
    
  3. Activate the virtual environment:

    source .venv/bin/activate
    

    This installs the package in editable mode along with tools for development (e.g., testing with pytest, linting with ruff) and Jupyter notebooks. The uv sync command ensures reproducible installations using the locked dependencies in uv.lock.

(back to top)


📝 Quickstart

Here's a minimal example to get you started:

import numpy as np
from pikaia.data import PikaiaPopulation
from pikaia.models import PikaiaModel
from pikaia.schemas import GeneStrategyEnum, OrgStrategyEnum, MixStrategyEnum
from pikaia.strategies import GeneStrategyFactory, OrgStrategyFactory, MixStrategyFactory

# Prepare a small dataset (3 samples, 3 features)
data_3x3_raw = np.array([[300, 10, 2], [600, 5, 2], [1500, 4, 1]])
data_min = data_3x3_raw.min(axis=0)
data_max = data_3x3_raw.max(axis=0)
data_3x3_scaled = (data_3x3_raw - data_min) / (data_max - data_min)
population = PikaiaPopulation(data_3x3_scaled)

# Define strategies
gene_strategies = [
    GeneStrategyFactory.get_strategy(GeneStrategyEnum.DOMINANT),
    GeneStrategyFactory.get_strategy(GeneStrategyEnum.ALTRUISTIC),
]
org_strategies = [
    OrgStrategyFactory.get_strategy(OrgStrategyEnum.BALANCED),
    OrgStrategyFactory.get_strategy(OrgStrategyEnum.SELFISH),
]
gene_mix_strategy = org_mix_strategy = MixStrategyFactory.get_strategy(MixStrategyEnum.FIXED)

# Create and fit the model
model = PikaiaModel(
    population=population,
    gene_strategies=gene_strategies,
    org_strategies=org_strategies,
    gene_mix_strategy=gene_mix_strategy,
    org_mix_strategy=org_mix_strategy,
    max_iter=32,
)
model.fit()

print("Gene fitness history:", model.gene_fitness_history)

For a significant speed-up on large populations, enable the D-matrix accelerated mode:

model = PikaiaModel(
    population=population,
    gene_strategies=gene_strategies,
    org_strategies=org_strategies,
    gene_mix_strategy=gene_mix_strategy,
    org_mix_strategy=org_mix_strategy,
    use_d_matrix=True,  # 30–80× faster for compatible strategy combinations
    max_iter=500,
)
model.fit()
  • Explore the examples/ directory for Jupyter notebooks, Python scripts, and data files.
  • See examples/README.md for a full index of all examples.
  • See examples/examples.ipynb for a hands-on walkthrough or run individual example scripts like python examples/example1.py.
  • See examples/paper_example.py for the paper example script.
  • See examples/d_matrix_comparison.py to benchmark all 40 strategy combinations with D-matrix acceleration.

(back to top)


🧬 Scientific Background

Genetic AI is a framework for evolutionary simulation and data analysis. In Genetic AI, a data problem is converted into a model of genes and organisms, and evolutionary simulations are run to gain insight into the input data.

  • Genetic AI does not use training data to 'learn', but instead autonomously analyzes a problem using evolutionary strategies that capture behaviors and correlations in the data.
  • This approach is useful for understanding complex datasets, optimization, and exploring emergent properties in data-driven systems.

Preprint: Genetic AI (arXiv)

(back to top)


👥 Authors & Contact

For questions, suggestions, or contributions, please feel free to open an issue or read our Contributing Guide. By participating you agree to our Code of Conduct.

(back to top)


📄 License

This project is licensed under the terms of the MIT License. See the LICENSE file for details.

(back to top)


📚 How to Cite

If you use Pikaia in your research, please cite our preprint:

@misc{wissgott2025geneticaievolutionarygames,
             title={Genetic AI: Evolutionary Games for ab initio dynamic Multi-Objective Optimization},
             author={Philipp Wissgott},
             year={2025},
             eprint={2501.19113},
             archivePrefix={arXiv},
             primaryClass={cs.NE},
             url={https://arxiv.org/abs/2501.19113},
}

(back to top)

Release files for pikaia 0.2.6

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

Source distribution (sdist)

Source distribution for pikaia 0.2.6
File Size Uploaded
pikaia-0.2.6.tar.gz 105.6 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for pikaia 0.2.6
File Interpreter ABI Platform
pikaia-0.2.6-py3-none-any.whl Python 3 none any Details

Total release size: 178.5 kB

Release files / pikaia-0.2.6.tar.gz

Download URL pikaia-0.2.6.tar.gz
Size 105.6 kB
Tags Source
SHA-256 checksum
How to use checksums
a13f5efd1389004e1af9f9785c81bd55c7b99f9b0a596414e85de2281105a9cb
BLAKE2b-256 checksum
How to use checksums
d6e744b0ef0ad6d77843a304045ca3f008ed9b3558abfac1ed47bcb26bf25723
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.13.13

Release files / pikaia-0.2.6-py3-none-any.whl

Download URL pikaia-0.2.6-py3-none-any.whl
Size 72.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
f3996bc0e65dda1dcc30dfb5b4849dca6024bfc6dcc1f56225f135d2dd2b3f75
BLAKE2b-256 checksum
How to use checksums
07bb68005bb4b7c4279b2adb53b7ad5d159f8663001599663f7c6c00e95a9757
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.13.13

Release history Release notifications | RSS feed

0.4.3

2 release files

0.4.2

2 release files

0.4.1

2 release files

0.4.0

2 release files

0.3.3

2 release files

0.3.2

2 release files

0.3.1

2 release files

0.3.0

2 release files

This release

0.2.6 This release

2 release files

0.2.4

2 release files

0.2.2

2 release files

0.2.1

2 release files

0.2.0

2 release files

0.1.0

2 release files

0.0.3

2 release files

0.0.2

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