Giter Club home page Giter Club logo

text-generation-using-genetic-algorithm's Introduction

Text Search Using Genetic Algorithm

What is Genetic Algorithm?

The term “Genetic Algorithm” refers to a specific algorithm implemented in a specific way to solve specific sorts of problems. [Daniel Shiffman, Nature of Code – Chapter 9] This algorithm is inspired by process of “natural selection” which basically belongs to the larger class of evolutionary algorithms (EA). These algorithms are used to generate high quality solutions to optimize and search problems by relying on bio-inspired operations such as “crossover”, “mutation”, “selection” etc. John Holland introduced Genetic Algorithm (GA) in 1960 based on the concept of Darwin’s theory of evolution

Why to use Genetic Algorithm?

Because they are simple to program! Proven to find the global optimum if given enough time. Can be applied to diverse problem domains, etc. Can be used when we know what’s a good solution but we can’t figure out the road to that solution. It provides a good way to search and traverse the space of possible solutions in a smart way. Along with easy implementation, it is easy to trace the performance.

About this project - The Problem Statement

Genetic Algorithms are one of the best ways to go when we know a good solution but we can’t figure out the road to that solution.

Let’s consider the string “Program Structures and Algorithms is the best class!!”. This string is 54 characters long. If a system starts guessing this string character by character, the probability that the system guesses all the 54 characters right will be (1/27) multiplied by itself 54 times!!! I.e.,  (1/27)54 which equals a 1 in 50,857,702,033,867,822,607,895,549,241,096,482,953,017,615,834,735,226,163,958,950 chance of getting it right!

Now, the chances are, if this system has capability of generating one million phrase per second, for the system to have a 99% probability to get the string right, it will have to work for 9,719,096,182,010,563,073,125,591,133,903,305,625,605,017 years. However, using Genetic Algorithm to do this would hardly take few seconds! And that’s exactly what we are here to demonstrate!

The demo of this project is available at

https://youtu.be/oH2PLkd36lc

Output Explained

The application accepts any string of user’s choice and applies Genetic Algorithm to generate the same string as an output based on the mutation rate entered by the user. The total number of generations involved along with the average fitness of the generation and total time taken by the algorithm (benchmarking) to generate the output.

Observations

The number of generations required to evolve a sentence vary with each execution. The number of generations and time required for evolution change drastically with change in the mutation rate For a given population size, the algorithm with get the results fast and with least number of generations only for a given range of mutation rate. As we go on considering lower or higher mutation rates, the number of generations to reach the target string may increase or the final string may not be correct at all If string size is too less, then is it normal to go in a infinity loop for a large mutation rate

Conclusion

From this project, we understood that Genetic Algorithm can offer efficient way of searching and text generation if the target is known. It is not necessary to get the right result every time, unless the combinations of mutation rate and population size selected are in right range For population size of 10,000, the mutation rate that suited almost all sizes of string is 0.01.

References

Daniel Shiffman, “Nature of Code”, Chapter 09 Wikipedia Vijini Mallawaarachchi’s article on “Introduction To Genetic Algorithms” featured at www.towardsdatascience.com Paper on “A NEW APPROACH FOR DATA ENCRYPTION USING GENETIC ALGORITHMS” featured at www.researchgate.net

text-generation-using-genetic-algorithm's People

Contributors

tripathivaishali avatar payalzanwar 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.