Skip to content

Add centered forms for scalar-valued functions #25

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions src/IntervalOptimisation.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,21 @@

module IntervalOptimisation

using IntervalArithmetic, IntervalRootFinding
using LinearAlgebra

export minimise, maximise,
minimize, maximize

export mean_value_form_scalar, third_order_taylor_form_scalar


include("SortedVectors.jl")
using .SortedVectors

using IntervalArithmetic, IntervalRootFinding


include("optimise.jl")
include("centered_forms.jl")

const minimize = minimise
const maximize = maximise
Expand Down
34 changes: 34 additions & 0 deletions src/centered_forms.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@

import ForwardDiff: gradient, jacobian, hessian

gradient(f, X::IntervalBox) = gradient(f, X.v)
# jacobian(f, X::IntervalBox) = jacobian(f, X.v)
hessian(f, X::IntervalBox) = hessian(f, X.v)

"""
Calculate the mean-value form of a function ``f:\\mathbb{R}^n \\to \\mathbb{R}``
using the gradient ``\nabla f``;
this gives a second-order approximation.
"""
function mean_value_form_scalar(f, X)
m = IntervalBox(mid(X))

return f(m) + gradient(f, X.v) ⋅ (X - m)
end

mean_value_form_scalar(f) = X -> mean_value_form_scalar(f, X)


"""
Calculate a third-order Taylor form of ``f:\\mathbb{R}^n \\to \\mathbb{R}`` using the Hessian.
"""
function third_order_taylor_form_scalar(f, X)
m = IntervalBox(mid(X))

H = hessian(f, X)
δ = X - m

return f(m) + gradient(f, m) ⋅ δ + 0.5 * sum(δ[i]*H[i,j]*δ[j] for i in 1:length(X) for j in 1:length(X))
end

third_order_taylor_form_scalar(f) = X -> third_order_taylor_form_scalar(f, X)
5 changes: 4 additions & 1 deletion src/optimise.jl
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@

interval_mid(X::Interval) = Interval(mid(X))
interval_mid(X::IntervalBox) = IntervalBox(mid(X))

"""
minimise(f, X, tol=1e-3)

Expand Down Expand Up @@ -27,7 +30,7 @@ function minimise(f, X::T, tol=1e-3) where {T}
end

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

if m < global_min
global_min = m
Expand Down