Fracnetics
Fracnetics is a high-performance C++ library with Python bindings for Genetic Network Programming (GNP) — an evolutionary approach that evolves directed graph structures for decision-making and control tasks.
Bridging evolution, networks, and fractals into one framework.
🔬 Overview
Fracnetics extends Genetic Network Programming (GNP) with variable-size networks and fractal geometry, designed to model adaptive, recursive, and self-similar network structures inspired by biological evolution and natural growth patterns.
It is designed for researchers and developers exploring:
- Evolutionary network design
- Obtain fully interpretable networks
- Training agents in dynamic environments
- Directed multigraph network architecture
- variable-size networks based on Fabian Köhnke and Christian Borgelt, 2025
- Complex systems with self-similar topology
🚀 Installation
pip install fracnetics
📓 Colab Tutorials
Small Tutorials Using Fracnetics
This notebooks demonstrate how to use the Fracnetics library to solve the CartPole environment problem from Gymnasium (a fork of OpenAI Gym) and the simple Irisdata classification.
🦾 Features
-
Population Management
- Create and manage a full population of
Networkindividuals. - Graph-Based Evolution: Networks evolve as directed graphs with judgment nodes (conditional decisions) and processing nodes (actions), enabling node reuse and cyclic execution paths
- Create and manage a full population of
-
Fitness Evaluation
- Built-in support for OpenAI Gymnasium environments
- Traverse a network path via
callTraversePathand calculate any own fitness/ target function
-
Selection & Elitism: Tournament selection with configurable size.
-
Mutation Operators
- Edge mutation (altering connections between nodes).
- Boundary mutations (multiple variants):
- Uniform
- Normally distributed
- Network-size dependent sigma scaling
- Edge-count dependent sigma scaling
- Fractal-based mutation
-
Crossover: Node exchange between individuals.
-
Innovative Opreators
- Add/Delete Nodes – dynamic structural changes in networks.
- Fractal Geometry Integration – hierarchical boundary generation via production rules (L-systems-style subdivision).
🔁 One Generation
The steps of a generation must run in this order; every step is optional:
pop.gymnasium(env, seeds=seeds, dMax=10, maxSteps=500, maxConsecutiveP=5) # evaluation
pop.callAgeUnusedNodes() # once
pop.tournamentSelection(N=5, E=1) # or lexicaseSelection(), once
pop.updateAdaptiveK()
pop.crossover(probability, type="caseSpecialistAppend") # once, before callAddDelNodes
pop.callAddDelNodes(minFeatures, maxFeatures, junk=0.1)
pop.crossover(probability, type="semantic")
pop.callEdgeMutation(0.05, 0.05) # mutations in any order
pop.callBoundaryMutationNormal(0.05, 0.2)
pop.capLineageAfterMutation()
The evaluation writes the node usage flags and the fitness that the later steps read, and
every change to the networks makes them stale: callAddDelNodes() after a mutation could
delete a node that has just become active, a selection after a crossover compares fitness
values of networks that no longer exist. The population therefore raises a RuntimeError
for a step out of order until the next evaluation. gymnasium(), callTraversePath(),
accuracy() and ParallelEvaluator.evaluate() count as evaluations; after an evaluation of
your own call pop.markEvaluated(). To call single operators on purpose (e.g. in tests), set
pop.checkOrder = False.
🏆 Hall of Fame for Noisy Evaluations
With stochastic episodes the training fitness on a few cases ranks the population poorly.
HallOfFame re-scores the best candidates and the current champion on the same fresh cases
every generation; the winner becomes the champion, and the round order fills the elite slots
after the selection. With memory=True the champion accumulates its scores, and a round
winner must confirm on further fresh cases before it takes over.
from fracnetics.hall_of_fame import HallOfFame
from fracnetics.parallel_eval import ParallelEvaluator
evaluator = ParallelEvaluator(env, popKwargs)
evaluate = lambda target, cases: evaluator.evaluate(target, seeds=cases, maxSteps=1000)
hof = HallOfFame(popKwargs, evaluate, candidates=10, memory=True, retestCases=100)
for g in range(generations):
evaluate(pop, trainingSeeds(g))
hof.update(pop, drawFreshSeeds(50), drawRetestCases=drawFreshSeeds) # between evaluation and selection
pop.lexicaseSelection(E=2, type="casesStandardized", epsilon=0.1)
hof.placeElites(pop) # right after the selection
... # crossover, growth, mutations
champion, score = hof.champion, hof.score
🎯 Data-Guided Boundary Mutation
A judgment node splits the declared range of its feature into intervals, but in practice it
judges only a small part of that range, so most boundaries never separate two values that
occur and most boundary mutations change nothing. Every evaluation therefore records, per
judgment node, the range of the values it judged (seenMin, seenMax), and over the node's
lifetime (everSeenMin, everSeenMax, inherited by offspring). With dataGuided=True the
uniform mutation redraws a boundary only inside its gap ∩ that range, and the normal mutation
scales its step with the range instead of the gap; everSeen=True uses the lifetime range.
The size-adaptive normal mutations (callBoundaryMutationNetworkSizeDependingSigma,
callBoundaryMutationEdgeSizeDependingSigma) take the same options, and the fractal
mutation lays its partition over the range (the outermost boundaries stay at the feature's
min/max). A boundary mutation acts on every boundary of a used node, also on boundaries far
outside the judged values, where a symmetric normal step only wanders without direction:
startInRange=True lets the normal step start from the nearest point of the range, so such
a boundary enters at the edge of the values.
pop.callBoundaryMutationNormal(probability=0, sigma=0.2, justUsedNodes=True, k=1,
dataGuided=True, everSeen=True, startInRange=True)
pop.callBoundaryMutationUniform(probability=0, justUsedNodes=True, k=1, dataGuided=True, everSeen=True)
pop.callBoundaryMutationFractal(probability=0, minF=minF, maxF=maxF, justUsedNodes=True, k=1,
dataGuided=True, everSeen=True) # with fractalJudgment=True
The fractal mutation redraws production-rule ratios, so its k counts ratios: k=1 redraws
about one ratio per network (rate k/N, N = mutable ratios of the eligible nodes).
Metadata
Release files for fracnetics 5.5.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| fracnetics-5.5.0.tar.gz | 1.9 MB | Without provenance | Details for fracnetics-5.5.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| fracnetics-5.5.0-cp311-cp311-macosx_26_0_x86_64.whl | CPython 3.11 | CPython 3.11 | macOS 26.0+ x86-64 | Details for fracnetics-5.5.0-cp311-cp311-macosx_26_0_x86_64.whl |
Total release size: 2.2 MB
Release files / fracnetics-5.5.0.tar.gz
| Download URL | fracnetics-5.5.0.tar.gz |
|---|---|
| Size | 1.9 MB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
1d3decd6aa23d2bce812387df1fce9cff314cf8d2bc3d0f440afa646ab3c478a
|
|
BLAKE2b-256 checksum How to use checksums |
874044b993acbe9213f374c57ca2feca346e596d96343af64fe23bdaf2fcefe7
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.11.2
|
Release files / fracnetics-5.5.0-cp311-cp311-macosx_26_0_x86_64.whl
| Download URL | fracnetics-5.5.0-cp311-cp311-macosx_26_0_x86_64.whl |
|---|---|
| Size | 285.5 kB |
| Tags | CPython 3.11 macOS 26.0+ x86-64 |
|
SHA-256 checksum How to use checksums |
76e6901289edb9b7f13aa2eab5c11d53f2ac85d71d49f5099ca15943b10736c8
|
|
BLAKE2b-256 checksum How to use checksums |
3e1a25a0046d70c893d75a70cd82d1c71beeb0b4609506627843f04f41c2195b
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.11.2
|
Security for fracnetics 5.5.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.