diff options
Diffstat (limited to 'fits.cpp')
-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); } } |