Skip to content
Permalink
Browse files

Fixed contour plotting, assignment complete

  • Loading branch information
Stephen
Stephen committed Feb 13, 2018
1 parent 53b7a9e commit 38cc7710ce32af456458b0c62ff150a2c25da69d
BIN +486 Bytes (100%) BestFitness.png
Binary file not shown.
37 GA.jl
@@ -187,7 +187,6 @@ function GA(populationSize::Int, chromosomeSize::Int, fitness_function::Function
end
clear!(:generations)
clear!(:population)
clear!(:children)
run += 1
end

@@ -219,27 +218,37 @@ function GA(populationSize::Int, chromosomeSize::Int, fitness_function::Function
quit()
end

# Init x and y z for contour plots
x = y = z = Array{Float64}(0)

# Pick X and Y range for contour plot based on bounds
xrange = bounds[1][1]:0.01:bounds[1][2]
yrange = bounds[2][1]:0.01:bounds[2][2]
size = length(xrange)
# Init z array for values of fitness function
z = zeros(size,size)
for i in 1:size
for j in 1:size
# Generate a z value for each x and y value
z[i,j] = fitness_function([xrange[i],yrange[j]])
end
end
# If we are at 1st gen or evry 10th, plot
for (index, gen) in enumerate(bestGenerations)
if (index == 1) || (mod(index,10) == 0)
# Re-init x and y for the generation
x = Array{Float64}(0)
y = Array{Float64}(0)
# Push x and y to separate arrays
for m in gen
push!(x,m[1])
push!(y,m[2])
end
size = length(x)
z = rand(size,size)
for i in 1:size
for j in 1:size
z[i,j] = fitness_function([x[i],y[j]])
end
end
contour(x,y,z)
# Plt the contour plot
contour(xrange,yrange,z)
# Then plot the scatter underneath
scatter(x,y)
title("Generation $index")
savefig("contour_gen$index.png")
close()
clear!(:x)
clear!(:y)
clear!(:z)
end
end

BIN -172 KB (33%) contour_gen1.png
Binary file not shown.
BIN -81 KB (52%) contour_gen10.png
Binary file not shown.
BIN +5.66 KB (110%) contour_gen100.png
Binary file not shown.
BIN -55.1 KB (61%) contour_gen20.png
Binary file not shown.
BIN -42.7 KB (67%) contour_gen30.png
Binary file not shown.
BIN -38.8 KB (69%) contour_gen40.png
Binary file not shown.
BIN -37.1 KB (70%) contour_gen50.png
Binary file not shown.
BIN -23 KB (79%) contour_gen60.png
Binary file not shown.
BIN -16.4 KB (84%) contour_gen70.png
Binary file not shown.
BIN -15.2 KB (85%) contour_gen80.png
Binary file not shown.
BIN +1.34 KB (100%) contour_gen90.png
Binary file not shown.

0 comments on commit 38cc771

Please sign in to comment.
You can’t perform that action at this time.