An evolutionary multi-agent platform based on mesa and NEAT

Related tags

MiscellaneousEvoAgent
Overview

EvoAgent

An evolutionary multi-agent platform based on mesa and NEAT
A video of an old version of EvoAgent can be found on youtube:
https://www.youtube.com/watch?v=pOF1H84xPik&ab_channel=VBiscione

Overview

With this tool you can evolve agents in a simple 2D environments.
At the beginning, agents are endowed with a simple neural network which is specified by their genome. With time, they'll make children, which will inherit the genome, plus some random mutations. The mutations will add a connetion, a node, or change the weight. The evolutionary system is based on NEAT by Kenneth Stanley (paper here). However, the main difference between this approach and the classic evolutionary algorithm approach, is the naturalistic approach we are using here. In a classic evolutionary algorithm we would use a fitness function, we would test our agents, and we would use a genetic operator for generating the next generation. We have none of that here. Agents will spawn a new children every x time-steps. The more they survive, the more children they'll get. I found this approach much more intuitively valid as will simply respond to the rule: the more you survive, the more you'll spread your genes. This will also allow for generational interactions (as multiple generations will live at the same time), in case one wants to run experiments on family behaviour etc.

Install

git clone [email protected]:ValerioB88/EvoAgent.git

EvoAgent plots everything in the browser. This is heavily dependent on the Mesa library. My fork of Project Mesa should be automatically added as a submodule.

Examples

There are several examples in the folder code/evoagent/experiments/, which should get you started. Most of this is self explanatory. For example, run the file difficult_env.py and a browser with the environment view should open. Both the model state and the population gets saved (the model state includes the population). You want to use the model state to continue a running simulation with exactly the same parameters, from exactly the same point (the model state includes the population state). Instead, you may want to test an evolved population on a different enviornment: in that case, load the population. Examples of both these cases in continue_sim.py and load_pop.py. Model and population get saved every 1000 time steps, or when you press s.

Environment View

This contains a canvas, information about the selected agent, and some plots. At each points there always be a selected agents, for which many info are shown in the text field on the right sidebar. You can change the selected agent by pressing a and d on your keyboard (in a future version, it will be possible to click on the agent on the canvas to select it). Other info are shown in the following image:

Shortcuts

q start/stop simulation
a/d previous/next agent
k kill selected agent
c selected agent spawn a child
s save model
x advance the simulation one step

Agents Behaviour

Agents will have a limited field of view, specified by the parameters fov and max_vision_dist. You can visualize them by checking Render FOV in the environment view. Each agent will have a maximum lifespan of max_age = 500, but it can die faster if its energy goes to 0. They have a energy_depletion rate of 0.008. An agent will eat a food token when it touches it, getting an energy increase of 0.8 (or whathever established by the current Epoch, see later), up to 1. Agent will become fertile after fertile_age_start = 90 timesteps. At that point, they will spawn a child every time_between_children = 100 timesteps. For now, reproduction is asexual, so there is no crossover (this will be expanded in a next version).

Agents can only perceive the closest food token, IF it's within their field of view. If the selected agent is perceiving a food token, this will be represented with a red color in the environment view. Agents' network input will be the linear distance to the perceived food token, the angular distance, and their own energy level. There will be two output units, one defining the forward/backward movement, the other one defining the rotation.

Epochs

The epochs are interval of times defined by the amount of food in the environment.

epochs = deque([Epoch(2000, [0.8]*200),
                Epoch(2000, [0.8]*100),
                Epoch(6000, [0.8]*75)])

This means that we have 3 epochs, the first lasting 2000 iteration, the last 6000 iterations. The first will have 200 food tokens, each provigin 0.8 units of energy (recall that [0.8]*200 generates a list of 200 elements of value 0.8: [0.8, 0.8, 0.8....]. By changing the second parametr, you can specify the distribution of food token easily. You can also have "posionous" food: Epoch(2000, [-0.2]*200) this will work. However, currently the agents don't have a way to differentiate between "good" and "bad" food, so it doesn't make much sense to use bad food right now.

The simulation will activate one epoch at the time, starting from the first one. When the last epoch finishes, the simulation stop. You can instead run the simulation indefinitively by setting the epoch duration to np.inf.

Speed Up Simulation

In the environment view, uncheck Render Canvas, then set the Frame per Second slider to 0. That's as fast as it can get!

Known Problems

If you stop the simulation and try to run it again, you'll get the error:
OSError: [WinError 10048] Only one usage of each socket address (protocol/network address/port) is normally permitted
To fix this, try to change the port in server.launch(...). If it doesn't work, close and open your browser. I know this is annoying, but hadn't have the time to fix it yet.

This has only been tested on Windows 10 and Edge 97. I don't plan to test it on any other configuration. Sorry!

To Do

☐ Add sexual reproduction: find a partner, do crossover
☐ Many agents options should be in a config file
☐ Select an agent by clicking on it with the mouse
☐ Implement data collection - or adapt mesa data collection
☐ Implement more ways to perceive food
☐ Implement ways to perceive other agents
☐ Server port stays open after code stops - which often lead to annoying behaviour. Find a way to fix this

Owner
Valerio1988
Valerio1988
This repo will have a small amount of Chrome tools that can be used for DFIR, Hacking, Deception, whatever your heart desires.

Chrome-Tools Overview Welcome to the repo. This repo will have a small amount of Chrome tools that can be used for DFIR, Hacking, Deception, whatever

5 Jun 08, 2022
A python trivium implemention

A python trivium implemention

tnt2402 1 Nov 12, 2021
Incident Response Process and Playbooks | Goal: Playbooks to be Mapped to MITRE Attack Techniques

PURPOSE OF PROJECT That this project will be created by the SOC/Incident Response Community Develop a Catalog of Incident Response Playbook for every

Austin Songer 987 Jan 02, 2023
Scientific color maps and standardization tools

Scicomap is a package that provides scientific color maps and tools to standardize your favourite color maps if you don't like the built-in ones. Scicomap currently provides sequential, bi-sequential

Thomas Bury 14 Nov 30, 2022
RxPY - The Reactive Extensions for Python (RxPY)

The Reactive Extensions for Python (RxPY) A library for composing asynchronous and event-based programs using observable collections and query operato

ReactiveX 4.4k Dec 29, 2022
A Python 3 client for the beanstalkd work queue

Greenstalk Greenstalk is a small and unopinionated Python client library for communicating with the beanstalkd work queue. The API provided mostly map

Justin Mayhew 67 Dec 08, 2022
Streamlit Component, for a Chatbot UI

st-chat Streamlit Component, for a Chat-bot UI, example app authors - @yashppawar & @YashVardhan-AI Installation Install streamlit-chat with pip pip i

Yash AI 99 Jan 07, 2023
A python package template that can be adapted for RAP projects

Warning - this repository is a snapshot of a repository internal to NHS Digital. This means that links to videos and some URLs may not work. Repositor

NHS Digital 3 Nov 08, 2022
Petuhlang is a joke-like language, based on Python.

Petuhlang is a joke-like language, based on Python. It updates builtins to make a new syntax based on operators rewrite.

DenyS 9 Jun 19, 2022
A 3-line lisp implementation

Nanolisp The download page of many a language harbors deep senses of forboding, of evil lurking in its native lair. You feel that the language is not

5 Jun 17, 2022
「📖」Tool created to extract metadata from a domain

Metafind is an OSINT tool created with the aim of automating the search for metadata of a particular domain from the search engine known as Google.

9 Dec 28, 2022
Runnable Python demo of ArtLine

artline-demo How to run? pip3 install -r requirements.txt python3 app.py How to use? Run the Flask app Open localhost:5000 in browser Select an image(

Jiang Wenjian 134 Jul 29, 2022
Find the remote website version based on a git repository

versionshaker Versionshaker is a tool to find a remote website version based on a git repository This tool will help you to find the website version o

Orange Cyberdefense 110 Oct 23, 2022
Script that creates graphical representations of Julia an Mandelbrot sets.

Julia and Mandelbrot Picture Maker This simple functions create simple plots of the Julia and Mandelbrot sets. The Julia set require the important par

Juan Riera Gomez 1 Jan 10, 2022
Repository voor verhalen over de woningbouw-opgave in Nederland

Analyse plancapaciteit woningen In deze notebook zetten we cijfers op een rij om de woningbouwplannen van Nederlandse gemeenten in kaart te kunnen bre

Follow the Money 10 Jun 30, 2022
Python 3 script for installing kali tools on your linux machine

Python 3 script for installing kali tools on your linux machine

gh0st 2 Apr 20, 2022
Grade 8 Version of Space Invaders

Space-Invaders Grade 8 Version of Space Invaders Compatability This program is Python 3 Compatable, and not Python 2 Compatable because i haven't test

Space64 0 Feb 16, 2022
Todo-backend - Todo backend with python

Todo-backend - Todo backend with python

Julio C. Diaz 1 Jan 07, 2022
Project for viewing the cheapest flight deals from Netherlands to other countries.

Flight_Deals_AMS Project for viewing the cheapest flight deals from Netherlands to other countries.

2 Dec 17, 2022