15#include <mp-units/math.h>
16#include <mp-units/systems/si.h>
22namespace dispersal_kernel
25using namespace mp_units;
26using namespace mp_units::si::unit_symbols;
27using std::numbers::pi;
33template <QuantityOf<isq::length> Distance = mp_units::quantity<mp_units::si::metre>>
37 using pdf_result_type = quantity<inverse(pow<2>(Distance::reference)),
typename Distance::rep>;
52 assert(p.
a > 0. * m && r >= 0. * m);
53 return (1. / (pi * p.
a * p.
a)) * exp(-(r * r) / (p.
a * p.
a));
63 return (p.
a * pow(pi, 0.5)) / 2.;
70template <QuantityOf<isq::length> Distance = mp_units::quantity<mp_units::si::metre>>
struct logistic
73 using pdf_result_type = quantity<inverse(pow<2>(Distance::reference)),
typename Distance::rep>;
98 assert(a > 0. * m && b > 2. && r >= 0. * m);
99 return (b / (2. * pi * (a * a) * tgamma(2. / b) * tgamma(1. - 2. / b))) *
100 (1. / (1. + (pow(r, b) / (pow(a, b)))));
112 assert(a > 0. * m && b > 2);
113 return (a * tgamma(3. / b) * tgamma(1. - 3. / b)) / (tgamma(2. / b) * tgamma(1. - 2. / b));
122template <QuantityOf<isq::length> Distance = mp_units::quantity<mp_units::si::metre>>
126 using pdf_result_type = quantity<inverse(pow<2>(Distance::reference)),
typename Distance::rep>;
143 assert(a > 0. * m && r >= 0. * m);
144 return 1. / (2. * pi * a * a) * exp(-r / a);
163template <QuantityOf<isq::length> Distance = mp_units::quantity<mp_units::si::metre>>
struct exponential_power
166 using pdf_result_type = quantity<inverse(pow<2>(Distance::reference)),
typename Distance::rep>;
188 assert(a > 0. * m && b > 0. && r >= 0. * m);
189 return b / (2. * pi * a * a * tgamma(2. / b)) * exp(- pow(r.numerical_value_in(m), b) / pow(a.numerical_value_in(m),b));
200 assert(a > 0. * m && b > 0.);
201 return a * tgamma(3. / b) / tgamma(2. / b);
209template <QuantityOf<isq::length> Distance = mp_units::quantity<mp_units::si::metre>>
struct two_dt
212 using pdf_result_type = quantity<inverse(pow<2>(Distance::reference)),
typename Distance::rep>;
233 assert(a > 0. * m && b > 1. && r >= 0. * m);
234 return (b - 1.) / (pi * a * a) * pow((1. + (r * r) / (a * a)), -b);
247 assert(a > 0. * m && b > 1.);
250 return std::numeric_limits<double>::infinity();
252 return (a * pow(pi, 0.5) * tgamma(b - 3. / 2.)) / (2. * tgamma(b - 1.));
259template <QuantityOf<isq::length> Distance = mp_units::quantity<mp_units::si::metre>>
struct inverse_power_law
262 using pdf_result_type = quantity<inverse(pow<2>(Distance::reference)),
typename Distance::rep>;
283 assert(a > 0. * m && b > 2. && r >= 0. * m);
284 return pow(1. + r / a, -b) * (b - 2.) * (b - 1.) / (2. * pi * a * a);
295 assert(a > 0. * m && b > 2.);
298 return std::numeric_limits<double>::infinity();
300 return 2. * a / (b - 3.);
308template <QuantityOf<isq::length> Distance = mp_units::quantity<mp_units::si::metre>>
struct lognormal
311 using pdf_result_type = quantity<inverse(pow<2>(Distance::reference)),
typename Distance::rep>;
343 assert(a > 0. * m && b > 0.);
344 return a * exp(b * b / 2.);
351template <QuantityOf<isq::length> Distance = mp_units::quantity<mp_units::si::metre>>
struct gaussian_mixture
354 using pdf_result_type = quantity<inverse(pow<2>(Distance::reference)),
typename Distance::rep>;
377 Distance a1 = param.
a1;
378 Distance a2 = param.
a2;
380 assert(a1 > 0. * m && a2 > 0. * m && p > 0. && p < 1. && r >= 0. * m);
381 return p / (pi * a1 * a1) * exp(-(r * r) / (a1 * a1)) +
382 (1. - p) / (pi * a2 * a2) * exp(-(r * r) / (a2 * a2));
391 Distance a1 = param.
a1;
392 Distance a2 = param.
a2;
394 assert(a1 > 0. * m && a2 > 0. * m && p > 0. && p < 1.);
395 return pow(pi, 0.5) * (p * a1 + (1. - p) * a2) / 2.;
Simulation of coalescence-based models of molecular evolution.
Definition coalescence.hpp:21
Dispersal location kernel parameter.
Definition dispersal_kernel.hpp:170
double b
Shape parameter determining the shape of the curve (weight of long-distance events).
Definition dispersal_kernel.hpp:175
Distance a
Scale parameter homogeneous to a distance.
Definition dispersal_kernel.hpp:172
Exponential Power dispersal location kernel ( : thin-tailed, : fat-tailed. Always thinner than powe...
Definition dispersal_kernel.hpp:164
quantity< inverse(pow< 2 >(Distance::reference)), typename Distance::rep > pdf_result_type
Probability density function value type.
Definition dispersal_kernel.hpp:166
static constexpr Distance mean_dispersal_distance(param_type const &p)
Mean dispersal distance.
Definition dispersal_kernel.hpp:195
static constexpr pdf_result_type pdf(Distance r, param_type const &p)
Probability density function.
Definition dispersal_kernel.hpp:182
Dispersal location kernel parameter.
Definition dispersal_kernel.hpp:41
Distance a
Scale parameter homogeneous to a distance.
Definition dispersal_kernel.hpp:43
Dispersal location kernel parameter.
Definition dispersal_kernel.hpp:358
Distance a1
First scale parameter homogeneous to a distance.
Definition dispersal_kernel.hpp:360
Distance a2
Second scale parameter homogeneous to a distance.
Definition dispersal_kernel.hpp:362
double p
Shape parameter.
Definition dispersal_kernel.hpp:364
Gaussian Mixture dispersal location kernel (leptokurtic, never fat-tailed)
Definition dispersal_kernel.hpp:352
quantity< inverse(pow< 2 >(Distance::reference)), typename Distance::rep > pdf_result_type
Probability density function value type.
Definition dispersal_kernel.hpp:354
static constexpr pdf_result_type pdf(Distance r, param_type const ¶m)
Probability density function.
Definition dispersal_kernel.hpp:374
static constexpr Distance mean_dispersal_distance(param_type const ¶m)
Mean dispersal distance.
Definition dispersal_kernel.hpp:388
Gaussian dispersal location kernel (thin-tailed)
Definition dispersal_kernel.hpp:35
static constexpr Distance mean_dispersal_distance(param_type const &p)
Mean dispersal distance.
Definition dispersal_kernel.hpp:59
static constexpr pdf_result_type pdf(Distance r, param_type const &p)
Probability density function.
Definition dispersal_kernel.hpp:50
quantity< inverse(pow< 2 >(Distance::reference)), typename Distance::rep > pdf_result_type
Probability density function value type.
Definition dispersal_kernel.hpp:37
Dispersal location kernel parameter.
Definition dispersal_kernel.hpp:266
Distance a
Scale parameter homogeneous to a distance.
Definition dispersal_kernel.hpp:268
double b
Shape parameter determining the shape of the curve (weight of long-distance events).
Definition dispersal_kernel.hpp:271
Inverse Power Law dispersal location kernel (fat-tailed, power-law tail)
Definition dispersal_kernel.hpp:260
static constexpr pdf_result_type pdf(Distance r, param_type const &p)
Probability density function.
Definition dispersal_kernel.hpp:278
quantity< inverse(pow< 2 >(Distance::reference)), typename Distance::rep > pdf_result_type
Probability density function value type.
Definition dispersal_kernel.hpp:262
static constexpr Distance mean_dispersal_distance(param_type const &p)
Mean dispersal distance.
Definition dispersal_kernel.hpp:291
Dispersal location kernel parameter.
Definition dispersal_kernel.hpp:77
Distance a
Scale parameter homogeneous to a distance.
Definition dispersal_kernel.hpp:79
double b
Shape parameter determining the shape of the curve (weight of long-distance events).
Definition dispersal_kernel.hpp:82
Logistic dispersal location kernel (fat-tailed, power-law tail)
Definition dispersal_kernel.hpp:71
quantity< inverse(pow< 2 >(Distance::reference)), typename Distance::rep > pdf_result_type
Probability density function value type.
Definition dispersal_kernel.hpp:73
static constexpr Distance mean_dispersal_distance(param_type const &p)
Mean dispersal distance.
Definition dispersal_kernel.hpp:107
static constexpr pdf_result_type pdf(Distance r, param_type const &p)
Probability density function.
Definition dispersal_kernel.hpp:90
Dispersal location kernel parameter.
Definition dispersal_kernel.hpp:315
Distance a
Scale parameter homogeneous to a distance.
Definition dispersal_kernel.hpp:317
double b
Shape parameter determining the shape of the curve (weight of long-distance events).
Definition dispersal_kernel.hpp:320
Lognormal dispersal location kernel (fat-tailed)
Definition dispersal_kernel.hpp:309
quantity< inverse(pow< 2 >(Distance::reference)), typename Distance::rep > pdf_result_type
Probability density function value type.
Definition dispersal_kernel.hpp:311
static constexpr Distance mean_dispersal_distance(param_type const &p)
Probability density function.
Definition dispersal_kernel.hpp:338
Dispersal location kernel parameter.
Definition dispersal_kernel.hpp:130
Distance a
Scale parameter homogeneous to a distance.
Definition dispersal_kernel.hpp:132
Negative Exponential dispersal location kernel (exponential tail fatness)
Definition dispersal_kernel.hpp:124
static constexpr Distance mean_dispersal_distance(param_type const &p)
Mean dispersal distance.
Definition dispersal_kernel.hpp:150
static constexpr pdf_result_type pdf(Distance r, param_type const &p)
Probability density function.
Definition dispersal_kernel.hpp:139
quantity< inverse(pow< 2 >(Distance::reference)), typename Distance::rep > pdf_result_type
Probability density function value type.
Definition dispersal_kernel.hpp:126
Dispersal location kernel parameter.
Definition dispersal_kernel.hpp:216
Distance a
Scale parameter homogeneous to a distance.
Definition dispersal_kernel.hpp:218
double b
Shape parameter determining the shape of the curve (weight of long-distance events).
Definition dispersal_kernel.hpp:221
TwoDt dispersal location kernel (fat-tailed, power-law tail)
Definition dispersal_kernel.hpp:210
static constexpr Distance mean_dispersal_distance(param_type const &p)
Mean dispersal distance.
Definition dispersal_kernel.hpp:241
static constexpr pdf_result_type pdf(Distance r, param_type const &p)
Probability density function.
Definition dispersal_kernel.hpp:228
quantity< inverse(pow< 2 >(Distance::reference)), typename Distance::rep > pdf_result_type
Probability density function value type.
Definition dispersal_kernel.hpp:212