Hello everybody,
I am working on an AI experiment involving generating candidate solutions to a problem. My candidates are in the form of smaller dataframes derived from the larger dataset dataframe. The error I’m facing is this:
ERROR: BoundsError: attempt to access "attempt to access a data frame with 475 rows at index [0, 202, 402, 259]"
Stacktrace:
[1] getindex(::DataFrames.DataFrame, ::Array{Int64,1}, ::Colon) at /home/jake/.julia/packages/DataFrames/Iyo5L/src/dataframe/dataframe.jl:387
[2] randomCandidate(::Int64) at /home/jake/Projects/gp-experiment/Experiment.jl:51
[3] mutate at /home/jake/Projects/gp-experiment/Experiment.jl:28 [inlined]
[4] main() at /home/jake/Projects/gp-experiment/Experiment.jl:84
[5] top-level scope at none:0
And this is the abridged version of my code.
function mutate(parent)
randomCandidate(4)
end
function randomCandidate(n::Integer)
# Select n random rows from the dataset.
rows = [randRow() for i = 1:n]
df[rows, :]
end
function generateInitialPopulation(lambda::Integer, candidateSize::Integer)
[randomCandidate(candidateSize) for i = 1:lambda]
end
function main()
# Local variables omitted
lambda = 4
mu = 1
while generationNum != GENLIMIT || (best != nothing && fitness(best) != 0)
# Population fitness evaluation omitted.
for p in parents
for i = 1:(lambda/mu)
push!(pop, mutate(p))
end
end
println("Generation $generationNum, best $best, fitness $bestFitness")
generationNum += 1
end
end
Apologies for the awful formatting, randomCandidate works in generateInitialPopulation, but when I try to call it as part of mutate, I get the BoundsError, seemingly nothing has changed, other then where I am calling it from, anyone have any idea what might be happening?