Genetic Algorithms in Elixir (PragProg)

Sean Moriarity @seanmor5

edited by Tammy Coron @Paradox927

From finance to artificial intelligence, genetic algorithms are a powerful tool with a wide array of applications. But you don’t need an exotic new language or framework to get started; you can learn about genetic algorithms in a language you’re already familiar with. Join us for an in-depth look at the algorithms, techniques, and methods that go into writing a genetic algorithm. From introductory problems to real-world applications, you’ll learn the underlying principles of problem solving using genetic algorithms.

Evolutionary algorithms are a unique and often overlooked subset of machine learning and artificial intelligence. Because of this, most of the available resources are outdated or too academic in nature, and none of them are made with Elixir programmers in mind.

Start from the ground up with genetic algorithms in a language you are familiar with. Discover the power of genetic algorithms through simple solutions to challenging problems. Use Elixir features to write genetic algorithms that are concise and idiomatic. Learn the complete life cycle of solving a problem using genetic algorithms. Understand the different techniques and fine-tuning required to solve a wide array of problems. Plan, test, analyze, and visualize your genetic algorithms with real-world applications.

Open your eyes to a unique and powerful field—without having to learn a new language or framework.


Sean Moriarity graduated from the United States Military Academy with a degree in Computer Science. Sean was first introduced to genetic algorithms while on a summer internship which inspired him to write Genex, a library for writing evolutionary algorithms in Elixir. Many of the problems and solutions you’ll encounter in this book were inspired from the lessons learned while developing Genex. Sean’s passions include functional programming, artificial intelligence, mathematics, and, of course, evolutionary algorithms.


Don’t forget you can get 35% off with your Devtalk discount! Just use the coupon code “devtalk.com" at checkout :+1:


Posted via Devtalk.
24 Likes

A new Elixir resource is available

13 Likes

@kokolegorille Author here. Thanks for sharing! If anybody has any questions or comments about the book, feel free to PM me!

28 Likes

Oh hey, that looks really cool! I wasn’t aware that Elixir was a suitable language for machine learning. Though I suppose that if you think about it, about any language would be able to do it.

2 Likes

Thanks for writing this book, Sean! I am really curious about it!

1 Like

I could not find information on the website, but will a paper version be available. I’m one of those that don’t do well with ebook formats and prefer holding a physical book.

1 Like

Yes there will, but don’t expect the book release before version 1.0 :slight_smile:

1 Like

I bought a copy recently, looking forward to learn a great deal from this book. Thank you.

1 Like

@seanmor5 Hi, the book is pretty informative so far, but there are some code inconsistencies, which is understandable given the book is still in beta; Still a great resource!

I do have something I can’t seem to figure out, though, which is the representation of the N-Queens problem. Given the configuration [0, 2, 1, 3, 6, 4, 7, 5], it’s being represented as such in the book:

image

  1. I can’t seem to figure out the relationship between the configuration, and the illustration. I don’t understand how a 2D board can be represented with only a 1D list, if each element in the list were to be a queen’s location.
  2. It isn’t a valid solution because of the 2 queens in the last column. Or maybe this is just to serve as an example, and not as a solution?

Edit: I found a resource that expounds further on this, and confirmed my guess. The index of an element represents the column number, and the element value represents the row value. But regardless, the image doesn’t really line up with the configuration.

2 Likes

Columns from left to right are the index of each value from the list, and the value is the row from top to bottom (both starting from zero). So it is the index that is making up for that X coordinate you are looking for, the Y coordinates are each value on the list, assuming the origin of this plane on the top left corner.

2 Likes

I am extremely excited about this announcement! I’ve been fascinated by genetic algorithms for a long time, but I’ve had to portion out my time to learning one thing or another. Since my learning time is mostly spent in Elixir, this can kill two birds with one stone!

1 Like

Yeah, the image is wrong. I need to adjust. Sorry about that

1 Like

really interested in this book. Any reviews? Suitable for someone without formal CS background?

1 Like

I liked the book and did not find it difficult to read, I learned a subject I did not really know.

Maybe it’s because I have studied Biology instead of CS, and I know what genetic is…

Terminology was familiar :slight_smile:

3 Likes

I’m from a similar background so that’s very encouraging. Thanks!

2 Likes

I have always found the topic interesting, but I really never found a use case for it. Most examples I see around are examples for which we already have a perfect algorithm - meaning we already know the solution. It may be these algorithms take a long time to run, but then again I would still wait in most cases instead of getting a “It is quite possible that this is the best solution” kind of answer.

Obviously, my preferences do not align if the run time is in the order of magnitude of, lets say, years of life the universe has.

So my question would really be: has anyone that had read this book found a real use case scenario for using it?

Right now I am working on what can be considered an auction sniper (there is an auction website, and my algorithm calculates the best price for my items given a few directions, like for example, how fast I want to get rid of said item). I understand the book has a chapter on finance, would this book hold value for the example I just mentioned?

Has anyone built cool things with the material from the book? I would really appreciate direction.

2 Likes

You can find @qhwa solving AOC with genetic algorythm :slightly_smiling_face:

3 Likes

Challenge in question:

Maybe it is just me, but I truly look at this and I see a variant of the queens problem, but with additional limitations (such as fuel and horizontal movement only).

I will say I am impressed that someone picked up genetic algorithms as the first tool in their toolbet though. Really interesting !

3 Likes

I don’t think people use their first tool for AOC.

Some did use awk @ferd , some sql @al2o3cr , and I used as a way to learn lfe syntax.

Genetic algorithm might not be obvious, but it solves optimization problems in a neat way.

3 Likes

Exactly correct for me :smiley: I’ve been using genetic algorithm in one of our products where we needed to solve a problem similar to the Vehicle Routing Problem and this book helped a lot. While there are a lot of solutions for VRP, I think genetic algorithm is still interesting as the fitness function can be easily extended as the business evolves.

One thing I find hard when using genetic algorithms is modeling the problem, or how to present the solution better. I would be very happy If the book can provide more help on it.

6 Likes