def test_no_dof(self): TOL = 1E-10 v = ureal(4.999, 0.0032, independent=False) i = ureal(0.019661, 0.0000095, independent=False) phi = ureal(1.04446, 0.00075, independent=False) set_correlation(-0.36, v, i) set_correlation(0.86, v, phi) set_correlation(-0.65, i, phi) r = v * cos(phi) / i x = v * sin(phi) / i z = v / i equivalent(uncertainty(r), 0.0699787279884, TOL) equivalent(uncertainty(x), 0.295716826846, TOL) equivalent(uncertainty(z), 0.236602971835, TOL) equivalent(math.sqrt(welch_satterthwaite(r)[0]), uncertainty(r), TOL) equivalent(math.sqrt(welch_satterthwaite(x)[0]), uncertainty(x), TOL) equivalent(math.sqrt(welch_satterthwaite(z)[0]), uncertainty(z), TOL) equivalent(get_correlation(r, x), -0.591484610819, TOL) equivalent(get_correlation(x, z), 0.992797472722, TOL) equivalent(get_correlation(r, z), -0.490623905441, TOL)
def test_with_dof_2(self): """ Same test as above, but now ensure that the ensemble calculation can deal with influences that are not in sequence """ TOL = 1E-10 # The dummy variables mean that those included # in the ensemble will not be a consecutive # series of IDs, provided we include the # dummies in the equations, as is done below # with zero weight. v = ureal(4.999, 0.0032, 5, independent=False) dummy_1 = ureal(1, 1) i = ureal(0.019661, 0.0000095, 5, independent=False) dummy_2 = ureal(1, 1) phi = ureal(1.04446, 0.00075, 5, independent=False) dummy_3 = ureal(1, 1) real_ensemble([v, i, phi], 5) set_correlation(-0.36, v, i) set_correlation(0.86, v, phi) set_correlation(-0.65, i, phi) r = v * cos(phi) / i + (0 * dummy_1) x = v * sin(phi) / i + (0 * dummy_2) z = v / i + (0 * dummy_3) # The presence of finite DoF should not alter previous results equivalent(uncertainty(r), 0.0699787279884, TOL) equivalent(uncertainty(x), 0.295716826846, TOL) equivalent(uncertainty(z), 0.236602971835, TOL) equivalent(math.sqrt(welch_satterthwaite(r)[0]), uncertainty(r), TOL) equivalent(math.sqrt(welch_satterthwaite(x)[0]), uncertainty(x), TOL) equivalent(math.sqrt(welch_satterthwaite(z)[0]), uncertainty(z), TOL) equivalent(get_correlation(r, x), -0.591484610819, TOL) equivalent(get_correlation(x, z), 0.992797472722, TOL) equivalent(get_correlation(r, z), -0.490623905441, TOL) equivalent(dof(r), 5, TOL) equivalent(dof(x), 5, TOL) equivalent(dof(z), 5, TOL)
def test_with_dof(self): TOL = 1E-10 # The old way! # NB, I think there are now multiple instances of this test # v = ureal(4.999,0.0032,5,independent=False) # i = ureal(0.019661,0.0000095,5,independent=False) # phi = ureal(1.04446,0.00075,5,independent=False) v, i, phi = multiple_ureal([4.999, 0.019661, 1.04446], [0.0032, 0.0000095, 0.00075], 5) set_correlation(-0.36, v, i) set_correlation(0.86, v, phi) set_correlation(-0.65, i, phi) r = v * cos(phi) / i x = v * sin(phi) / i z = v / i # The presence of finite DoF should not alter previous results equivalent(uncertainty(r), 0.0699787279884, TOL) equivalent(uncertainty(x), 0.295716826846, TOL) equivalent(uncertainty(z), 0.236602971835, TOL) equivalent(math.sqrt(welch_satterthwaite(r)[0]), uncertainty(r), TOL) equivalent(math.sqrt(welch_satterthwaite(x)[0]), uncertainty(x), TOL) equivalent(math.sqrt(welch_satterthwaite(z)[0]), uncertainty(z), TOL) equivalent(get_correlation(r, x), -0.591484610819, TOL) equivalent(get_correlation(x, z), 0.992797472722, TOL) equivalent(get_correlation(r, z), -0.490623905441, TOL) equivalent(dof(r), 5, TOL) equivalent(dof(x), 5, TOL) equivalent(dof(z), 5, TOL) # Add another influence and it breaks again, but earlier results OK f = ureal(1, 0.0032, 5, independent=False) self.assertRaises(RuntimeError, set_correlation, 0.3, f, i) equivalent(dof(r), 5, TOL) equivalent(dof(x), 5, TOL) equivalent(dof(z), 5, TOL)
def test_with_dof_multiple_ureal(self): TOL = 1E-10 x = [4.999, 0.019661, 1.04446] u = [0.0032, 0.0000095, 0.00075] labels = ['v', 'i', 'phi'] v, i, phi = multiple_ureal(x, u, 5, labels) set_correlation(-0.36, v, i) set_correlation(0.86, v, phi) set_correlation(-0.65, i, phi) r = v * cos(phi) / i x = v * sin(phi) / i z = v / i # The presence of finite DoF should not alter previous results equivalent(uncertainty(r), 0.0699787279884, TOL) equivalent(uncertainty(x), 0.295716826846, TOL) equivalent(uncertainty(z), 0.236602971835, TOL) equivalent(math.sqrt(welch_satterthwaite(r)[0]), uncertainty(r), TOL) equivalent(math.sqrt(welch_satterthwaite(x)[0]), uncertainty(x), TOL) equivalent(math.sqrt(welch_satterthwaite(z)[0]), uncertainty(z), TOL) equivalent(get_correlation(r, x), -0.591484610819, TOL) equivalent(get_correlation(x, z), 0.992797472722, TOL) equivalent(get_correlation(r, z), -0.490623905441, TOL) # Dof calculation should be legal equivalent(dof(r), 5, TOL) equivalent(dof(x), 5, TOL) equivalent(dof(z), 5, TOL) # Add another influence and it breaks again, but earlier results OK f = ureal(1, 0.0032, 5, independent=False) self.assertRaises(RuntimeError, set_correlation, 0.3, f, i) equivalent(dof(r), 5, TOL) equivalent(dof(x), 5, TOL) equivalent(dof(z), 5, TOL)
def test(self): x = ureal(1, 1, 4) self.assertEqual(4, x.df) self.assertEqual(4, welch_satterthwaite(x)[1]) # product with zero values x1 = ureal(0, 1, 4) x2 = ureal(0, 1, 3) y = x1 * x2 self.assertEqual(0, y.u) self.assertTrue(nan is y.df) # Pathological case - not sure it can be created in practice x1 = ureal(1, 1) x2 = UncertainReal._elementary(1, 0, 4, label=None, independent=True) x3 = UncertainReal._elementary(1, 0, 3, label=None, independent=True) y = x1 + x2 + x3 self.assertEqual(len(y._u_components), 3) self.assertTrue(inf is y.df)