More tunable params, starting notebook

This commit is contained in:
Jacob Windle 2019-08-21 09:35:37 -04:00
parent 9ddbecefc7
commit 637f45f9bd
2 changed files with 15 additions and 4 deletions

View File

@ -0,0 +1,6 @@
{
"cells": [],
"metadata": {},
"nbformat": 4,
"nbformat_minor": 2
}

View File

@ -6,6 +6,7 @@ mu = 1
lambda = 4 lambda = 4
GENLIMIT = 20 GENLIMIT = 20
TARGETCALORIES = 2000 TARGETCALORIES = 2000
CANDIDATESIZE = 4
data = ExcelReaders.readxlsheet("./data/nutrional_information_5917.xlsx", "Sheet2", skipstartrows=1) data = ExcelReaders.readxlsheet("./data/nutrional_information_5917.xlsx", "Sheet2", skipstartrows=1)
header = ExcelReaders.readxlsheet("./data/nutrional_information_5917.xlsx", "Sheet2", nrows=1) header = ExcelReaders.readxlsheet("./data/nutrional_information_5917.xlsx", "Sheet2", nrows=1)
@ -96,15 +97,16 @@ function generateInitialPopulation(lambda::Integer, candidateSize::Integer)
[randomCandidate(candidateSize) for i = 1:lambda] [randomCandidate(candidateSize) for i = 1:lambda]
end end
function main() function main(genLimit)
# Generate the initial population. # Generate the initial population.
pop = generateInitialPopulation(lambda, 4) pop = generateInitialPopulation(lambda, CANDIDATESIZE)
best = nothing best = nothing
generationNum = 0 generationNum = 0
fit = nothing fit = nothing
parents = nothing parents = nothing
results = Dict{Integer, Float64}()
while generationNum <= GENLIMIT while generationNum <= genLimit
# Assess the fitness of parents # Assess the fitness of parents
for parent in pop for parent in pop
fit = fitness(parent) fit = fitness(parent)
@ -115,6 +117,7 @@ function main()
# Grab our best fitness for logging purposes. # Grab our best fitness for logging purposes.
bestFitness = fitness(best) bestFitness = fitness(best)
results[generationNum+1] = bestFitness
# Copy the best mu parents into the population. # Copy the best mu parents into the population.
sort!(pop, by = x -> fitness(x)) sort!(pop, by = x -> fitness(x))
@ -128,9 +131,11 @@ function main()
end end
end end
println("Generation $generationNum, best $best, fitness $bestFitness") # println("Generation $generationNum, best $best, fitness $bestFitness")
generationNum += 1 generationNum += 1
end end
results
end end
# search(generateInitialPopulation()) # search(generateInitialPopulation())