Coder Social home page Coder Social logo

evolgenalg's Introduction

Evolutionary Genetic Algorithm for Path Optimization in Python

This is an optimizer which tries to optimize a path on a virtual terrain in regards to energy consumption. It works by creating simple creatures which contain a brain which is modeled as a very simple neural network. The training process works by generating a population of creatures which we get by randomly modifying and combining the parameters inside the neural networks of the previous generation.

Main Image

Problem statement

We have:

  • terrain
  • starting point
  • target point

Goal: find optimal path in regards to energy consumption

Approach

Basic Idea:

  • make creatures
  • let them walk
  • evaluate their performance
  • "kill" the worst ones
  • generate new population (randomly, mating or mutation)
  • iterate until convergence

Which classes do we need?

  • World
  • Creature
  • Brain

The world contains a certain amount of creatures which all have their own individual brain.

World

The world contains:

  • terrain (simple perlin noise as a height map)
  • creatures

For each iteration the world…

  • creates new creatures by breeding, mutating and killing the previous population
  • calculates the trajectory each creature makes over 1000+ steps

There are a couple of rules:

  • a creature dies when it reaches the border of the terrain
  • each step has to be a certain size
  • for each step a creature loses / gains some energy (uphill loses, downhill gains)
  • the final score is a weighted sum of the energy and 1/distance_to_goal

Creature

A creature contains:

  • id
  • starting location
  • target location
  • current location
  • trajectory
  • energy score
  • brain

-> while walking the brain decides which step to take according to given inputs

Brain Inputs:

current energy current height height difference to last step x,y distances to target the heights of 4 points around the creature how many steps it already took

Brain

Brain

Implementation:

  • input tensor
  • n x m matrix for the connections between two layers
  • where n,m are the amount of neurons which are connected
  • non linear functions after each layer (relu)
  • output tensor [x,y]

to calculate the next step:

  1. matrix multiplication with input
  2. use non linear function to truncate the result
  3. do these steps for each hidden layer
  4. get output

evolgenalg's People

Contributors

thomacdebabo avatar

Stargazers

 avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.