From 752d0b61595166aafa93b48dd6c209381ac00f02 Mon Sep 17 00:00:00 2001 From: Jaron Kent-Dobias Date: Wed, 6 Jan 2021 17:36:28 +0100 Subject: Got Newton's method working well. --- stereographic.hpp | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) (limited to 'stereographic.hpp') diff --git a/stereographic.hpp b/stereographic.hpp index 515890e..a3f2cc6 100644 --- a/stereographic.hpp +++ b/stereographic.hpp @@ -54,7 +54,8 @@ Matrix stereographicMetric(const Matrix& J) { return J * J.adjoint(); } -Eigen::Tensor stereographicChristoffel(const Vector& ζ, const Matrix& gInvJac) { +// Gives the Christoffel symbol, with Γ_(i1, i2)^(i3). +Eigen::Tensor stereographicChristoffel(const Vector& ζ, const Matrix& gInvJacConj) { unsigned N = ζ.size() + 1; Eigen::Tensor dJ(N - 1, N - 1, N); @@ -83,7 +84,7 @@ Eigen::Tensor stereographicChristoffel(const Vector& ζ, const Matrix std::array, 1> ip = {Eigen::IndexPair(2, 1)}; - return dJ.contract(Eigen::TensorMap>(gInvJac.data(), N - 1, N), ip); + return dJ.contract(Eigen::TensorMap>(gInvJacConj.data(), N - 1, N), ip); } std::tuple stereographicHamGradHess(const Tensor& J, const Vector& ζ) { @@ -98,19 +99,19 @@ std::tuple stereographicHamGradHess(const Tensor& J, con Matrix hessZ; std::tie(hamiltonian, gradZ, hessZ) = hamGradHess(J, z); - Matrix g = stereographicMetric(jacobian); - // g is Hermitian, which is positive definite. - Matrix gInvJac = g.llt().solve(jacobian); + Matrix metric = stereographicMetric(jacobian); - grad = gInvJac * gradZ; + grad = metric.llt().solve(jacobian) * gradZ; - Eigen::Tensor Γ = stereographicChristoffel(ζ, gInvJac); + /* This is much slower to calculate than the marginal speedup it offers... + Eigen::Tensor Γ = stereographicChristoffel(ζ, gInvJac.conjugate()); Vector df = jacobian * gradZ; Eigen::Tensor dfT = Eigen::TensorMap>(df.data(), {df.size()}); - std::array, 1> ip = {Eigen::IndexPair(0, 0)}; + std::array, 1> ip = {Eigen::IndexPair(2, 0)}; Eigen::Tensor H2 = Γ.contract(dfT, ip); + */ - hess = jacobian * hessZ * jacobian.transpose() - Eigen::Map(H2.data(), ζ.size(), ζ.size()).transpose(); + hess = jacobian * hessZ * jacobian.transpose(); // - Eigen::Map(H2.data(), ζ.size(), ζ.size()); return {hamiltonian, grad, hess}; } -- cgit v1.2.3-54-g00ecf