From bbc56fde4cffb5fc85dbb5d78a2994a3b14bdb7e Mon Sep 17 00:00:00 2001 From: Jaron Kent-Dobias Date: Sun, 21 Apr 2024 17:31:38 +0200 Subject: Small refactoring. --- least_squares.cpp | 21 ++++++++------------- 1 file changed, 8 insertions(+), 13 deletions(-) (limited to 'least_squares.cpp') diff --git a/least_squares.cpp b/least_squares.cpp index 1fd25e1..d80fd2d 100644 --- a/least_squares.cpp +++ b/least_squares.cpp @@ -17,7 +17,7 @@ class Tensor : public Eigen::Tensor { public: Matrix operator*(const Vector& x) const { - const std::array, 1> ip20 = {Eigen::IndexPair(2, 0)}; + std::array, 1> ip20 = {Eigen::IndexPair(2, 0)}; const Eigen::Tensor xT = Eigen::TensorMap>(x.data(), x.size()); const Eigen::Tensor JxT = contract(xT, ip20); return Eigen::Map(JxT.data(), dimension(0), dimension(1)); @@ -25,14 +25,14 @@ public: }; Matrix operator*(const Eigen::Matrix& x, const Tensor& J) { - const std::array, 1> ip00 = {Eigen::IndexPair(0, 0)}; + std::array, 1> ip00 = {Eigen::IndexPair(0, 0)}; const Eigen::Tensor xT = Eigen::TensorMap>(x.data(), x.size()); const Eigen::Tensor JxT = J.contract(xT, ip00); return Eigen::Map(JxT.data(), J.dimension(1), J.dimension(2)); } Vector normalize(const Vector& x) { - return x * sqrt((Real)x.size() / x.squaredNorm()); + return x * sqrt(x.size() / x.squaredNorm()); } Vector makeTangent(const Vector& v, const Vector& x) { @@ -82,23 +82,23 @@ public: unsigned N; unsigned M; - QuadraticModel(unsigned N, unsigned M, Rng& r, Real μ1, Real μ2, Real μ3) : J(M, N, N), A(M, N), b(M), N(N), M(M) { + QuadraticModel(unsigned N, unsigned M, Rng& r, Real σ², Real μA, Real μJ) : J(M, N, N), A(M, N), b(M), N(N), M(M) { Eigen::StaticSGroup> sym23; for (unsigned k = 0; k < N; k++) { for (unsigned j = k; j < N; j++) { for (unsigned i = 0; i < M; i++) { - sym23(J, i, j, k) = r.variate(0, sqrt(2 * μ3) / N); + sym23(J, i, j, k) = r.variate(0, sqrt(2 * μJ) / N); } } } for (Real& Aij : A.reshaped()) { - Aij = r.variate(0, sqrt(μ2 / N)); + Aij = r.variate(0, sqrt(μA / N)); } for (Real& bi : b) { - bi = r.variate(0, sqrt(μ1)); + bi = r.variate(0, sqrt(σ²)); } } @@ -108,17 +108,12 @@ public: Vector getGradient(const Vector& x) const { auto [V, ∂V, ∂∂V] = V_∂V_∂∂V(x); - return ∇HFromV∂Vx(V, ∂V, x); } std::tuple getHamGrad(const Vector& x) const { auto [V, ∂V, ∂∂V] = V_∂V_∂∂V(x); - - Real H = HFromV(V); - Vector ∇H = ∇HFromV∂Vx(V, ∂V, x); - - return {H, ∇H}; + return {HFromV(V), ∇HFromV∂Vx(V, ∂V, x)}; } Matrix getHessian(const Vector& x) const { -- cgit v1.2.3-70-g09d2