Created
August 8, 2017 22:12
-
-
Save mikewl/9366b7bca63831c9cc0c30d64e4314f3 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#setup GPUArrays and CUDA backend | |
using CUDAnative | |
using GPUArrays | |
CUBackend.init() | |
const absMax = 5 | |
struct Individual | |
chromosome::Vector{Float32} | |
fitness::Float32 | |
function Individual(size::Int, fitness) | |
chromosome = rand(size) * absMax*2 - absMax | |
return new(chromosome, fitness(new(chromosome,0))) | |
end | |
Individual(data, fitness) = new(data, fitness) | |
end | |
function sphereFitness(input::Individual) | |
total = 0.0f0 | |
for gene in input.chromosome | |
total += gene*gene | |
end | |
return total | |
end | |
GPUArray([Individual(10, sphereFitness) for i = 1:10]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment