Adding similar test for Muir distribution

This commit is contained in:
Patrick Shriwise 2022-04-06 10:35:46 -05:00
parent 2f22474aea
commit 2c74dcf336
2 changed files with 16 additions and 2 deletions

View file

@ -764,11 +764,14 @@ class Muir(Univariate):
cv.check_greater_than('Muir kt', kt, 0.0)
self._kt = kt
@property
def std_dev(self):
return np.sqrt(4.*self.e0*self.kt/self.m_rat)
def sample(self, n_samples=1, seed=None):
# https://permalink.lanl.gov/object/tr?what=info:lanl-repo/lareport/LA-05411-MS
np.random.seed(seed)
sigma = np.sqrt(4.*self.e0*self.kt/self.m_rat)
return np.random.normal(self.e0, sigma, n_samples)
return np.random.normal(self.e0, self.std_dev, n_samples)
def to_xml_element(self, element_name):
"""Return XML representation of the Watt distribution

View file

@ -292,3 +292,14 @@ def test_muir():
assert d.m_rat == pytest.approx(mass)
assert d.kt == pytest.approx(temp)
assert len(d) == 3
# sample normal distribution
n_samples = 10000
samples = d.sample(n_samples, seed=100)
samples = np.abs(samples - mean)
within_1_sigma = np.count_nonzero(samples < d.std_dev)
assert within_1_sigma / n_samples >= 0.68
within_2_sigma = np.count_nonzero(samples < 2*d.std_dev)
assert within_2_sigma / n_samples >= 0.95
within_3_sigma = np.count_nonzero(samples < 3*d.std_dev)
assert within_3_sigma / n_samples >= 0.99