diff --git a/src/Hyperopt.jl b/src/Hyperopt.jl index 7160cc6..7b19820 100644 --- a/src/Hyperopt.jl +++ b/src/Hyperopt.jl @@ -40,8 +40,8 @@ end function Base.getproperty(ho::Hyperoptimizer, s::Symbol) s === :minimum && (return isempty(ho.results) ? NaN : minimum(replace(ho.results, NaN => Inf))) s === :minimizer && (return isempty(ho.results) ? [] : ho.history[argmin(replace(ho.results, NaN => Inf))]) - s === :maximum && (return isempty(ho.results) ? NaN : maximum(replace(ho.results, NaN => Inf))) - s === :maximizer && (return isempty(ho.results) ? [] : ho.history[argmax(replace(ho.results, NaN => Inf))]) + s === :maximum && (return isempty(ho.results) ? NaN : maximum(replace(ho.results, NaN => -Inf))) + s === :maximizer && (return isempty(ho.results) ? [] : ho.history[argmax(replace(ho.results, NaN => -Inf))]) return getfield(ho,s) end diff --git a/test/runtests.jl b/test/runtests.jl index d8ebe9c..3adf349 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -41,6 +41,14 @@ end @test length(hor.history) == 102 @test length(hor.results) == 102 + # Test NaN handling + ho2 = @hyperopt for i=2, sampler=RandomSampler(), a = [20], b = [1] + i == 1 ? a*b : NaN + end + @test ho2.minimum == 20 + @test ho2.maximum == 20 + @test ho2.minimizer == [20, 1] + @test ho2.maximizer == [20, 1] end @testset "Latin hypercube" begin