-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_ackley.jl
61 lines (52 loc) · 1.78 KB
/
test_ackley.jl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#!/usr/bin/env julia
import Random
import Statistics
import DelimitedFiles
include("model_ackley.jl")
include("solver_eks.jl")
include("solver_cbo.jl")
objective = Ackley.ackley
constraint = Ackley.sphere_constraint
grad_constraint = Ackley.grad_sphere_constraint
β = 1
λ = 1
σ = .7
Δ = .01
writedlm = DelimitedFiles.writedlm
datadir = "data/"
run(`mkdir -p $datadir`)
# ε = .1
J = 100
nsimuls = 100
ν, ε, nsimuls = 1, 1, 1
νs = [ν]
# νs = [10., 1., .1]
for ν in νs
config = Cbo.Config(β, λ, σ, Δ, ν, ε)
limits = zeros(Ackley.n, nsimuls)
Random.seed!(0);
for s in 1:nsimuls
global mean
ensembles = 10*Random.randn(Ackley.n, J)
distance, spread, niter = 10, 1, 0
while spread > 1e-10
# println("iteration $spread")
mean = Statistics.mean(ensembles, dims=2)
spread = sqrt(sum(abs2, Statistics.cov(ensembles, dims=2)))
ensembles = Cbo.step(objective, config, ensembles;
verbose=false, ineq_constraint=constraint,
# verbose=false, eq_constraint=constraint,
# grad_eq_constraint=nothing)
grad_ineq_constraint=grad_constraint)
# ensembles = Cbo.step(objective, config, ensembles;
# verbose=false, ineq_constraint=constraint)
println("$niter: Constraint: $(constraint(mean)), Distance: $distance, Spread: $spread")
niter += 1
writedlm(datadir * "niter=$niter.txt", ensembles)
end
println(s, mean, " ", constraint(mean))
limits[:, s] = mean
end
writedlm(datadir * "limits-nu=$ν-epsilon=$ε-J=$J.txt", limits)
writedlm(datadir * "limits.txt", limits)
end