gsoleilhac / nsgaii.jl Goto Github PK
View Code? Open in Web Editor NEWA NSGA-II implementation in Julia
License: Other
A NSGA-II implementation in Julia
License: Other
I'm attempting to execute the example code (knapsack), but I get this error:
ERROR: LoadError: UndefVarError: undef not defined
Stacktrace:
[1] (::Atom.##110#114{String,String})() at C:\Users\leona\AppData\Local\JuliaPro-0.6.2.2\pkgs-0.6.2
.2\v0.6\Atom\src\eval.jl:104
[2] withpath(::Atom.##110#114{String,String}, ::String) at C:\\\\\\\\\\\\\\\\\\\
\\\\\\\\\Users\leona\AppData\Local\JuliaPro-0.6.2.2\pkgs-0.6.2.2\v0.6\CodeTools\src\utils.jl
:30
[3] withpath(::Function, ::String) at C:\Users\leona\AppData\Local\JuliaPro-0.6.2.2\pkgs-0.6.2.2\v0
.6\Atom\src\eval.jl:38
[4] hideprompt(::Atom.##109#113{String,String}) at C:\Users\leona\AppData\Local\JuliaPro-0.6.2.2\pk
gs-0.6.2.2\v0.6\Atom\src\repl.jl:65
[5] macro expansion at C:\Users\leona\AppData\Local\JuliaPro-0.6.2.2\pkgs-0.6.2.2\v0.6\Atom\src\eva
l.jl:99 [inlined]
[6] (::Atom.##108#112{Dict{String,Any}})() at .\task.jl:80
while loading C:\Users\leona\Downloads\knapsack_test.jl, in expression starting on line 13
Checking the source code, the problem seems to be in 'functions.jl' line 5 where you write undef, which isn't indeed declared anywhere. What's that? Is it a way to say 'not implemented yet'? Am I missing something?
With some updates, the readme doesn't quite work as written. Specifically, the calls to bitrand need to be changed, and you need to call using Random, LinearAlgebra
The following worked for me:
`using NSGAII
using Random
using LinearAlgebra
n = 20 #Number of items
p1 = [77,94,71,63,96,82,85,75,72,91,99,63,84,87,79,94,90,60,69,62] #Coeffs objective 1
p2 = [65,90,90,77,95,84,70,94,66,92,74,97,60,60,65,97,93,60,69,74] #Coeffs objective 2
w = [80,87,68,72,66,77,99,85,70,93,98,72,100,89,67,86,91,79,71,99] #Items weights
c = 900 #Knapsack capacity
rng = MersenneTwister(1234);
popsize = 100
nbgen = 200
init() = bitrand(rng, n) #our genotype is a binary vector of size n, initialized randomly
z(x) = dot(x, p1), dot(x, p2) #and our objectives are the sum of the items we pick
function CV(x)
sumW = dot(x, w)
return sumW <= c ? 0 : sumW - c
end
#We can now call
result = nsga_max(popsize, nbgen, z, init, fCV = CV)
`
The model I am using means that the cost of evaluating genes is very high. Can there be an argument to nsga
that allows you to use pmap
for the parts of nsga that involve computing new genes? If I try to implement this on my fork which parts of NSGAII.jl should I edit?
Hello, while inspecting your code I noticed a potential flaw in the crowding distance assignment function.
I see that you split crowding_distance_assignement!
in two cases: one for when you have only 2 objective functions, the other for more than 2.
I assume this is an optimization to avoid a sort in the first case, which is fine and makes sense.
However, I think that you forgot to check if pop[1].y[1] != pop[end].y[1]
and if pop[1].y[2] != pop[end].y[2]
in the first case, which could become a source of zero division errors when the whole population shares the same fitness for at least one objective.
In the second case, instead, you perform the check (line 112) and that's good.
I think it's just an oversight, because I see no reason to assume pop[end].y[1] always different from pop[1].y[1]
PS: I also suggest to rename 'assignement' into 'assignment'
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.