Repository: fitbenchmarking/fitbenchmarking

Issue:
Wrong `chi_sq` value produced
**Description of the error**
Noticed by @AndrewLister-STFC in the review of #316 that the `chi_sq` computed in `utils/fitting/misc.py` is incorrect. 

**Describe the expected result**
Fixed reported `chi_sq` value


Discussion:

Patch:
diff --git a/fitbenchmarking/fitting/misc.py b/fitbenchmarking/fitting/misc.py
index 73ccd9e5..3120ebfc 100644
--- a/fitbenchmarking/fitting/misc.py
+++ b/fitbenchmarking/fitting/misc.py
@@ -20,10 +20,8 @@ def compute_chisq(actual, fitted, errors=None):
     """
     r = fitted - actual
     if errors is not None:
-        weighted_r = np.multiply(errors, r)
-        chi_sq = np.dot(r, weighted_r)
-    else:
-        chi_sq = np.dot(r, r)
+        r = r / errors
+    chi_sq = np.dot(r, r)
 
     return chi_sq
 
@@ -46,8 +44,10 @@ def create_result_entry(problem, status, chi_sq, runtime, minimizer,
     """
 
     if 'fitFunction' in ini_function_def:
-        ini_function_def = ini_function_def.replace('fitFunction', problem.equation)
-        fin_function_def = fin_function_def.replace('fitFunction', problem.equation)
+        ini_function_def = ini_function_def.replace(
+            'fitFunction', problem.equation)
+        fin_function_def = fin_function_def.replace(
+            'fitFunction', problem.equation)
 
     # Create empty fitting result object
     result = fitbm_result.FittingResult()


Test patch:
diff --git a/fitbenchmarking/fitting/tests/test_misc.py b/fitbenchmarking/fitting/tests/test_misc.py
index b74458e2..1363554a 100644
--- a/fitbenchmarking/fitting/tests/test_misc.py
+++ b/fitbenchmarking/fitting/tests/test_misc.py
@@ -79,7 +79,7 @@ class FitMiscTests(unittest.TestCase):
         errors = np.array([5, 0.1, 0.5])
 
         chi_sq = compute_chisq(actual, calculated, errors)
-        chi_sq_expected = 9.9
+        chi_sq_expected = 436.04
 
         self.assertEqual(chi_sq_expected, chi_sq)