From a7bcc3ec2cb33d183bd427aa9053b94a64d79814 Mon Sep 17 00:00:00 2001 From: Luis Aleixo Date: Mon, 2 May 2022 11:18:49 +0200 Subject: [PATCH] Removed beta distribution and added custom distribution for the interpersonal distances distribution --- cara/monte_carlo/data.py | 8 ++++++-- cara/monte_carlo/sampleable.py | 19 ------------------- cara/tests/models/test_short_range_model.py | 6 +++--- 3 files changed, 9 insertions(+), 24 deletions(-) diff --git a/cara/monte_carlo/data.py b/cara/monte_carlo/data.py index a725b8fa..bf9c148c 100644 --- a/cara/monte_carlo/data.py +++ b/cara/monte_carlo/data.py @@ -5,7 +5,7 @@ import numpy as np from scipy import special as sp import cara.monte_carlo as mc -from cara.monte_carlo.sampleable import LogNormal,LogCustomKernel,CustomKernel,Uniform, Beta +from cara.monte_carlo.sampleable import LogNormal,LogCustomKernel,CustomKernel,Uniform, Custom sqrt2pi = np.sqrt(2.*np.pi) @@ -203,4 +203,8 @@ short_range_expiration_distributions = { # Derived from Fig 8 a) "stand-stand" in https://www.mdpi.com/1660-4601/17/4/1445/htm -short_range_distances = Beta(alpha=0.588715, beta=1.50214, loc=0.5, scale=1.5) \ No newline at end of file +distances = np.array((0.5,0.6,0.7,0.8,0.9,1,1.1,1.2,1.3,1.4,1.5,1.6,1.7,1.8,1.9,2)) +frequencies = np.array((0.0598036,0.0946154,0.1299152,0.1064905,0.1099066,0.0998209, 0.0845298,0.0479286,0.0406084,0.039795,0.0205997,0.0152316,0.0118155,0.0118155,0.018485,0.0205997)) +short_range_distances = Custom(bounds=(0.5,2.), + function=lambda x: np.interp(x,distances,frequencies,left=0.,right=0.), + max_function=0.13) \ No newline at end of file diff --git a/cara/monte_carlo/sampleable.py b/cara/monte_carlo/sampleable.py index d9d4afc7..27907e49 100644 --- a/cara/monte_carlo/sampleable.py +++ b/cara/monte_carlo/sampleable.py @@ -2,7 +2,6 @@ import typing import numpy as np from sklearn.neighbors import KernelDensity # type: ignore -from scipy.stats import beta import cara.models @@ -131,24 +130,6 @@ class LogCustomKernel(SampleableDistribution): return 10 ** kde_model.sample(n_samples=size)[:, 0] -class Beta(SampleableDistribution): - """ - Defines a Beta distribution parameterized by two positive shape parameters, - denoted by alpha (α) and beta (β), that appear as exponents of the random - variable and control the shape of the distribution. - """ - - def __init__(self, alpha: float, beta: float, loc: float, scale: float): - # these are resp. the alpha and beta of the underlying distribution - self.alpha = alpha - self.beta = beta - self.loc = loc - self.scale = scale - - def generate_samples(self, size: int) -> float_array_size_n: - return beta.rvs(a = self.alpha, b = self.beta, loc=self.loc, scale=self.scale, size=size) - - _VectorisedFloatOrSampleable = typing.Union[ SampleableDistribution, cara.models._VectorisedFloat, ] diff --git a/cara/tests/models/test_short_range_model.py b/cara/tests/models/test_short_range_model.py index 481860a8..6f4de3d2 100644 --- a/cara/tests/models/test_short_range_model.py +++ b/cara/tests/models/test_short_range_model.py @@ -72,9 +72,9 @@ def test_dilution_factor(activity, expected_dilution): @pytest.mark.parametrize( "time, expected_short_range_concentration", [ [8.5, 0.], - [10.5, 8.037883241318065], - [10.6, 8.037883241318065], - [11.0, 8.037883241318065], + [10.5, 5.401601371244907], + [10.6, 5.401601371244907], + [11.0, 5.401601371244907], [12.0, 0.], ] )