Skip to content

Commit 4099735

Browse files
committed
Initial implementation of global optimisation
1 parent 2499f85 commit 4099735

File tree

1 file changed

+52
-0
lines changed

1 file changed

+52
-0
lines changed

src/optimise1.jl

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
using IntervalArithmetic, DataStructures
2+
3+
import Base.isless
4+
5+
struct IntervalMinima{T<:Real}
6+
intval::Interval{T}
7+
minima::T
8+
end
9+
10+
function isless(a::IntervalMinima{T}, b::IntervalMinima{T}) where {T<:Real}
11+
return isless(a.minima, b.minima)
12+
end
13+
14+
function minimise1d(f::Function, x::Interval{T}; reltol=1e-3, abstol=1e-3) where {T<:Real}
15+
16+
Q = binary_minheap(IntervalMinima{T})
17+
18+
minima = f(interval(mid(x))).hi
19+
arg_minima = Interval{T}[]
20+
21+
push!(Q, IntervalMinima(x, minima))
22+
23+
while !isempty(Q)
24+
25+
p = pop!(Q)
26+
27+
if p.minima > minima
28+
continue
29+
end
30+
#
31+
# if 0 ∉ ForwardDiff.derivative(f, p.intval)
32+
# continue
33+
# end
34+
35+
# current_minima = f(p.intval).lo
36+
37+
current_minima = f(interval(mid(p.intval))).hi
38+
39+
if current_minima < minima
40+
minima = current_minima
41+
end
42+
43+
if diam(p.intval) < abstol
44+
push!(arg_minima, p.intval)
45+
else
46+
x1, x2 = bisect(p.intval)
47+
push!(Q, IntervalMinima(x1, f(x1).lo), IntervalMinima(x2, f(x2).lo))
48+
end
49+
end
50+
51+
return minima, arg_minima
52+
end

0 commit comments

Comments
 (0)