pops-core  0.9
PoPS (Pest or Pathogen Spread) Model Core C++ library
exponential_power_kernel.hpp
Go to the documentation of this file.
1 /*
2  * PoPS model - exponential dispersal kernel
3  *
4  * Copyright (C) 2015-2020 by the authors.
5  *
6  * Authors: Margaret Lawrimore malawrim ncsu edu
7  *
8  * The code contained herein is licensed under the GNU General Public
9  * License. You may obtain a copy of the GNU General Public License
10  * Version 2 or later at the following locations:
11  *
12  * http://www.opensource.org/licenses/gpl-license.html
13  * http://www.gnu.org/copyleft/gpl.html
14  */
15 
16 #ifndef POPS_EXPONENTIAL_POWER_KERNEL_HPP
17 #define POPS_EXPONENTIAL_POWER_KERNEL_HPP
18 
19 #include "kernel_types.hpp"
20 #include "gamma_kernel.hpp"
21 #include "raster.hpp"
22 
23 #include <random>
24 
25 namespace pops {
26 
27 using std::pow;
28 using std::exp;
29 
34 {
35 protected:
36  double alpha;
37  double beta;
38  std::uniform_real_distribution<double> distribution;
39 
40 public:
41  ExponentialPowerKernel(double a, double b)
42  : alpha(a), beta(b), distribution(0.0, 1.0)
43  {
44  if (alpha <= 0 || beta <= 0) {
45  throw std::invalid_argument(
46  "alpha and beta must greater than or equal to 0");
47  }
48  }
49 
56  template<class Generator>
57  double random(Generator& generator)
58  {
59  double x = distribution(generator);
60  return icdf(x);
61  }
62 
69  double pdf(double x)
70  {
71  return (beta / (2 * alpha * std::tgamma(1.0 / beta)))
72  * exp(-pow(x / alpha, beta));
73  }
74 
81  double icdf(double x)
82  {
83  if (x <= 0 || x >= 1) {
84  throw std::invalid_argument("icdf: x must be between 0.0 and 1.0");
85  }
86  float sign = ((x - 0.5) > 0) ? 1.0 : ((x - 0.5) < 0 ? -1.0 : 0);
87  if (sign == 0) {
88  return 0;
89  }
90  GammaKernel gamma_distribution(1.0 / beta, 1.0 / pow(alpha, beta));
91  double gamma = gamma_distribution.icdf(2 * std::abs(x - 0.5));
92  return sign * pow(gamma, 1.0 / beta);
93  }
94 };
95 
96 } // namespace pops
97 
98 #endif // POPS_EXPONENTIAL_POWER_KERNEL_HPP
raster.hpp
pops::ExponentialPowerKernel::pdf
double pdf(double x)
Exponential Power probability density function Used by DeterministicKernel to determine location of s...
Definition: exponential_power_kernel.hpp:69
pops::ExponentialPowerKernel::distribution
std::uniform_real_distribution< double > distribution
Definition: exponential_power_kernel.hpp:38
pops::ExponentialPowerKernel
Dispersal kernel for exponential power distribution class utilized by RadialKernel and DeterministicK...
Definition: exponential_power_kernel.hpp:33
pops::ExponentialPowerKernel::icdf
double icdf(double x)
Exponential Power inverse cumulative distribution (quantile) function Used by DeterministicKernel to ...
Definition: exponential_power_kernel.hpp:81
pops
Definition: cauchy_kernel.hpp:25
pops::ExponentialPowerKernel::random
double random(Generator &generator)
Returns random value from exponential power distribution Used by RadialKernel to determine location o...
Definition: exponential_power_kernel.hpp:57
pops::ExponentialPowerKernel::alpha
double alpha
Definition: exponential_power_kernel.hpp:36
pops::ExponentialPowerKernel::beta
double beta
Definition: exponential_power_kernel.hpp:37
pops::ExponentialPowerKernel::ExponentialPowerKernel
ExponentialPowerKernel(double a, double b)
Definition: exponential_power_kernel.hpp:41
gamma_kernel.hpp
kernel_types.hpp
Kernel types enum and helper functions.
pops::GammaKernel
Dispersal kernel for gamma distribution class utilized by RadialKernel and DeterministicKernel.
Definition: gamma_kernel.hpp:33
pops::GammaKernel::icdf
double icdf(double x)
Gamma inverse cumulative distribution (quantile) function Used by DeterministicKernel to determine ma...
Definition: gamma_kernel.hpp:104