summaryrefslogtreecommitdiff
path: root/fits.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'fits.cpp')
-rw-r--r--fits.cpp7
1 files changed, 4 insertions, 3 deletions
diff --git a/fits.cpp b/fits.cpp
index 370b63d..62d75c9 100644
--- a/fits.cpp
+++ b/fits.cpp
@@ -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);
}
}