GeneticSnake | Genetic Algorithm to teach a Neural Network | Machine Learning library

 by   filipposerafini Python Version: Current License: No License

kandi X-RAY | GeneticSnake Summary

kandi X-RAY | GeneticSnake Summary

GeneticSnake is a Python library typically used in Artificial Intelligence, Machine Learning applications. GeneticSnake has no bugs, it has no vulnerabilities, it has build file available and it has low support. You can download it from GitHub.

A Genetic Algorithm used to teach a Neural Network how to play snake.
Support
    Quality
      Security
        License
          Reuse

            kandi-support Support

              GeneticSnake has a low active ecosystem.
              It has 5 star(s) with 2 fork(s). There are 1 watchers for this library.
              OutlinedDot
              It had no major release in the last 6 months.
              There are 1 open issues and 1 have been closed. There are no pull requests.
              It has a neutral sentiment in the developer community.
              The latest version of GeneticSnake is current.

            kandi-Quality Quality

              GeneticSnake has no bugs reported.

            kandi-Security Security

              GeneticSnake has no vulnerabilities reported, and its dependent libraries have no vulnerabilities reported.

            kandi-License License

              GeneticSnake does not have a standard license declared.
              Check the repository for any license declaration and review the terms closely.
              OutlinedDot
              Without a license, all rights are reserved, and you cannot use the library in your applications.

            kandi-Reuse Reuse

              GeneticSnake releases are not available. You will need to build from source code and install.
              Build file is available. You can build the component from source.

            Top functions reviewed by kandi - BETA

            kandi has reviewed GeneticSnake and discovered the below as its top functions. This is intended to give you an instant insight into GeneticSnake implemented functionality, and help decide if they suit your requirements.
            • Play the game
            • Eat apple
            • Update the snake
            • Render the game
            • Run genetic algorithm
            • Compute the outputs of the input tensor
            • Forward propagation
            • Calculate fitness for a population
            • Draws the best neural network
            • Calculate the coordinates of a given neuron
            • Draws a circle
            • Draw a weight line
            • Plot the fitness history
            • Draws the observation
            • Change the direction
            Get all kandi verified functions for this library.

            GeneticSnake Key Features

            No Key Features are available at this moment for GeneticSnake.

            GeneticSnake Examples and Code Snippets

            No Code Snippets are available at this moment for GeneticSnake.

            Community Discussions

            QUESTION

            Snake AI that uses MLP and GA to learn doesn't exhibit intelligent behavior even after thousands of generations
            Asked 2020-Aug-30 at 05:13

            I'm a high school senior who's working on a project for my CS research class (I'm very lucky to have the opportunity to be in such a class)! The project is to make an AI learn the popular game, Snake, with a Multilayer Perceptron (MLP) that learns through Genetic Algorithm (GA). This project is heavily inspired by many videos I've seen on Youtube accomplishing what I've just described, as you can see here and here. I've written the project described above using JavaFX and an AI library called Neuroph.

            This is what my program looks like currently:

            The name is irrelevant, as I have a list of nouns and adjectives I used to generate them from (I thought it would make it more interesting). The number in the parenthesis for Score is the best score in that generation, since only 1 snake is shown at a time.

            When breeding, I set x% of the snakes to be parents (in this case, 20). The number of children is then divided up evenly for each pair of snake parents. The "genes" in this case, are the weights of the MLP. Since my library doesn't really support biases, I added a bias neuron to the input layer and connected it to all of the other neurons in every layer for its weights to act as biases instead (as described in a thread here). Each of the snake's children has a 50, 50 chance of getting either parents' gene for every gene. There is also a 5% chance for a gene to mutate, where it's set to a random number between -1.0 and 1.0.

            Each snake's MLP has 3 layers: 18 input neurons, 14 hidden ones, and 4 output neurons (for each direction). The inputs I feed it are the x of head, y of head, x of food, y of food, and steps left. It also looks in 4 directions, and check for the distance to food, wall, and itself (if it doesn't see it, it's set to -1.0). There's also the bias neuron I talked about which brings the number to 18 after adding it.

            The way I calculate a snake's score is through my fitness function, which is (apples consumed × 5 + seconds alive / 2)

            Here is my GAMLPAgent.java, where all the MLP and GA stuff happens.

            ...

            ANSWER

            Answered 2020-Aug-30 at 05:13

            I'm not surprised your snakes are dying.

            Let's take a step back. What is AI exactly? Well, it's a search problem. We're searching through some parameter space to find the set of parameters that solve snake given the current state of the game. You can imagine a space of parameters that has a global minimum: the best possible snake, the snake that makes the fewest mistakes.

            All learning algorithms start at some point in this parameters space and attempt to find that global maximum over time. First, let's think about MLPs. MLPs learn by trying a set of weights, computing a loss function, and then taking a step in the direction that would further minimize the loss (gradient descent). It's fairly obvious that an MLP will find a minimum, but whether it can find a good enough minimum is a question and there are a lot of training techniques that exist to improve that chance.

            Genetic algorithms, on the other hand, have very poor convergence characteristics. First, let's stop calling these genetic algorithms. Let's call these smorgasbord algorithms instead. A smorgasbord algorithm takes two sets of parameters from two parents, jumbles them, and then yields a new smorgasbord. What makes you think this would be a better smorgasbord than either of the two? What are you minimizing here? How do you know it's approaching anything better? If you attach a loss function, how do you know you're in a space that can actually be minimized?

            The point I'm trying to make is that genetic algorithms are unprincipled, unlike nature. Nature does not just put codons in a blender to make a new strand of DNA, but that's exactly what genetic algorithms do. There are techniques to add some time of hill climbing, but still genetic algorithms have tons of problems.

            Point is, don't get swept up in the name. Genetic algorithms are simply smorgasbord algorithms. My view is that your approach doesn't work because GAs have no guarantees of converging after infinite iterations and MLPs have no guarantees of converging to a good global minimum.

            What to do? Well, a better approach would be to use a learning paradigm that fits your problem. That better approach would be to use reinforcement learning. There's a very good course on Udacity from Georgia Tech on the subject.

            Source https://stackoverflow.com/questions/63534076

            Community Discussions, Code Snippets contain sources that include Stack Exchange Network

            Vulnerabilities

            No vulnerabilities reported

            Install GeneticSnake

            You can download it from GitHub.
            You can use GeneticSnake like any standard Python library. You will need to make sure that you have a development environment consisting of a Python distribution including header files, a compiler, pip, and git installed. Make sure that your pip, setuptools, and wheel are up to date. When using pip it is generally recommended to install packages in a virtual environment to avoid changes to the system.

            Support

            For any new features, suggestions and bugs create an issue on GitHub. If you have any questions check and ask questions on community page Stack Overflow .
            Find more information at:

            Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from over 650 million Knowledge Items

            Find more libraries
            CLONE
          • HTTPS

            https://github.com/filipposerafini/GeneticSnake.git

          • CLI

            gh repo clone filipposerafini/GeneticSnake

          • sshUrl

            git@github.com:filipposerafini/GeneticSnake.git

          • Stay Updated

            Subscribe to our newsletter for trending solutions and developer bootcamps

            Agree to Sign up and Terms & Conditions

            Share this Page

            share link

            Consider Popular Machine Learning Libraries

            tensorflow

            by tensorflow

            youtube-dl

            by ytdl-org

            models

            by tensorflow

            pytorch

            by pytorch

            keras

            by keras-team

            Try Top Libraries by filipposerafini

            LiveQuizBot

            by filipposerafiniPython

            RubiksCube

            by filipposerafiniC#

            Templates-Reti-Di-Calcolatori-T

            by filipposerafiniJava

            PythonVsAndroid

            by filipposerafiniPython

            Room8

            by filipposerafiniC#