-
Notifications
You must be signed in to change notification settings - Fork 21
Expand file tree
/
Copy pathcentered_forms.jl
More file actions
34 lines (24 loc) · 951 Bytes
/
centered_forms.jl
File metadata and controls
34 lines (24 loc) · 951 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
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)