Lightning talk:
Julia for Evolutionary Computation
Valentina Ivanovic
Xavier F. C. Sánchez Díaz
Outline
2
Quick Links
3
Why Julia?
4
An example
function jumpk(x; k=6)::Int
s = sum(x)
n = length(x)
return s ∈ (1:n-k) ∪ n ? s : -s
end
5
one-liners
binary_vector_pop(n, l; rng=Random.GLOBAL_RNG) = [bitrand(rng, l) for _ in 1:n]
f(x) = sum(x)
6
Why Julia?
7
Why Julia?
8
Why Julia?
9
Environments and Packages
julia> import Pkg
julia> Pkg.add("EvoLP")
julia> ] # enter pkg mode
(@v1.10) pkg> add EvoLP
or
10
Comparison with Python
11
Ecosystem & Community Support
12
Concurrency & Parallelism
13
Interoperability
14
IDE Support
15
OOP vs. Multiple Dispatch
16
Object oriented
class Representation:
def create_vector_spaces(self, df, n, attr_groups):
# Check if something happens
if len(attr_groups) != n:
raise ValueError("Number of attribute groups should be equal to the specified number of vector spaces (n).")
# Initialize an empty dict to store vector spaces
vector_spaces = {}
17
Types/structs
struct Representation end
function create_vector_spaces(df, n, attr_groups)
# Check if something happens
if length(attr_groups) != n
error("Number of attribute groups should be equal to the specified number of vector spaces (n)")
end
vector_spaces = Dict()
end
18
Memory Management
19
Broadcasting
20
Keywords
struct Representation end
function create_vector_spaces(df, n, attr_groups)
# Check if something happens
if length(attr_groups) != n
error("Number of attribute groups should be equal to the specified number of vector spaces (n)")
end
vector_spaces = Dict()
end
21
Differences with Python
import numpy as np
def f(x):
return 3 * x**2 + 2 * x + 10 * np.pi
f(x) = 3x^2 + 2x + 10π
function f(x)
return 3 * x^2 + 2 * x + 10 * pi
end
Python
Julia
or
22
Differences with Python
julia> x = [1, 2, 3, 4]; # ; suppresses output
julia> x[1]
1
julia> x[0]
ERROR: BoundsError: attempt to access 4-element Vector{Int64} at index [0]
Stacktrace:
[1] getindex(A::Vector{Int64}, i1::Int64)
@ Base ./essentials.jl:13
[2] top-level scope
@ REPL[3]:1
23
Differences with Python
julia> x = [1, 2, 3, 4];
julia> filter(isodd, x)
2-element Vector{Int64}:
1
3
julia> x
4-element Vector{Int64}:
1
2
3
4
julia> x = [1, 2, 3, 4];
julia> filter!(isodd, x)
2-element Vector{Int64}:
1
3
julia> x
2-element Vector{Int64}:
1
3
24
Differences with Python
julia
python
25
Differences with Python
Python
Julia
26
EvoLP.jl
Evolutionary Computation in Julia
Evolutionary Computation in Julia
We made EvoLP.jl!
"A playground for evolutionary computation—for prototyping evolutionary solvers such that one can swap a component or two and see how it affects the run"
28
EvoLP – The Taxonomy
A block for each step in the evolution process:
29
EvoLP – The Taxonomy
A block for each step in the evolution process:
30
An example: 8-queens
Constraints of 1 queen
Conflicts of 8 queens
A solution
31
An example: 8-queens
A block for each step in the evolution process:
32
An example: 8-queens
A block for each step in the evolution process:
33
An example: 8-queens
A block for each step in the evolution process:
34
EvoLP.jl
A playground for Evolutionary Computation in Julia
Project repo at
https://github.com/ntnu-ai-lab/EvoLP.jl
��Documentation at https://ntnu-ai-lab.github.io/EvoLP.jl/stable
julia> ] # enter pkg mode
(@v1.10) pkg> add EvoLP
An open-source framework to code and analyse evolutionary computation solvers with:
Partially funded by NFR
Proudly supported by NAIL