seanmor5

seanmor5

Author of Genetic Algorithms in Elixir

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.

https://github.com/seanmor5/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!

First Post!

seanmor5

seanmor5

Author of Genetic Algorithms in Elixir

To anybody following this project:

v0.1.0 was just released and published to Hex.

Documentation
Package

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!

Most Liked

seanmor5

seanmor5

Author of Genetic Algorithms in Elixir

v0.1.2

Documentation
Package

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:

  1. 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.
  2. 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!
  3. 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 :slight_smile:

seanmor5

seanmor5

Author of Genetic Algorithms in Elixir

v0.1.4

Documentation
Package

What’s New

  • Bug fixes
  • 3.51x Performance Improvement in single_point crossover
  • 2.35x Performance Improvement in two_point crossover
  • Addition of benchmark/0 function 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 master branch 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 :slight_smile:.

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 :protected and :private. If anybody has a workaround for this, I’d love to hear it!

Thanks!

seanmor5

seanmor5

Author of Genetic Algorithms in Elixir

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!

Last Post!

subetei

subetei

Agree max and seanmor! While back had a real world use-case recently involving solving a travelling salesman problem with a few quirks making it have to be customized (too many nodes, multiple robot arms, extra rules etc). First implementation was with a genetic algorithm adapted from a Rust program and it worked very well. It’s a fun algorithm to play with and the use cases may be rare but the dudes that finally need it will appreciate this kind of lib very much

Where Next?

Popular in Announcing Top

wmnnd
Hi there, for my project DBLSQD, I needed a file storage solution that is a bit more flexible than Arc. Because I thought others might f...
New
anshuman23
Hello all, I have been working on my proposed project called Tensorflex as part of Google Summer of Code 2018.. Tensorflex can be used f...
New
mbuhot
Leverage Open Api 3.0 (Swagger) to document, test, validate and explore your Plug and Phoenix APIs. Generate and serve a JSON Open API ...
New
sorentwo
Hello! tl;dr Announcing Oban, an Ecto based job processing library with a focus on reliability and historical observability. After spen...
985 44778 311
New
ityonemo
Currently just starting out on a new mini-project - getting zig NIFs to run in elixir. https://github.com/ityonemo/zigler The idea here...
New
kip
Image is an image processing library for Elixir. It is based upon the fabulous vix library that provides a libvips wrapper for Elixir. I...
622 19610 194
New
brainlid
LangChain is short for Language Chain. An LLM, or Large Language Model, is the “Language” part. This library makes it easier for Elixir a...
New

Other popular topics Top

KronicDeth
Elixir plugin for JetBrain’s IntelliJ Platform (including Rubymine) This is a plugin that adds support for Elixir to JetBrains IntelliJ...
289 36820 110
New
baxterw3b
Hi guys, i’m new in the Elixir world, and i have to say, that i love it! i’m having some problem to understand anonymous functions with ...
New
joaquinalcerro
Hi there, I am working with Ecto-Postgresql and I need to call all of the records from a specific table but the table has 40,000 records...
New
jononomo
I am trying to figure out how Mix knows whether the environment is test, dev, or prod – where is this set? Thanks.
New
Harrisonl
We have an ECS cluster with 4 services, where each task joins a single cluster, via discovery ECS discovery service. Currently when I de...
New
jason.o
In the code below, if the create action is not set to accept “extra_key” as an input, it errors out with a message shown above. Is there ...
New

We're in Beta

About us Mission Statement