m-d-grunnill / MetaCast

A package for broadcasting epidimiological and ecological models over metapopulations.
Apache License 2.0
1 stars 1 forks source link

Support sampling from arbitrary distributions #9

Open robmoss opened 4 days ago

robmoss commented 4 days ago

This modifies the lhs_prcc function so that it can accept a dictionary that maps parameter names to percentage-point (inverse-CDF) functions. Here is an example of what it supports:

dist_nu = scipy.stats.beta(a=1, b=1, loc=0.767, scale=0.025)
dist_nu_lag = scipy.stats.beta(a=100, b=100, loc=1 / 28, scale=1 / 7 - 1 / 28)
dist_l_v = scipy.stats.beta(a=100, b=0.5, loc=0.3, scale=0.3)
dist_l_h = scipy.stats.beta(a=0.5, b=100, loc=0.7, scale=0.25)
parameter_dists = {
    'nu_unvaccinated': dist_nu.ppf,
    'nu_vaccination_lag': dist_nu_lag.ppf,
    'l_v': dist_l_v.ppf,
    'h_v': dist_l_h.ppf,
}
results_df, prccs = lhs_prcc(
    parameters_df=parameter_dists,
    # other arguments ...
)

I've added a new test case in tests/test_lhs_arbitrary_dists.py to check that the samples are consistent with the defined distributions.