Skip to main content

BERT mutation operator for EC-KitY genetic programming

Project description

BERT Mutation for EC-KitY Genetic Programming

eckity-bert-gp provides the BERT mutation operator for tree-based genetic programming in EC-KitY.

The operator is described in “BERT Mutation: Deep Transformer Model for Masked Uniform Mutation in Genetic Programming”, Mathematics 2025, 13(5), 779 (paper). It masks selected GP-tree nodes and uses a compact BERT masked-language model to sample replacements that preserve the required node arity.

Installation

pip install eckity-bert-gp

Public API

from eckity_bert_gp import BertMutation, BERTUniformMutation

BertMutation owns and trains the BERT policy. BERTUniformMutation adapts that policy to EC-KitY's genetic-operator interface.

Usage

The BERT model needs the function names, terminal names, fitness callback, and mappings back to the EC-KitY functions:

import numpy as np
from eckity.base.untyped_functions import f_add, f_div, f_mul, f_sub
from eckity_bert_gp import BertMutation, BERTUniformMutation

function_set = [f_add, f_sub, f_mul, f_div]
terminal_set = ["x", "y", "z"]
function_mappings = {function.__name__: function for function in function_set}

bert_model = BertMutation(
    operators_list=np.array(list(function_mappings)),
    constant_names=terminal_set,
    get_fitness_func=evaluator.evaluate_individual,
    context_size=256,
    word_embedding_dim=20,
    n_layers=1,
    n_attention_heads=1,
    function_mappings=function_mappings,
    higher_is_better=False,
)

bert_mutation = BERTUniformMutation(
    bert_model=bert_model,
    probability=1.0,
    node_probability=0.1,
)

Add bert_mutation to the EC-KitY subpopulation's operators_sequence.

  • get_fitness_func accepts an EC-KitY GP tree and returns its fitness.
  • function_mappings maps each function name used by BERT back to the callable stored in GP trees.
  • Terminal mappings default to the names supplied in constant_names.
  • probability controls whether the EC-KitY mutation operator runs.
  • node_probability controls the probability of masking each tree node.
  • context_size must be large enough for the longest tree representation expected during evolution.

The model is initialized locally from BertConfig; installing or constructing the operator does not download pretrained model weights.

Compatibility

  • Python 3.9 or newer
  • EC-KitY 0.4.x
  • NumPy 2.0.2 or newer
  • SciPy 1.13.0 or newer
  • PyTorch 2.7.1 or newer
  • Transformers 4.50.0 or newer
  • scikit-learn 1.5.0 or newer

These bounds are compatible with eckity-dnc and eckity-bert-ga; none of the three packages directly depends on another operator package.

Repository experiment

The repository includes the paper's experiment runner and datasets. They are development resources and are not included in the wheel.

Install the development dependencies and run the symbolic-regression example:

python -m pip install -e ".[dev]"
python runner.py

Additional benchmark data is stored under data/, and Artificial Ant maps are stored under ant_opt/.

Development

With uv:

uv sync --extra dev --resolution lowest-direct
uv run pytest
uv build

Release preparation and manual PyPI upload commands are documented in RELEASING.md.

License

This project is licensed under the BSD 3-Clause License. See LICENSE.

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

eckity_bert_gp-0.1.0.tar.gz (10.9 kB view details)

Uploaded Source

Built Distribution

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

eckity_bert_gp-0.1.0-py3-none-any.whl (9.9 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: eckity_bert_gp-0.1.0.tar.gz
  • Upload date:
  • Size: 10.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.0.0 CPython/3.10.20

File hashes

Hashes for eckity_bert_gp-0.1.0.tar.gz
Algorithm Hash digest
SHA256 878e6b513d2379aa36f919c242dd4faacc65645a18a47f2e2d1b3b288b4fbf33
MD5 701571444cdba770b2b9be2633de2cfc
BLAKE2b-256 af7fa6c76b74e648ec553674073c91f0c38fd9f0ff07f1480deaa8b5dfcf45e7

See more details on using hashes here.

File details

Details for the file eckity_bert_gp-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: eckity_bert_gp-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 9.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.0.0 CPython/3.10.20

File hashes

Hashes for eckity_bert_gp-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 6aa000ddbaab9914f1b26bb8ac782875ba5df1e293bcab071bac62a9c39b45d0
MD5 f97d6222cae95b09825e9f69b15b38c9
BLAKE2b-256 61d13a18d5b014fd470739af9442e7e8271866aaabf73a89313262181a00336a

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