diff options
author | Jaron Kent-Dobias <jaron@kent-dobias.com> | 2025-02-10 08:24:43 -0300 |
---|---|---|
committer | Jaron Kent-Dobias <jaron@kent-dobias.com> | 2025-02-10 08:24:43 -0300 |
commit | efd5b5bea4640e498686f1c7f2eae44d2caad44b (patch) | |
tree | a9b6f4656c4961a0d9492127df511d25917993ea | |
parent | 9a9f982ff10e2130475204985c6f98637ce826b3 (diff) | |
download | ictp-saifr_colloquium-efd5b5bea4640e498686f1c7f2eae44d2caad44b.tar.gz ictp-saifr_colloquium-efd5b5bea4640e498686f1c7f2eae44d2caad44b.tar.bz2 ictp-saifr_colloquium-efd5b5bea4640e498686f1c7f2eae44d2caad44b.zip |
Slightly more effecient calculation of gradient
-rw-r--r-- | fits.cpp | 7 |
1 files changed, 4 insertions, 3 deletions
@@ -57,11 +57,12 @@ Real cost(const std::list<std::tuple<Real, Real>>& data, const Vector& coeffs) { Vector dCost(const std::list<std::tuple<Real, Real>>& data, const Vector& coeffs) { Vector dC = Vector::Zero(coeffs.size()); - for (unsigned j = 0; j < coeffs.size(); j++) { - for (const std::tuple<Real, Real>& xy : data) { + for (const std::tuple<Real, Real>& xy : data) { + for (unsigned j = 0; j < coeffs.size(); j++) { Real x = std::get<0>(xy); Real y = std::get<1>(xy); - dC[j] += (value(coeffs, x) - y) * basisFunctions(coeffs.size(), j, x); + Real Δc = value(coeffs, x) - y; + dC[j] += Δc * basisFunctions(coeffs.size(), j, x); } } |