Skip to content

Commit ca926f6

Browse files
authored
Update to IntervalArithmetic v0.22 (#71)
1 parent c7de3d4 commit ca926f6

7 files changed

Lines changed: 100 additions & 123 deletions

File tree

.github/workflows/CI.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ jobs:
2929
with:
3030
version: ${{ matrix.version }}
3131
arch: ${{ matrix.arch }}
32-
- uses: actions/cache@v1
32+
- uses: actions/cache@v4
3333
env:
3434
cache-name: cache-artifacts
3535
with:

NEWS.md

Lines changed: 0 additions & 13 deletions
This file was deleted.

Project.toml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
name = "IntervalOptimisation"
22
uuid = "c7c68f13-a4a2-5b9a-b424-07d005f8d9d2"
3-
version = "0.4.6"
3+
version = "0.5.0"
44

55
[deps]
66
IntervalArithmetic = "d1acc4aa-44c8-5952-acd4-ba5d80a2a253"
77

88
[compat]
9-
IntervalArithmetic = "0.15, 0.16, 0.17, 0.18, 0.19, 0.20"
10-
julia = "1.0"
9+
IntervalArithmetic = "0.22"
10+
julia = "1.9"
1111

1212
[extras]
1313
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"

README.md

Lines changed: 29 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -1,91 +1,70 @@
1-
# `IntervalOptimisation.jl`
1+
<h1 align="center">
2+
IntervalOptimisation
23

3-
[![github badge][gh_badge]][gh_url]
4-
[![doc badge][doc_badge]][doc_url]
5-
[![codecov badge][codecov_badge]][codecov_url]
4+
[![Stable](https://img.shields.io/badge/docs-stable-blue.svg)](https://juliaintervals.github.io/IntervalOptimisation.jl/stable)
5+
[![Build Status](https://github.com/JuliaIntervals/IntervalOptimisation.jl/workflows/CI/badge.svg)](https://github.com/JuliaIntervals/IntervalOptimisation.jl/actions/workflows/CI.yml)
6+
[![coverage](https://codecov.io/gh/JuliaIntervals/IntervalOptimisation.jl/branch/master/graph/badge.svg)](https://codecov.io/gh/JuliaIntervals/IntervalOptimisation.jl)
7+
</h1>
68

7-
[gh_badge]: https://github.com/JuliaIntervals/IntervalOptimisation.jl/workflows/CI/badge.svg
8-
[gh_url]: https://github.com/JuliaIntervals/IntervalOptimisation.jl/actions/workflows/CI.yml
9-
10-
11-
[codecov_badge]: http://codecov.io/github/JuliaIntervals/IntervalOptimisation.jl/coverage.svg?branch=master
12-
[codecov_url]: http://codecov.io/github/JuliaIntervals/IntervalOptimisation.jl?branch=master
13-
14-
[doc_badge]: https://img.shields.io/badge/docs-stable-blue.svg
15-
[doc_url]: https://juliaintervals.github.io/pages/packages/intervaloptimisation/
16-
17-
18-
## Rigorous global optimisation using Julia
19-
20-
This package provides rigorous global optimisation routines written in pure Julia, using interval arithmetic provided by the author's [IntervalArithmetic.jl](https://github.com/JuliaIntervals/IntervalArithmetic.jl) package.
9+
IntervalOptimisation.jl is a Julia package for rigorous global optimisation routines, using interval arithmetic provided by the [IntervalArithmetic.jl](https://github.com/JuliaIntervals/IntervalArithmetic.jl) package.
2110

2211
Currently, the package uses an implementation of the Moore-Skelboe algorithm.
2312

2413
## Documentation
25-
Documentation for the package is available [here][doc_url].
2614

27-
The best way to learn how to use the package is to look at the tutorial, available in the organisation webpage [here](https://juliaintervals.github.io/pages/tutorials/tutorialOptimisation/).
15+
The official documentation is available online: https://juliaintervals.github.io/IntervalOptimisation.jl/stable.
2816

29-
## Usage
17+
## Usage
3018

31-
Functions `minimise` and `maximise` are provided to find the **global** minimum or maximum, respectively, of a standard Julia function `f` of one or several variables.
19+
Functions `minimise` and `maximise` are provided to find the **global** minimum or maximum, respectively, of a function `f` of one or several variables.
3220

33-
They return an `Interval` that is guaranteed to contain the global minimum (maximum), and a `Vector` of `Interval`s or `IntervalBox`es whose union contains all the minimisers.
21+
They return an `Interval` that is guaranteed to contain the global minimum (maximum), and a `Vector` of `Interval`s whose union contains all the minimisers.
3422

3523
### Examples
3624

3725
#### 1D
26+
3827
```julia
3928
using IntervalArithmetic, IntervalOptimisation
4029

41-
julia> @time global_min, minimisers = minimise(x -> (x^2 - 2)^2, -10..11);
42-
0.046620 seconds (36.07 k allocations: 1.586 MiB)
30+
julia> global_min, minimisers = minimise(x -> (x^2 - interval(2))^2, interval(-10, 11));
4331

4432
julia> global_min
45-
[0, 1.50881e-09]
33+
[0, 1.50881e-09]_com
4634

4735
julia> minimisers
48-
2-element Array{IntervalArithmetic.Interval{Float64},1}:
49-
[1.41387, 1.41453]
50-
[-1.41428, -1.41363]
36+
2-element Vector{Interval{Float64}}:
37+
[-1.41428, -1.41363]_com
38+
[1.41387, 1.41453]_com
5139
```
5240

5341
#### 2D
5442

5543
```julia
56-
julia> @time global_min, minimisers = minimise( X -> ( (x,y) = X; x^2 + y^2 ),
57-
(-10000..10001) × (-10000..10001) );
58-
0.051122 seconds (46.80 k allocations: 2.027 MiB)
44+
julia> global_min, minimisers = minimise(X -> ( (x,y) = X; x^2 + y^2 ), [interval(-10000, 10001), interval(-10000, 10001)]);
5945

6046
julia> global_min
61-
[0, 2.33167e-08]
47+
[0.0, 3.63963e-08]_com
6248

6349
julia> minimisers
64-
3-element Array{IntervalArithmetic.IntervalBox{2,Float64},1}:
65-
[-0.000107974, 0.000488103] × [-0.000107974, 0.000488103]
66-
[-0.000107974, 0.000488103] × [-0.000704051, -0.000107973]
67-
[-0.000704051, -0.000107973] × [-0.000107974, 0.000488103]
50+
3-element Vector{Vector{Interval{Float64}}}:
51+
[[-0.000412491, 0.00014269]_com, [-0.000412491, 0.00014269]_com]
52+
[[-0.000412491, 0.00014269]_com, [0.000142689, 0.000706613]_com]
53+
[[0.000142689, 0.000706613]_com, [-0.000412491, 0.00014269]_com]
6854
```
69-
Note that the last two `IntervalBox`es do not actually contain the global minimum;
55+
56+
Note that the last two `Vector` of `Interval`s do not actually contain the global minimum;
7057
decreasing the tolerance (maximum allowed box diameter) removes them:
7158

7259
```
73-
julia> @time global_min, minimisers = minimise( X -> ( (x,y) = X; x^2 + y^2 ),
74-
(-10000..10001) × (-10000..10001), 1e-5 );
75-
0.047196 seconds (50.72 k allocations: 2.180 MiB)
60+
julia> global_min, minimisers = minimise(X -> ( (x,y) = X; x^2 + y^2 ), [interval(-10000, 10001), interval(-10000, 10001)]; tol = 1e-8);
7661
7762
julia> minimisers
78-
1-element Array{IntervalArithmetic.IntervalBox{2,Float64},1}:
79-
[-5.52321e-06, 3.79049e-06] × [-5.52321e-06, 3.79049e-06]
63+
1-element Vector{Vector{Interval{Float64}}}:
64+
[[-4.74512e-09, 4.41017e-09]_com, [-4.74512e-09, 4.41017e-09]_com]
8065
```
8166

82-
## Author
83-
84-
- [David P. Sanders](http://sistemas.fciencias.unam.mx/~dsanders),
85-
Departamento de Física, Facultad de Ciencias, Universidad Nacional Autónoma de México (UNAM)
86-
87-
88-
## References:
67+
## References
8968

9069
- *Validated Numerics: A Short Introduction to Rigorous Computations*, W. Tucker, Princeton University Press (2010)
9170

@@ -94,6 +73,3 @@ Departamento de Física, Facultad de Ciencias, Universidad Nacional Autónoma de
9473
- van Emden M.H., Moa B. (2004). Termination Criteria in the Moore-Skelboe Algorithm for Global Optimization by Interval Arithmetic. In: Floudas C.A., Pardalos P. (eds), *Frontiers in Global Optimization. Nonconvex Optimization and Its Applications*, vol. 74. Springer, Boston, MA. [Preprint](http://webhome.cs.uvic.ca/~vanemden/Publications/mooreSkelb.pdf)
9574

9675
- H. Ratschek and J. Rokne, [*New Computer Methods for Global Optimization*](http://pages.cpsc.ucalgary.ca/~rokne/global_book.pdf)
97-
98-
## Acknowledements
99-
Financial support is acknowledged from DGAPA-UNAM PAPIIT grant IN-117117.

examples/griewank.jl

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using IntervalArithmetic, IntervalOptimisation
2+
using IntervalArithmetic.Symbols
23

34
G(X) = 1 + sum(abs2, X) / 4000 - prod( cos(X[i] / i) for i in 1:length(X) )
45

@@ -7,6 +8,6 @@ G(X) = 1 + sum(abs2, X) / 4000 - prod( cos(X[i] / √i) for i in 1:length(X) )
78

89
for N in (10, 30, 50)
910
@show N
10-
@time minimise(G, IntervalBox(-600..600, N))
11-
@time minimise(G, IntervalBox(-600..600, N))
11+
@time minimise(G, fill(-600..600, N))
12+
@time minimise(G, fill(-600..600, N))
1213
end

src/optimise.jl

Lines changed: 25 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,18 @@
1-
numeric_type(::Interval{T}) where {T} = T
2-
numeric_type(::IntervalBox{N, T}) where {N, T} = T
1+
numeric_type(x::Interval) = IntervalArithmetic.numtype(x)
2+
numeric_type(v::AbstractVector{<:Interval}) = mapreduce(IntervalArithmetic.numtype, IntervalArithmetic.promote_numtype, v)
3+
4+
_bisect(X::Interval) = bisect(X, 0.49609375)
5+
6+
function _bisect(X::AbstractVector{<:Interval}) # bisect along the largest dimension
7+
i = argmax(diam.(X)) # find longest side
8+
9+
x1, x2 = _bisect(X[i])
10+
11+
X1 = copy(X); X1[i] = x1
12+
X2 = copy(X); X2[i] = x2
13+
14+
return (X1, X2)
15+
end
316

417
"""
518
minimise(f, X, structure = SortedVector, tol=1e-3)
@@ -8,7 +21,7 @@ numeric_type(::IntervalBox{N, T}) where {N, T} = T
821
or
922
minimise(f, X, tol=1e-3) in this case the default value of "structure" is "HeapedVector"
1023
11-
Find the global minimum of the function `f` over the `Interval` or `IntervalBox` `X`
24+
Find the global minimum of the function `f` over the `Interval` or `AbstractVector{<:Interval}` `X`
1225
using the Moore-Skelboe algorithm. The way in which vector elements are
1326
kept arranged can be either a heaped array or a sorted array.
1427
If you not specify any particular strategy to keep vector elements arranged then
@@ -20,11 +33,11 @@ Returns an interval containing the global minimum, and a list of boxes that cont
2033
"""
2134
function minimise(f, X::T; structure = HeapedVector, tol=1e-3) where {T}
2235
nT = numeric_type(X)
23-
36+
2437
# list of boxes with corresponding lower bound, arranged according to selected structure :
25-
working = structure([(X, nT())], x->x[2])
38+
working = structure([(X, nT(Inf))], x->x[2])
2639
minimizers = T[]
27-
global_min = nT() # upper bound
40+
global_min = nT(Inf) # upper bound
2841

2942
num_bisections = 0
3043

@@ -37,19 +50,19 @@ function minimise(f, X::T; structure = HeapedVector, tol=1e-3) where {T}
3750
end
3851

3952
# find candidate for upper bound of global minimum by just evaluating a point in the interval:
40-
m = sup(f(Interval.(mid.(X)))) # evaluate at midpoint of current interval
53+
m = sup(f(interval.(mid.(X)))) # evaluate at midpoint of current interval
4154

4255
if m < global_min
4356
global_min = m
4457
end
4558

4659
# Remove all boxes whose lower bound is greater than the current one:
47-
filter_elements!(working , (X, global_min) )
60+
filter_elements!(working, (X, global_min))
4861

49-
if diam(X) < tol
62+
if maximum(diam, X) < tol
5063
push!(minimizers, X)
5164
else
52-
X1, X2 = bisect(X)
65+
X1, X2 = _bisect(X)
5366
push!( working, (X1, inf(f(X1))) )
5467
push!( working, (X2, inf(f(X2))) )
5568
num_bisections += 1
@@ -59,7 +72,7 @@ function minimise(f, X::T; structure = HeapedVector, tol=1e-3) where {T}
5972

6073
lower_bound = minimum(inf.(f.(minimizers)))
6174

62-
return Interval(lower_bound, global_min), minimizers
75+
return interval(lower_bound, global_min), minimizers
6376
end
6477

6578
"""
@@ -69,7 +82,7 @@ end
6982
or
7083
maximise(f, X, tol=1e-3) in this case the default value of "structure" is "HeapedVector"
7184
72-
Find the global maximum of the function `f` over the `Interval` or `IntervalBox` `X`
85+
Find the global maximum of the function `f` over the `Interval` or `AbstractVector{<:Interval}` `X`
7386
using the Moore-Skelboe algorithm. See [`minimise`](@ref) for a description
7487
of the available options.
7588
"""

0 commit comments

Comments
 (0)