pops-core  0.9
PoPS (Pest or Pathogen Spread) Model Core C++ library
weibull_kernel.hpp
Go to the documentation of this file.
1 /*
2  * PoPS model - weibull 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_WEIBULL_KERNEL_HPP
17 #define POPS_WEIBULL_KERNEL_HPP
18 
19 #include "kernel_types.hpp"
20 #include "raster.hpp"
21 
22 #include <random>
23 
24 namespace pops {
25 
26 using std::pow;
27 using std::exp;
28 using std::log;
29 
34 {
35 protected:
36  double a;
37  double b;
38  std::weibull_distribution<double> weibull_distribution;
39 
40 public:
41  WeibullKernel(double scale, double shape)
42  : a(shape), b(scale), weibull_distribution(a, b)
43  {
44  if (a <= 0 || b <= 0) {
45  throw std::invalid_argument(
46  "scale and shape parameters must be greater than zero");
47  }
48  }
49 
56  template<class Generator>
57  double random(Generator& generator)
58  {
59  return std::abs(weibull_distribution(generator));
60  }
61 
68  double pdf(double x)
69  {
70  if (x < 0) {
71  throw std::invalid_argument("x must be greater than or equal to 0.0");
72  }
73  // Note: If the value inside exp() is too large it returns zero
74  // any a >= 2 returns zero
75  return (a / b) * pow(x / b, a - 1) * exp(-pow(x / b, a));
76  }
77 
84  double icdf(double x)
85  {
86  if (x <= 0 || x >= 1) {
87  throw std::invalid_argument("icdf: x must be between 0 and 1.0");
88  }
89  return a * pow(-(log(1 - x)), (1.0 / b));
90  }
91 };
92 
93 } // namespace pops
94 
95 #endif // POPS_WEIBULL_KERNEL_HPP
raster.hpp
pops::WeibullKernel
Dispersal kernel for weibull distribution class utilized by RadialKernel and DeterministicKernel.
Definition: weibull_kernel.hpp:33
pops::WeibullKernel::b
double b
Definition: weibull_kernel.hpp:37
pops::WeibullKernel::random
double random(Generator &generator)
Returns random value from weibull distribution Used by RadialKernel to determine location of spread.
Definition: weibull_kernel.hpp:57
pops::WeibullKernel::weibull_distribution
std::weibull_distribution< double > weibull_distribution
Definition: weibull_kernel.hpp:38
pops::WeibullKernel::WeibullKernel
WeibullKernel(double scale, double shape)
Definition: weibull_kernel.hpp:41
pops
Definition: cauchy_kernel.hpp:25
pops::WeibullKernel::a
double a
Definition: weibull_kernel.hpp:36
pops::WeibullKernel::pdf
double pdf(double x)
Weibull probability density function Used by DeterministicKernel to determine location of spread.
Definition: weibull_kernel.hpp:68
pops::WeibullKernel::icdf
double icdf(double x)
Weibull inverse cumulative distribution (quantile) function Used by DeterministicKernel to determine ...
Definition: weibull_kernel.hpp:84
kernel_types.hpp
Kernel types enum and helper functions.