pops-core  0.9
PoPS (Pest or Pathogen Spread) Model Core C++ library
cauchy_kernel.hpp
Go to the documentation of this file.
1 /*
2  * PoPS model - cauchy 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_CAUCHY_KERNEL_HPP
17 #define POPS_CAUCHY_KERNEL_HPP
18 
19 #include "utils.hpp"
20 #include "kernel_types.hpp"
21 #include "raster.hpp"
22 
23 #include <random>
24 
25 namespace pops {
26 
27 using std::pow;
28 using std::tan;
29 
34 {
35 protected:
36  double s;
37  std::cauchy_distribution<double> cauchy_distribution;
38 
39 public:
40  CauchyKernel(double scale) : s(scale), cauchy_distribution(0, s)
41  {
42  if (scale <= 0) {
43  throw std::invalid_argument(
44  "CauchyKernel: scale (s) must be greater than 0.0");
45  }
46  }
47 
54  template<class Generator>
55  double random(Generator& generator)
56  {
57  return std::abs(cauchy_distribution(generator));
58  }
59 
66  double pdf(double x)
67  {
68  return 1 / ((s * M_PI) * (1 + (pow(x / s, 2))));
69  }
70 
77  double icdf(double x)
78  {
79  if (x <= 0 || x >= 1) {
80  throw std::invalid_argument("icdf: x must be between 0.0 and 1.0");
81  }
82  return s * tan(M_PI * (x - 0.5));
83  }
84 };
85 
86 } // namespace pops
87 
88 #endif // POPS_CAUCHY_KERNEL_HPP
pops::CauchyKernel::s
double s
Definition: cauchy_kernel.hpp:36
raster.hpp
pops::CauchyKernel::random
double random(Generator &generator)
Returns random value from cauchy distribution Used by RadialKernel to determine location of spread.
Definition: cauchy_kernel.hpp:55
utils.hpp
M_PI
#define M_PI
Definition: utils.hpp:35
pops::CauchyKernel::pdf
double pdf(double x)
Cauchy probability density function Used by DeterministicKernel to determine location of spread.
Definition: cauchy_kernel.hpp:66
pops::CauchyKernel
Dispersal kernel for cauchy distribution class utilized by RadialKernel and DeterministicKernel.
Definition: cauchy_kernel.hpp:33
pops::CauchyKernel::CauchyKernel
CauchyKernel(double scale)
Definition: cauchy_kernel.hpp:40
pops
Definition: cauchy_kernel.hpp:25
pops::CauchyKernel::cauchy_distribution
std::cauchy_distribution< double > cauchy_distribution
Definition: cauchy_kernel.hpp:37
pops::CauchyKernel::icdf
double icdf(double x)
Cauchy inverse cumulative distribution (quantile) function Used by DeterministicKernel to determine m...
Definition: cauchy_kernel.hpp:77
kernel_types.hpp
Kernel types enum and helper functions.