🌟 TensorNEAT: Tensorized NEAT Implementation in JAX 🌟
## Introduction TensorNEAT is a JAX-based libaray for NeuroEvolution of Augmenting Topologies (NEAT) algorithms, focused on harnessing GPU acceleration to enhance the efficiency of evolving neural network structures for complex tasks. Its core mechanism involves the tensorization of network topologies, enabling parallel processing and significantly boosting computational speed and scalability by leveraging modern hardware accelerators. TensorNEAT is compatible with the [EvoX](https://github.com/EMI-Group/evox/) framewrok. ## Key Features - JAX-based network for neuroevolution: - **Batch inference** across networks with different architectures, GPU-accelerated. - Evolve networks with **irregular structures** and **fully customize** their behavior. - Visualize the network and represent it in **mathematical formulas** or **codes**. - GPU-accelerated NEAT implementation: - Run NEAT and HyperNEAT on GPUs. - Achieve **500x** speedup compared to CPU-based NEAT libraries. - Rich in extended content: - Compatible with **EvoX** for multi-device and distributed support. - Test neuroevolution algorithms on advanced **RL tasks** (Brax, Gymnax). ## Basic API Usage Start your journey with TensorNEAT in a few simple steps: 1. **Import necessary modules**: ```python from tensorneat.pipeline import Pipeline from tensorneat import algorithm, genome, problem, common ``` 2. **Configure the NEAT algorithm and define a problem**: ```python algorithm = algorithm.NEAT( pop_size=10000, species_size=20, survival_threshold=0.01, genome=genome.DefaultGenome( num_inputs=3, num_outputs=1, output_transform=common.ACT.sigmoid, ), ) problem = problem.XOR3d() ``` 3. **Initialize the pipeline and run**: ```python pipeline = Pipeline( algorithm, problem, generation_limit=200, fitness_target=-1e-6, seed=42, ) state = pipeline.setup() # run until termination state, best = pipeline.auto_run(state) # show results pipeline.show(state, best) ``` Obtain result in a few generations: ``` Fitness limit reached! input: [0. 0. 0.], target: [0.], predict: [0.00037953] input: [0. 0. 1.], target: [1.], predict: [0.9990619] input: [0. 1. 0.], target: [1.], predict: [0.9991497] input: [0. 1. 1.], target: [0.], predict: [0.0004661] input: [1. 0. 0.], target: [1.], predict: [0.998262] input: [1. 0. 1.], target: [0.], predict: [0.00077246] input: [1. 1. 0.], target: [0.], predict: [0.00082464] input: [1. 1. 1.], target: [1.], predict: [0.99909043] loss: 8.861396736392635e-07 ``` 4. **Visualize the best network**: ```python network = algorithm.genome.network_dict(state, *best) algorithm.genome.visualize(network, save_path="./imgs/xor_network.svg") ```