def test_two(): density1 = [0, 0, 0, 0, 0.1, 0.4, 0.2, 0.1, 0.1, 0.1, 0, 0, 0, 0, 0] density2 = [0, 0, 0, 0.1, 0.15, 0.35, 0.15, 0.15, 0.1, 0, 0, 0, 0] density = convolve_two(density1=density1, density2=density2, L=20) mu_before = mean_of_density(density1, unit=1) + mean_of_density(density2, unit=1) mu_after = mean_of_density(density, unit=1) assert abs(mu_after - mu_before) < 1e-4
def test_two_skew(): density1 = skew_normal_density(L=50, unit=1.0, scale=5.0, a=1.0) density2 = skew_normal_density(L=50, unit=1.0, scale=5.0, loc=1.2, a=-1.0) density = convolve_two(density1=density1, density2=density2, L=100) mu_before = mean_of_density(density1, unit=1) + mean_of_density(density2, unit=1) mu_after = mean_of_density(density, unit=1) assert abs(mu_after - mu_before) < 1e-4
def test_shift_pdf_integer(): cdf = example_cdf() pdf = cdf_to_pdf(cdf) x = 2 pdf_moved = fractional_shift(cdf=pdf, x=x) mean_before = mean_of_density(pdf, unit=1) mean_after = mean_of_density(pdf_moved, unit=1) mean_diff = mean_after - mean_before assert abs(mean_diff - x) < 1e-6
def test_many_skew(): densities = [ skew_normal_density(L=50, unit=1.0, scale=5.0, a=1.0) for _ in range(10) ] density = convolve_many(densities=densities, L=500, do_padding=True) assert len(density) == 1001 mu_before = sum([mean_of_density(d, unit=1) for d in densities]) mu_after = mean_of_density(density, unit=1) assert abs(mu_after - mu_before) < 1e-4
def test_many_many_normal(): densities = [ skew_normal_density(L=50, unit=1.0, scale=5.0, a=0.0) for _ in range(100) ] L = 5000 density = convolve_many(densities=densities, L=L) assert len(density) == 2 * L + 1 mu_before = sum([mean_of_density(d, unit=1) for d in densities]) mu_after = mean_of_density(density, unit=1) assert abs(mu_after - mu_before) < 1e-4
def test_die(): x = [ np.random.choice([-2.5, -1.5, -0.5, 0, 0.5, 1.5, 2.5]) for _ in range(10000) ] unit = 1 d = density_from_samples(x=x, L=5, unit=0.5) mu = mean_of_density(density=d, unit=unit) print(mu) return d
def mean_of_cdf(cdf): pdf = cdf_to_pdf(cdf) return mean_of_density(pdf, unit=1)
def demo(): skew = skew_normal_density(L=L, unit=unit, a=1.0) print("mean is " + str(mean_of_density(skew, unit=unit))) densitiesPlot([skew], unit=unit)
def test_samples(): x = np.random.randn(5000) unit = 0.05 d = density_from_samples(x=x, L=501, unit=unit) mu = mean_of_density(density=d, unit=unit)