diff --git a/tests/__init__.py b/tests/__init__.py index 65129d8..c8fe2c3 100644 --- a/tests/__init__.py +++ b/tests/__init__.py @@ -204,19 +204,14 @@ class GrayTest: err = data['Λ_r'].var() / 10 self.assertGreater(err, 0, msg="Λ is exactly constant") - def χ2(k, var): - ''' - Reduced χ² for the curve fit: Λ(s) = k⋅var(s) - ''' - res = (data['Λ_r'] - k*data[var]) / err - return np.sum(res**2) / (data.size - 1) - - import scipy.optimize - for var in ['X', 'Y', 'N_⊥']: - k_best = scipy.optimize.minimize(χ2, x0=1, args=var).x[0] + # Minimise the χ²(k) = |(Λ_r - k⋅var) / err|² / (n - 1) + # The solution is simply: k = (Λ⋅var)/var⋅var + k = np.dot(data['Λ_r'], data[var]) / np.linalg.norm(data[var])**2 with self.subTest(var=var): - self.assertGreater(χ2(k_best, var), 1) + res = (data['Λ_r'] - k*data[var]) / err + χ2 = np.linalg.norm(res)**2 / (data.size - 1) + self.assertGreater(χ2, 1) # Command line options