statistically more valid test

This commit is contained in:
Martin Diehl 2020-09-20 21:50:52 +02:00
parent 6ab88aad2b
commit d33507866d
1 changed files with 25 additions and 18 deletions

View File

@ -907,20 +907,25 @@ class TestRotation:
@pytest.mark.parametrize('sigma',[5,10,15,20]) @pytest.mark.parametrize('sigma',[5,10,15,20])
@pytest.mark.parametrize('N',[1000,10000,100000]) @pytest.mark.parametrize('N',[1000,10000,100000])
def test_spherical_component(self,N,sigma): def test_spherical_component(self,N,sigma):
p = []
for run in range(5):
c = Rotation.from_random() c = Rotation.from_random()
o = Rotation.from_spherical_component(c,sigma,N) o = Rotation.from_spherical_component(c,sigma,N)
_, angles = c.misorientation(o).as_axis_angle(pair=True,degrees=True) _, angles = c.misorientation(o).as_axis_angle(pair=True,degrees=True)
angles[::2] *= -1 # flip angle for every second to symmetrize distribution angles[::2] *= -1 # flip angle for every second to symmetrize distribution
p = stats.normaltest(angles)[1] p.append(stats.normaltest(angles)[1])
sigma_out = np.std(angles) sigma_out = np.std(angles)
assert (.9 < sigma/sigma_out < 1.1) and p > 1e-4, f'{sigma/sigma_out},{p}' p = np.average(p)
assert (.9 < sigma/sigma_out < 1.1) and p > 1e-2, f'{sigma/sigma_out},{p}'
@pytest.mark.parametrize('sigma',[5,10,15,20]) @pytest.mark.parametrize('sigma',[5,10,15,20])
@pytest.mark.parametrize('N',[1000,10000,100000]) @pytest.mark.parametrize('N',[1000,10000,100000])
def test_from_fiber_component(self,N,sigma): def test_from_fiber_component(self,N,sigma):
"""https://en.wikipedia.org/wiki/Full_width_at_half_maximum.""" p = []
for run in range(5):
alpha = np.random.random()*2*np.pi,np.arccos(np.random.random()) alpha = np.random.random()*2*np.pi,np.arccos(np.random.random())
beta = np.random.random()*2*np.pi,np.arccos(np.random.random()) beta = np.random.random()*2*np.pi,np.arccos(np.random.random())
@ -933,6 +938,8 @@ class TestRotation:
angles = np.arccos(np.clip(np.dot(o@np.broadcast_to(f_in_S,(N,3)),n@f_in_S),-1,1)) angles = np.arccos(np.clip(np.dot(o@np.broadcast_to(f_in_S,(N,3)),n@f_in_S),-1,1))
dist = np.array(angles) * (np.random.randint(0,2,N)*2-1) dist = np.array(angles) * (np.random.randint(0,2,N)*2-1)
p = stats.normaltest(dist)[1] p.append(stats.normaltest(dist)[1])
sigma_out = np.degrees(np.std(dist)) sigma_out = np.degrees(np.std(dist))
assert (.9 < sigma/sigma_out < 1.1) and p > 1.e-4, f'{sigma/sigma_out},{p}' p = np.average(p)
assert (.9 < sigma/sigma_out < 1.1) and p > 1e-2, f'{sigma/sigma_out},{p}'