Skip to content

Instantly share code, notes, and snippets.

@dpsanders
Created November 23, 2019 22:46
Show Gist options
  • Save dpsanders/acdd31e2e6d0ad8aceca393369a83ba3 to your computer and use it in GitHub Desktop.
Save dpsanders/acdd31e2e6d0ad8aceca393369a83ba3 to your computer and use it in GitHub Desktop.
using TaylorSeries, StaticArrays, ForwardDiff
f( (x, y) ) = x^2 + 5x*y + 2y^2
H = zeros(2, 2)
t = Taylor1(2)
a, b, = 1, 2
H_target = ForwardDiff.hessian(f, SA[a, b])
xx = a + t
yy = b + 0t
H[1, 1] = 2 * f( (xx, yy) )[2]
H[2, 2] = 2 * f( (a + 0t, b + t))[2]
v = SA[1, 1]
xx = SA[a, b] .+ t.*v
f(xx)
f(xx)[2] - 0.5*(H[1, 1] + H[2, 2])
## H[1, 1] + 2 H[1, 2] + H[2, 2]
# 2nd order term is 0.5*∑ v_i H_{ij} v_j
# If v_i == v_j == 1 then this is ∑ H_{ij} / 2
# So H[1, 2] = 2nd_order_term - H[1, 1] - H[1, 2]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment