Skip to content

Commit 5dd515b

Browse files
authored
Complete rewrite using generic branch and prune with contractors (#24)
* Start refactoring using generic branch and prune * Make generic newton_helper for Newton and Krawczyk * Revert inadvertent modification to newton.jl * Add branch_and_prune.jl * Add bisection branch-and-prune example * Refactor to include f explicitly * Add explicit dimension to helpers * Add 2D bisection example * Multi-dim Newton working with some clumsiness Due to the interaction of FowardDiff and StaticArrays. JuliaDiff/ForwardDiff.jl#235 * Add 2D Newton example with required syntax for now * Docstring improvements * Use contractors * Add fudged Newton contractor * Add StaticArrays dependency * Add support for bisection of complex function * Remove Contractor from contractor object names * Export Bisection and Newton; remove _helper function * Fix Newton * Remove typing for Root * Cleanup and rewrite examples for new syntax * Add references to test suites * Export roots and invert order of f and X in argument list * Use IntervalArithmetic.Interval explicitly * Update examples (now roots.jl) * Use SVector in multidim Newton * Fix complex examples * Update minimum Julia version to 0.6 in REQUIRE and .travis * Fix examples.jl * Bump IntervalArithmetic to 0.12 in REQUIRE * Address problems in tests * Allow failures for nightly in travis * Allow root vector without :unique information. Add basic docstring for roots function * Add test_suites.md file with a list of places with test functions * Add tests of new root finders * Import roots from Polynomials.jl as stopgap measure * Fix typo * Fix test * Fix typo
1 parent f2f2251 commit 5dd515b

File tree

13 files changed

+545
-98
lines changed

13 files changed

+545
-98
lines changed

.travis.yml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,13 @@ os:
77
- osx
88

99
julia:
10-
- release
10+
- 0.6
1111
- nightly
1212

13+
matrix:
14+
allow_failures:
15+
- julia: nightly
16+
1317
notifications:
1418
email: false
1519

REQUIRE

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1-
julia 0.5
2-
IntervalArithmetic 0.9
1+
julia 0.6
2+
IntervalArithmetic 0.12
33
ForwardDiff 0.3
4+
StaticArrays 0.5
5+
Polynomials

docs/test_suites.md

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
2+
# Test suites:
3+
4+
- http://folk.uib.no/ssu029/Pdf_file/Testproblems/testprobRheinboldt03.pdf
5+
6+
- http://www.mat.univie.ac.at/~neum/glopt/test.html
7+
8+
- http://titan.princeton.edu/TestProblems/
9+
10+
- http://www-sop.inria.fr/saga/POL/
11+
12+
- MINPACK benchmarks: https://github.com/JuliaNLSolvers/NLsolve.jl/blob/master/test/minpack.jl
13+
14+
and other files in NLsolve test suite
15+
16+
17+
# Papers
18+
19+
- Testing unconstrained optimization software, Moré, Garbow, Hillstrom ACM Trans. Math. Soft. 7 (1), 17-41 (1981)

examples/complex_roots.jl

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

examples/roots.jl

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
2+
using IntervalArithmetic, IntervalRootFinding, StaticArrays
3+
4+
rts = roots(sin, -5..5)
5+
6+
rts = roots(sin, -5..6, Bisection)
7+
rts = roots(sin, rts, Newton)
8+
9+
# 2D:
10+
f(x, y) = SVector(x^2 + y^2 - 1, y - x)
11+
f(X) = f(X...)
12+
13+
rts = roots(f, (-5..5) × (-5..5))
14+
rts = roots(f, rts, Bisection)
15+
16+
# complex:
17+
x = -5..6
18+
Xc = Complex(x, x)
19+
f(z) = z^3 - 1
20+
21+
rts = roots(f, Xc, Bisection)
22+
rts = roots(f, rts, Newton)
23+
rts = roots(f, Xc)
24+
25+
# From R docs:
26+
27+
# https://www.rdocumentation.org/packages/pracma/versions/1.9.9/topics/broyden
28+
29+
function g(x)
30+
(x1, x2, x3) = x
31+
SVector( x1^2 + x2^2 + x3^2 - 1,
32+
x1^2 + x3^2 - 0.25,
33+
x1^2 + x2^2 - 4x3
34+
)
35+
end
36+
37+
X = (-5..5)
38+
@time rts = roots(g, X × X × X)
39+
40+
41+
42+
43+
44+
h(xv) = ((x,y) = xv; SVector(2*x - y - exp(-x), -x + 2*y - exp(-y)))
45+
46+
rts = roots(h, X × X, Bisection)
47+
rts = roots(h, rts, Newton)
48+
49+
50+
51+
# Dennis-Schnabel:
52+
h(xv) = ((x, y) = xv; SVector(x^2 + y^2 - 2, exp(x - 1) + y^3 - 2))
53+
54+
rts = roots(h, X × X, Bisection)
55+
rts = roots(h, rts, Newton)
56+
57+
# Test suites:
58+
59+
# http://folk.uib.no/ssu029/Pdf_file/Testproblems/testprobRheinboldt03.pdf
60+
61+
# http://www.mat.univie.ac.at/~neum/glopt/test.html
62+
63+
# http://titan.princeton.edu/TestProblems/
64+
65+
# http://www-sop.inria.fr/saga/POL/
66+
67+
## MINPACK benchmarks: https://github.com/JuliaNLSolvers/NLsolve.jl/blob/master/test/minpack.jl
68+
69+
rosenbrock(x, y) = SVector( 1 - x, 10 * (y - x^2) )
70+
rosenbrock(X) = rosenbrock(X...)
71+
72+
rosenbrock(xx) = ( (x, y) = xx; SVector( 1 - x, 1000 * (y - x^2) ) )
73+
X = IntervalBox(-1e5..1e5, 2)
74+
75+
rts = roots(rosenbrock, X)
76+
77+
78+
79+
# and other files in NLsolve test suite
80+
81+
82+
83+
# Testing unconstrained optimization software, Moré, Garbow, Hillstrom ACM Trans. Math. Soft. 7 (1), 17-41 (1981)

src/IntervalRootFinding.jl

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,24 +6,26 @@ module IntervalRootFinding
66

77
using IntervalArithmetic
88
using ForwardDiff
9+
using StaticArrays
10+
11+
import Polynomials: roots
912

1013
## Root finding
1114
export
12-
newton, krawczyk,
1315
derivative, jacobian, # reexport derivative from ForwardDiff
1416
Root, is_unique,
15-
find_roots,
16-
find_roots_midpoint,
17-
bisection,
17+
roots, find_roots,
1818
bisect
1919

2020
import Base: , show
2121

22+
const Interval = IntervalArithmetic.Interval
23+
2224
const derivative = ForwardDiff.derivative
2325
const D = derivative
2426

2527
# Root object:
26-
immutable Root{T<:Union{Interval,IntervalBox}}
28+
immutable Root{T}
2729
interval::T
2830
status::Symbol
2931
end
@@ -58,7 +60,8 @@ include("bisect.jl")
5860
include("bisection.jl")
5961
include("newton.jl")
6062
include("krawczyk.jl")
61-
63+
include("complex.jl")
64+
include("branch_and_prune.jl")
6265

6366
function find_roots{T}(f::Function, a::Interval{T}, method::Function = newton;
6467
tolerance = eps(T), debug = false, maxlevel = 30)

src/bisection.jl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@ function bisection{T<:Union{Interval,IntervalBox}}(f, X::T; tolerance=1e-3, debu
1010

1111
debug && @show X, image
1212

13-
if !(zero(X) image)
13+
#if !(zero(X) ⊆ image)
14+
if !(contains_zero(image))
1415
return Root{typeof(X)}[]
1516
end
1617

0 commit comments

Comments
 (0)