Run this notebook

Use Livebook to open this notebook and explore new ideas.

It is easy to get started, on your machine or the cloud.

Click below to open and run it in your Livebook at .

(or change your Livebook location)

# Genetix ```elixir Mix.install([ {:kino_explorer, "~> 0.1.20"}, {:genetix, "~> 0.1"} ]) ``` ## Section ```elixir defmodule OneMax do @behaviour Genetix.Problem alias Genetix.Types.Chromosome @impl true def genotype(opts \\ []) do # Notice that in this case, we use `size` as a hyperparameter to define the gene size. size = Keyword.get(opts, :size, 10) genes = for _ <- 1..42, do: Enum.random(0..1) %Chromosome{genes: genes, size: size} end @impl true def fitness_function(chromosome, _opts \\ []), do: Enum.sum(chromosome.genes) @impl true def terminate?([best | _], _opts \\ []) do best.fitness == best.size end end ``` ```elixir Genetix.run(Genetix.Problems.OneMax, size: 100) ```
See source

Have you already installed Livebook?

If you already installed Livebook, you can configure the default Livebook location where you want to open notebooks.
Livebook up Checking status We can't reach this Livebook (but we saved your preference anyway)
Run notebook

Not yet? Install Livebook in just a minute

Livebook is open source, free, and ready to run anywhere.

Run on your machine

with Livebook Desktop

Run in the cloud

on select platforms

To run on Linux, Docker, embedded devices, or Elixir’s Mix, check our README.

PLATINUM SPONSORS
SPONSORS
Code navigation with go to definition of modules and functions Read More ×