Metadata-Version: 2.4
Name: evonet
Version: 0.3.0
Summary: Evolvable neural network core for integration with EvoLib
Author-email: EvoLib <evolib@dismail.de>
License: MIT License
        
        Copyright (c) 2025 EvoLib
        
        Permission is hereby granted, free of charge, to any person obtaining a copy
        of this software and associated documentation files (the "Software"), to deal
        in the Software without restriction, including without limitation the rights
        to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
        copies of the Software, and to permit persons to whom the Software is
        furnished to do so, subject to the following conditions:
        
        The above copyright notice and this permission notice shall be included in all
        copies or substantial portions of the Software.
        
        THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
        IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
        FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
        AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
        LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
        OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
        SOFTWARE.
        
Classifier: Development Status :: 5 - Production/Stable
Classifier: License :: OSI Approved :: MIT License
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.12
Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
Requires-Python: >=3.12
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: numpy>=1.24
Requires-Dist: pyyaml>=6.0
Requires-Dist: pydantic>=2.7
Requires-Dist: graphviz>=0.20.1
Provides-Extra: dev
Requires-Dist: mypy; extra == "dev"
Requires-Dist: types-PyYAML; extra == "dev"
Provides-Extra: docs
Requires-Dist: sphinx; extra == "docs"
Requires-Dist: sphinx-rtd-theme; extra == "docs"
Requires-Dist: myst-parser; extra == "docs"
Dynamic: license-file

# EvoNet

[![Code Quality & Tests](https://github.com/EvoLib/evo-net/actions/workflows/ci.yml/badge.svg)](https://github.com/EvoLib/evo-net/actions/workflows/ci.yml)
[![License: MIT](https://img.shields.io/badge/license-MIT-green.svg)](LICENSE)
[![Project Status: Stable](https://img.shields.io/badge/status-stable-green.svg)](https://github.com/EvoLib/evo-net)

**EvoNet** is a modular and evolvable neural network core designed for integration
with [EvoLib](https://github.com/EvoLib/evo-lib).  
It supports dynamic topologies, recurrent connections, per-neuron activation, and
structural evolution, with explicit and deterministic behaviour.

---

## Scope

EvoNet is not a state-of-the-art or general-purpose deep learning framework.

It does not aim to compete with libraries such as PyTorch, TensorFlow, or JAX in terms
of performance, scalability, or training algorithms. Backpropagation, GPU acceleration,
and highly optimised tensor operations are outside the scope of this project.

Instead, EvoNet supports evolutionary algorithms, structural mutation, and
exploratory research, with a focus on transparent and explicit implementations rather
than performance optimisation or feature completeness.

---

## Overview

- Explicit neural network topology with inspectable structure  
- Support for recurrent connections and temporal dynamics
- Dynamic topology growth during evolution
- Per-neuron activations and stateful neuron dynamics
- Supports evolutionary and structural mutation methods
- Deterministic execution model with explicit state  

---

## Technical Highlights

- Explicit **layer / neuron / connection** objects
- Typed neuron roles (`INPUT`, `HIDDEN`, `OUTPUT`)
- Typed connection kinds (`STANDARD`, `RECURRENT`, …)
- Recurrent connections with integer delay buffers
- Per-neuron activation functions and local dynamics
- Deterministic forward execution (`calc()` = one time step)
- Runtime topology growth (add/remove neurons and connections)
- Structural mutation utilities (weights, biases, activations, topology)
- Deterministic weight & bias vectorization (`get_weights`, `set_weights`)
- YAML / JSON serialization of full topology and parameters
- Graphviz-based network visualization
- Lightweight Python implementation with small runtime dependency

---

## Quick Example

```python
from evonet import Nnet, NeuronRole

net = Nnet()
net.add_layer()  # Input layer
net.add_layer()  # Output layer

net.add_neuron(layer_idx=0, role=NeuronRole.INPUT, activation="linear", connection_init="none", label="in")
net.add_neuron(layer_idx=1, role=NeuronRole.OUTPUT, activation="linear", bias=0.5, label="out")

result = net.calc([1.0])
```

---

## Recurrent Connections & Delay

```python
from evonet import ConnectionType

net.add_connection(
    src,
    dst,
    weight=0.8,
    conn_type=ConnectionType.RECURRENT,
    delay=2,   # uses output from t-2
)
```

Semantics:

- delay = 1 → previous time step
- delay > 1 → buffered history
- delay = 0 is normalized to 1 for recurrent edges

A full reset (net.reset(full=True)) clears all delay buffers.

---

## Neuron Dynamics

Neuron behaviour is defined locally at the neuron level:

```python
net.add_neuron(
    layer_idx=1,
    activation="tanh",
    dynamics_name="leaky",
    dynamics_params={"alpha": 0.2},
)
```

Current built-in dynamics:

- standard – stateless activation
- leaky – leaky integrator using last_output

Dynamics are evaluated inside the neuron, not at network level.

---

## Structural Mutation Utilities

The evonet.mutation module provides mutation operators for:

- mutate weights / biases (Gaussian noise)
- mutate activations (global or layer-specific)
- add/remove random connections
- add/remove random hidden neurons
- control recurrent edge kinds (direct, lateral, indirect)
- neutral or near-zero initialization

EvoNet itself does not decide when or why to mutate — that logic belongs in
EvoLib.

---

## Serialization

Network topology, parameters, and configuration can be saved and restored:

```python
net.save("network.yaml")
net = Nnet.load("network.yaml")
```

Supported formats:

- YAML (recommended, human-readable)
- JSON (machine-friendly)

Serialization includes:
layers, neurons, activations, biases, dynamics, connections, types, and delays.

---

## Relationship to EvoLib

- EvoNet: execution, structure, state
- EvoLib: evolution strategy, fitness, mutation scheduling, environments

EvoNet is intentionally usable as a standalone library.
Evolutionary control, fitness evaluation, and mutation scheduling are provided by EvoLib.

---


## License

MIT License - see [MIT License](https://github.com/EvoLib/evo-net/tree/main/LICENSE).

