pops-core
0.9
PoPS (Pest or Pathogen Spread) Model Core C++ library
include
pops
logistic_kernel.hpp
Go to the documentation of this file.
1
/*
2
* PoPS model - logistic 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_LOGISTIC_KERNEL_HPP
17
#define POPS_LOGISTIC_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;
32
class
LogisticKernel
33
{
34
protected
:
35
double
s
;
36
std::uniform_real_distribution<double>
distribution
;
37
38
public
:
39
LogisticKernel
(
double
scale) :
s
(scale),
distribution
(0.0, 1.0)
40
{
41
if
(
s
<= 0) {
42
throw
std::invalid_argument(
43
"LogisticKernel: scale (s) must be greater than 0.0"
);
44
}
45
}
46
53
template
<
class
Generator>
54
double
random
(Generator& generator)
55
{
56
double
x =
distribution
(generator);
57
return
icdf
(x);
58
}
59
66
double
pdf
(
double
x)
67
{
68
if
(
s
== 1) {
69
return
exp(-x) / pow(1 + exp(-x), 2);
70
}
71
return
(exp(-x /
s
)) / (
s
* pow(1 + exp(-x /
s
), 2));
72
}
73
80
double
icdf
(
double
x)
81
{
82
if
(x <= 0 || x >= 1) {
83
throw
std::invalid_argument(
"icdf: x must be between 0.0 and 1.0"
);
84
}
85
return
s
* log(x / (1.0 - x));
86
}
87
};
88
89
}
// namespace pops
90
91
#endif // POPS_LOGISTIC_KERNEL_HPP
raster.hpp
pops::LogisticKernel::LogisticKernel
LogisticKernel(double scale)
Definition:
logistic_kernel.hpp:39
pops::LogisticKernel::pdf
double pdf(double x)
Logistic probability density function Used by DeterministicKernel to determine location of spread.
Definition:
logistic_kernel.hpp:66
pops::LogisticKernel
Dispersal kernel for logistic distribution class utilized by RadialKernel and DeterministicKernel.
Definition:
logistic_kernel.hpp:32
pops::LogisticKernel::icdf
double icdf(double x)
Logistic inverse cumulative distribution (quantile) function Used by DeterministicKernel to determine...
Definition:
logistic_kernel.hpp:80
pops
Definition:
cauchy_kernel.hpp:25
pops::LogisticKernel::distribution
std::uniform_real_distribution< double > distribution
Definition:
logistic_kernel.hpp:36
pops::LogisticKernel::s
double s
Definition:
logistic_kernel.hpp:35
pops::LogisticKernel::random
double random(Generator &generator)
Returns random value from logistic distribution Used by RadialKernel to determine location of spread.
Definition:
logistic_kernel.hpp:54
kernel_types.hpp
Kernel types enum and helper functions.
Generated by
1.8.17