Skip to content

Commit dbd29bf

Browse files
authored
Merge pull request #83 from alyst/borg_fixes
Misc (mostly Borg) tweaks
2 parents a978d8b + 3ed5b36 commit dbd29bf

20 files changed

+255
-244
lines changed

.travis.yml

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,17 @@ os:
33
- linux
44
- osx
55
julia:
6-
# - 0.7 uncomment once 0.7 is out
6+
- 0.7
7+
- 1.0
78
- nightly
8-
#matrix: uncomment once 0.7 is out
9-
# allow_failures:
10-
# - julia: nightly
9+
matrix:
10+
allow_failures:
11+
- julia: nightly
1112
notifications:
1213
email: false
13-
script:
14-
- if [[ -a .git/shallow ]]; then git fetch --unshallow; fi
15-
- julia --check-bounds=yes -e 'Pkg.clone(pwd()); Pkg.build("BlackBoxOptim"); Pkg.test("BlackBoxOptim"; coverage=true)'
14+
# uncomment the following lines to override the default test script
15+
#script:
16+
# - if [[ -a .git/shallow ]]; then git fetch --unshallow; fi
17+
# - julia --check-bounds=yes -e 'using Pkg; Pkg.clone(pwd()); Pkg.build("RData"); Pkg.test("RData"; coverage=true)'
1618
after_success:
17-
- julia -e 'cd(Pkg.dir("BlackBoxOptim")); Pkg.add("Coverage"); using Coverage; Coveralls.submit(Coveralls.process_folder())'
19+
- julia -e 'using Pkg, BlackBoxOptim; cd(joinpath(dirname(pathof(BlackBoxOptim)), "..")); Pkg.add("Coverage"); using Coverage; Coveralls.submit(Coveralls.process_folder())'

REQUIRE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
julia 0.7.0-beta2.0
1+
julia 0.7
22
StatsBase
33
Distributions
44
Compat

appveyor.yml

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,21 @@
11
environment:
22
matrix:
3-
- JULIA_URL: "https://julialang-s3.julialang.org/bin/winnt/x86/0.7/julia-0.7-latest-win32.exe"
4-
- JULIA_URL: "https://julialang-s3.julialang.org/bin/winnt/x64/0.7/julia-0.7-latest-win64.exe"
3+
- julia_version: 0.7
4+
- julia_version: 1.0
5+
- julia_version: latest
6+
7+
platform:
8+
- x86 # 32-bit
9+
- x64 # 64-bit
10+
11+
matrix:
12+
allow_failures:
13+
- julia_version: latest
514

615
branches:
716
only:
817
- master
18+
- /release-.*/
919

1020
notifications:
1121
- provider: Email
@@ -14,18 +24,12 @@ notifications:
1424
on_build_status_changed: false
1525

1626
install:
17-
- ps: "[System.Net.ServicePointManager]::SecurityProtocol = [System.Net.SecurityProtocolType]::Tls12"
18-
# Download most recent Julia Windows binary
19-
- ps: (new-object net.webclient).DownloadFile(
20-
$env:JULIA_URL,
21-
"C:\projects\julia-binary.exe")
22-
# Run installer silently, output to C:\projects\julia
23-
- C:\projects\julia-binary.exe /S /D=C:\projects\julia
27+
- ps: iex ((new-object net.webclient).DownloadString("https://raw.githubusercontent.com/JuliaCI/Appveyor.jl/version-1/bin/install.ps1"))
2428

2529
build_script:
26-
# Need to convert from shallow to complete for Pkg.clone to work
27-
- IF EXIST .git\shallow (git fetch --unshallow)
28-
- C:\projects\julia\bin\julia -e "Pkg.clone(pwd(), \"BlackBoxOptim\"); versioninfo(); Pkg.build(\"BlackBoxOptim\")"
30+
- echo "%JL_BUILD_SCRIPT%"
31+
- C:\julia\bin\julia -e "%JL_BUILD_SCRIPT%"
2932

3033
test_script:
31-
- C:\projects\julia\bin\julia --check-bounds=yes -e "Pkg.test(\"BlackBoxOptim\")"
34+
- echo "%JL_TEST_SCRIPT%"
35+
- C:\julia\bin\julia -e "%JL_TEST_SCRIPT%"

src/BlackBoxOptim.jl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ export Optimizer, AskTellOptimizer, SteppingOptimizer, PopulationOptimizer,
3737
Problems,
3838
OptimizationProblem, FunctionBasedProblem,
3939
minimization_problem,
40-
name, fitness_scheme, search_space, numdims, opt_value,
40+
name, fitness_scheme_type, fitness_scheme, search_space, numdims, opt_value,
4141
fitness_is_within_ftol, objfunc, fitness,
4242

4343
# Problem factory/family
@@ -54,6 +54,7 @@ export Optimizer, AskTellOptimizer, SteppingOptimizer, PopulationOptimizer,
5454

5555
# OptimizationResults
5656
minimum, f_minimum, iteration_converged, parameters, population, pareto_frontier, params,
57+
archived_fitness,
5758

5859
# OptController
5960
numruns, lastrun, problem,

src/archives/epsbox_archive.jl

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ mutable struct EpsBoxArchive{N,F,FS<:EpsBoxDominanceFitnessScheme} <: Archive{In
4545
last_progress::Int # when (wrt num_candidates) last ϵ-progress has occured
4646
last_restart::Int # when (wrt num_dlast) last restart has occured
4747
n_restarts::Int # the counter of the method restarts
48+
n_oversize_inserts::Int # how many times the candidates were inserted into oversized archive
4849

4950
len::Int # current frontier size
5051
max_size::Int # maximal frontier size
@@ -55,7 +56,7 @@ mutable struct EpsBoxArchive{N,F,FS<:EpsBoxDominanceFitnessScheme} <: Archive{In
5556

5657
EpsBoxArchive(fit_scheme::EpsBoxDominanceFitnessScheme{N,F};
5758
max_size::Integer = 1_000_000) where {N,F} =
58-
new{N,F,typeof(fit_scheme)}(fit_scheme, time(), 0, 0, 0, 0, 0, 0, max_size,
59+
new{N,F,typeof(fit_scheme)}(fit_scheme, time(), 0, 0, 0, 0, 0, 0, 0, max_size,
5960
sizehint!(Vector{EpsBoxFrontierIndividual{N,F}}(), 64),
6061
sizehint!(BitVector(), 64))
6162
end
@@ -244,7 +245,7 @@ function add_candidate!(a::EpsBoxArchive{N,F}, cand_fitness::IndexedTupleFitness
244245
has_progress = true # no existing element with the same index, otherwise it would have been replaced
245246
#info("Appended non-dominated element to the frontier")
246247
if length(a.frontier) > a.max_size
247-
throw(error("Pareto frontier exceeds maximum size"))
248+
a.n_oversize_inserts += 1 # throw(error("Pareto frontier exceeds maximum size"))
248249
end
249250
end
250251
if updated_frontier_ix > 0
@@ -259,6 +260,9 @@ function add_candidate!(a::EpsBoxArchive{N,F}, cand_fitness::IndexedTupleFitness
259260
end
260261
end
261262
end
263+
if length(a.frontier) <= a.max_size
264+
a.n_oversize_inserts = 0 # reset the counter since the size is ok
265+
end
262266
if has_progress # non-dominated solution that has some eps-indices different from the existing ones
263267
a.last_progress = a.num_candidates
264268
end
@@ -273,7 +277,14 @@ add_candidate!(a::EpsBoxArchive{N,F}, cand_fitness::NTuple{N,F},
273277

274278
# called by check_stop_condition(e::Evaluator, ctrl)
275279
function check_stop_condition(a::EpsBoxArchive, p::OptimizationProblem, ctrl)
276-
ctrl.max_steps_without_progress > 0 &&
277-
noprogress_streak(a, since_restart=false) > ctrl.max_steps_without_progress ?
278-
"No epsilon-progress for more than $(ctrl.max_steps_without_progress) iterations" : ""
280+
if ctrl.max_steps_without_progress > 0 &&
281+
noprogress_streak(a, since_restart=false) > ctrl.max_steps_without_progress
282+
return "No epsilon-progress for more than $(ctrl.max_steps_without_progress) iterations"
283+
elseif a.n_oversize_inserts >= 10
284+
# notify that the last 10 inserts were to the oversized archive
285+
# that means that the ϵ quantization steps are too small
286+
return "Pareto frontier size ($(length(a.frontier))) exceeded maximum ($(a.max_size))"
287+
else
288+
return ""
289+
end
279290
end

src/borg_moea.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ mutable struct BorgMOEA{FS<:FitnessScheme,V<:Evaluator,P<:Population,M<:GeneticO
5353
params[], params[], params[:γ_δ], params[:PopulationSize],
5454
Categorical(ones(length(recombinate))/length(recombinate)),
5555
params[], params[], params[:OperatorsUpdatePeriod], params[:RestartCheckPeriod],
56-
params[:MaxStepsWithoutProgress],
56+
params[:MaxStepsWithoutEpsProgress],
5757
recombinate,
5858
TournamentSelector(fit_scheme, ceil(Int, params[]*popsize(pop))), modify, embed)
5959
end
@@ -68,7 +68,7 @@ const BorgMOEA_DefaultParameters = chain(EpsBoxArchive_DefaultParameters, Params
6868
=> 1.0, # dampening coefficient for recombination operator weights
6969
:RestartCheckPeriod => 1000,
7070
:OperatorsUpdatePeriod => 100,
71-
:MaxStepsWithoutProgress => 100
71+
:MaxStepsWithoutEpsProgress => 100
7272
))
7373

7474
function borg_moea(problem::OptimizationProblem, options::Parameters = EMPTY_PARAMS)

src/dx_nes.jl

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -105,11 +105,7 @@ function tell!(dxnes::DXNESOpt{F}, rankedCandidates::Vector{Candidate{F}}) where
105105
u = assign_weights!(dxnes.tmp_Utilities, rankedCandidates, dxnes.sortedUtilities)
106106
dxnes.evol_path *= dxnes.evol_discount
107107
# We'll take the small perf hit for now just so this can run also on pre rc2 julia 0.7s
108-
if VERSION < v"0.7.0-rc2"
109-
dxnes.evol_path += dxnes.evol_Zscale * squeeze(wsum(dxnes.Z, u, 2), dims=2)
110-
else
111-
dxnes.evol_path += dxnes.evol_Zscale * dropdims(wsum(dxnes.Z, u, 2), dims=2)
112-
end
108+
dxnes.evol_path += dxnes.evol_Zscale * dropdims(wsum(dxnes.Z, u, 2), dims=2)
113109
evol_speed = norm(dxnes.evol_path)/dxnes.moving_threshold
114110
if evol_speed > 1.0
115111
# the center is moving, adjust weights

src/genetic_operators/embedding/random_bound.jl

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,16 +17,19 @@ search_space(rb::RandomBound) = rb.searchSpace
1717
function apply!(eo::RandomBound, target::AbstractIndividual, ref::AbstractIndividual)
1818
length(target) == length(ref) == numdims(eo.searchSpace) ||
1919
throw(ArgumentError("Dimensions of problem/individuals do not match"))
20+
ss = search_space(eo)
2021
ssmins = mins(eo.searchSpace)
2122
ssmaxs = maxs(eo.searchSpace)
2223

23-
@inbounds for i in 1:length(target)
24+
@inbounds for i in eachindex(target)
2425
l, u = ssmins[i], ssmaxs[i]
2526

2627
if target[i] < l
27-
target[i] = l + rand() * (ref[i] - l)
28+
target[i] = l + rand() * (ref[i]-l)
2829
elseif target[i] > u
29-
target[i] = u + rand() * (ref[i] - u)
30+
target[i] = u + rand() * (ref[i]-u)
31+
else
32+
continue
3033
end
3134
@assert l <= target[i] <= u "target[$i]=$(target[i]) is out of [$l, $u]"
3235
end

src/ntuple_fitness.jl

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,12 @@ Always used when printing fitness vectors though.
3232
struct ParetoFitnessScheme{N,F<:Number,MIN,AGG} <: TupleFitnessScheme{N,F,NTuple{N,F},MIN,AGG}
3333
aggregator::AGG # fitness aggregation function
3434

35+
ParetoFitnessScheme{N,F,MIN,AGG}(; aggregator::AGG=sum) where {N, F<:Number, MIN, AGG} =
36+
new{N,F,MIN,AGG}(aggregator)
37+
38+
ParetoFitnessScheme{N,F,MIN}(; aggregator::AGG=sum) where {N, F<:Number, MIN, AGG} =
39+
new{N,F,MIN,AGG}(aggregator)
40+
3541
ParetoFitnessScheme{N,F}(; is_minimizing::Bool=true, aggregator::AGG=sum) where {N, F<:Number, AGG} =
3642
new{N,F,is_minimizing,AGG}(aggregator)
3743

@@ -291,16 +297,16 @@ hat_compare(u::IndexedTupleFitness{N,F}, v::IndexedTupleFitness{N,F},
291297

292298
hat_compare(u::NTuple{N,F}, v::IndexedTupleFitness{N,F},
293299
fs::EpsBoxDominanceFitnessScheme{N,F}, expected::Int=0) where {N,F} =
294-
hat_compare(convert(IndexedTupleFitness, u, fs), v, fs, expected)
300+
hat_compare(convert(IndexedTupleFitness{N,F}, u, fs), v, fs, expected)
295301

296302
hat_compare(u::IndexedTupleFitness{N,F}, v::NTuple{N,F},
297303
fs::EpsBoxDominanceFitnessScheme{N,F}, expected::Int=0) where {N,F} =
298-
hat_compare(u, convert(IndexedTupleFitness, v, fs), fs, expected)
304+
hat_compare(u, convert(IndexedTupleFitness{N,F}, v, fs), fs, expected)
299305

300306
hat_compare(u::NTuple{N,F}, v::NTuple{N,F},
301307
fs::EpsBoxDominanceFitnessScheme{N,F}, expected::Int=0) where {N,F} =
302-
hat_compare(convert(IndexedTupleFitness, u, fs),
303-
convert(IndexedTupleFitness, v, fs), fs, expected)
308+
hat_compare(convert(IndexedTupleFitness{N,F}, u, fs),
309+
convert(IndexedTupleFitness{N,F}, v, fs), fs, expected)
304310

305311
# special overload that strips index equality flag
306312
(hc::HatCompare{FS})(u::IndexedTupleFitness{N,F},

src/opt_controller.jl

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -395,11 +395,7 @@ end
395395
function init_rng!(parameters::Parameters)
396396
if parameters[:RandomizeRngSeed]
397397
parameters[:RngSeed] = rand(1:1_000_000)
398-
if VERSION < v"0.7.0-rc2"
399-
srand(parameters[:RngSeed])
400-
else
401-
Random.seed!(parameters[:RngSeed])
402-
end
398+
Random.seed!(parameters[:RngSeed])
403399
end
404400
end
405401

0 commit comments

Comments
 (0)