seanmor5
Genex - Genetic Algorithms in Elixir
Hey all,
I wanted to get some experience writing libraries in Elixir, so I started a project today called Genex.
Genex is a simple library that makes it easy to write Genetic Algorithms in Elixir. All you have to do is specify some parameters, define a few functions, and then run the algorithm.
This library is VERY new (I literally just started it today). So it doesn’t have sufficient tests, documentation, or really much of anything yet. It is NOWHERE near finished.
I was looking for suggestions, tips, ideas, etc. for the rest of the way forward. I know Elixir isn’t really the best language for this stuff, but it’s a fun little project. I’ve had fun messing around solving very basic optimization problems with it.
Let me know what you guys think! If you want to contribute, send me a message!
Most Liked
seanmor5
What’s New
- Bug Fixes
- Improved Documentation (Including full customization guide)
- Statistics collection using built in or 3rd party modules
- Implementation of Crossover Rate, Mutation Rate, and Radiation as overridable functions to change with population parameters
What’s Next
- PERFORMANCE
From the start of this project, I understood Elixir and the BEAM are not ideal for this kind of application; however, I am really falling in love with the simplicity Elixir and this Library can offer to these kinds of problems. That being said, I know this library’s performance will likely never rival DEAP or similar implementations in languages like C or Rust; however, I know the performance itself can be improved.
If you check out some of the benchmarks in the Git Repository, you’ll see how hopelessly slow a lot of the evolutionary operators are. I’m considering 3 options for solving this problem:
- Parallelization using Task API or Flow as well as scrutinizing my implementations of the various algorithms. This is probably the route I’m going to explore first and settle with for the next release.
- NIFs. My research tells me this is an absolutely ideal use case for NIFs. Essentially, we just need the evolutionary operators (crossover, mutation, selection) implemented as NIFs. The operators just need to perform computation on large lists really fast and return the result. This seems like an ideal use case for NIFs. If anybody has experience writing them in Rust or C, please shoot me a message so we can discuss!
- Ports. This option doesn’t make much sense in my opinion although if anybody can make an argument for it, I’d be willing to listen.
If you’re writing anything cool with Genex or just playing around - please let me know! I don’t expect this library to be very popular but it’s been a lot of fun to work on 
seanmor5
What’s New
- Bug fixes
- 3.51x Performance Improvement in single_point crossover
- 2.35x Performance Improvement in two_point crossover
- Addition of
benchmark/0function to benchmark your algorithm - Addition of
track_history?flag to turn off and on the Genealogy tree feature (see problems for why).
What’s Next
- Exploring the idea of using the Matrex library per @OvermindDL1 suggestion. Representing the Populations and Chromosomes as matrices gives access to their REALLY fast matrix functions.
- Also began messing around with implementing the operators as NIFs last night. 2 problems I ran into: Rustler’s current release doesn’t support Erlang 22. Not a huge problem because their
masterbranch does, more a minor inconvenience. 2nd problem is it was my first experience with Rust and I couldn’t write anything efficient to save my life
.
Problems
- I had to add the
track_history?flag because I couldn’t get Benchee to play nicely with the current Genealogy tree implementation. The Genealogy tree is just an Erlang digraph. The problem is Benchee runs in it’s own process and Erlang digraph’s are protected by default. I thought it would be an easy fix - considering you can make ETS table’s public - however, digraph’s protection options are only:protectedand:private. If anybody has a workaround for this, I’d love to hear it!
Thanks!
seanmor5
Hey guys, sorry I haven’t been able to put much time into this library due to school; however, I have a quick announcement and update.
First, I added a new function interactive/2 up on the master branch for creating Interactive Genetic Algorithms. Basically, you call interactive/2 in your fitness_function/1 definition.
The function accepts chromosome and view which is a function for displaying the Chromosome struct. It defaults to IO.inspect.
This came from a paper I read on Web Design Optimization using GAs. Basically, each Chromosome is displayed to a user and THEY determine the fitness based on some arbitrary criteria. In the case of web pages, it was on how appealing the page looked.
This concept was pretty cool to me so I added the functionality to Genex. You can see the example in the examples directory.
v1.0 Update
I am pushing towards v1.0 slowly but surely. This will include major restructuring of the library and introduce a bunch of new and exciting concepts including Multi-Objective Optimization, Multiple Populations, Customizable Evolutions, different reinsertion strategies, etc. I’m also working on a Web Visualizer of GAs using Phoenix Live View.
I expect v1.0 to be pretty full featured and well-tested when it’s released, and because my time is limited with school, I don’t anticipate it will be out for another month or two.
I plan to use this library for some Academic Research (not just trivial examples like I have been), so expect some pretty cool things in the near future!
If anybody wants to help out, let me know!
seanmor5
To anybody following this project:
v0.1.0 was just released and published to Hex.
This version includes a few basic selection, crossover, and mutation methods, a text visualization module, and a Genealogy tree implementation. It has many limitations and many more features are in the works; however, this is a usable working version.
Enjoy!
Rainer
Interesting project, years ago I played with genetic algorithms and it was quite fun.
I’d also go for the combination with Rust.
If only I had time…







