Skip to content

Commit

Permalink
Iterate named tuples, fixes #42
Browse files Browse the repository at this point in the history
  • Loading branch information
baggepinnen committed Dec 30, 2020
1 parent f4ce4c3 commit fecc1c4
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 3 deletions.
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "Hyperopt"
uuid = "93e5fe13-2215-51db-baaf-2e9a34fb2712"
author = ["Fredrik Bagge Carlson <[email protected]>"]
version = "0.3.4"
version = "0.3.5"

[deps]
BayesianOptimization = "4c6ed407-134f-591c-93fa-e0f7c164a0ec"
Expand Down
3 changes: 2 additions & 1 deletion src/Hyperopt.jl
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,8 @@ function Base.iterate(ho::Hyperoptimizer, state=1)
state > ho.iterations && return nothing
samples = ho.sampler(ho, state)
push!(ho.history, samples)
[state;samples], state+1
nt = (; Pair.([:i, ho.params...], [state; samples])...)
nt, state+1
end

function preprocess_expression(ex)
Expand Down
2 changes: 1 addition & 1 deletion src/samplers.jl
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ function (s::GPSampler)(ho, iter)
# iters = 3000
ho2 = Hyperoptimizer(iterations=iters, params=ho.params, candidates=s.candidates)
for params in ho2
params2 = params[2:end]
params2 = collect(params)[2:end]
res = -Inf
try
res = acqfunc(params2)
Expand Down
5 changes: 5 additions & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,11 @@ f(a,b=true;c=10) = sum(@. 100 + (a-3)^2 + (b ? 10 : 20) + (c-100)^2) # This func
println(i, "\t", a, "\t", b, "\t", c)
end

ho = Hyperoptimizer(10, a = range(1, stop=2, length=50), b = [true, false], c = randn(100))
for vals in ho
println(vals.i, "\t", vals.a, "\t", vals.b, "\t", vals.c)
end

end


Expand Down

0 comments on commit fecc1c4

Please sign in to comment.