pops-core  0.9
PoPS (Pest or Pathogen Spread) Model Core C++ library
exponential_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_KERNEL_HPP
17 #define POPS_EXPONENTIAL_KERNEL_HPP
18 
19 #include "kernel_types.hpp"
20 #include "raster.hpp"
21 #include "utils.hpp"
22 
23 #include <random>
24 
25 namespace pops {
26 
27 using std::exp;
28 using std::log;
29 
34 {
35 protected:
36  double beta;
37  std::exponential_distribution<double> exponential_distribution;
38 
39 public:
41  {
42  if (beta <= 0) {
43  throw std::invalid_argument("beta must be greater than 0.0");
44  }
45  }
46 
53  template<class Generator>
54  double random(Generator& generator)
55  {
56  return std::abs(exponential_distribution(generator));
57  }
58 
65  double pdf(double x)
66  {
67  if (x < 0) {
68  throw std::invalid_argument("x must be greater than or equal to zero");
69  }
70  return (1.0 / beta) * (exp(-x / beta));
71  }
72 
79  double icdf(double x)
80  {
81  if (x <= 0 || x >= 1) {
82  throw std::invalid_argument("icdf: x must be between 0.0 and 1.0");
83  }
84  else {
85  return -beta * log(1 - x);
86  }
87  }
88 };
89 
90 } // namespace pops
91 
92 #endif // POPS_EXPONENTIAL_KERNEL_HPP
raster.hpp
utils.hpp
pops::ExponentialKernel::exponential_distribution
std::exponential_distribution< double > exponential_distribution
Definition: exponential_kernel.hpp:37
pops::ExponentialKernel::icdf
double icdf(double x)
Exponential inverse cumulative distribution (quantile) function Used by DeterministicKernel to determ...
Definition: exponential_kernel.hpp:79
pops::ExponentialKernel::ExponentialKernel
ExponentialKernel(double b)
Definition: exponential_kernel.hpp:40
pops
Definition: cauchy_kernel.hpp:25
pops::ExponentialKernel::beta
double beta
Definition: exponential_kernel.hpp:36
pops::ExponentialKernel::random
double random(Generator &generator)
Returns random value from exponential distribution Used by RadialKernel to determine location of spre...
Definition: exponential_kernel.hpp:54
pops::ExponentialKernel
Dispersal kernel for exponential distribution class utilized by RadialKernel and DeterministicKernel.
Definition: exponential_kernel.hpp:33
pops::ExponentialKernel::pdf
double pdf(double x)
Exponential probability density function Used by DeterministicKernel to determine location of spread.
Definition: exponential_kernel.hpp:65
kernel_types.hpp
Kernel types enum and helper functions.