Title: | Simulating Nonhomogeneous Poisson Point Processes |
---|---|
Description: | Simulates events from one dimensional nonhomogeneous Poisson point processes (NHPPPs) as per Trikalinos and Sereda (2024, <doi:10.48550/arXiv.2402.00358>). Functions are based on three algorithms that provably sample from a target NHPPP: the time-transformation of a homogeneous Poisson process (of intensity one) via the inverse of the integrated intensity function (Cinlar E, "Theory of stochastic processes" (1975, ISBN:0486497996)); the generation of a Poisson number of order statistics from a fixed density function; and the thinning of a majorizing NHPPP via an acceptance-rejection scheme (Lewis PAW, Shedler, GS (1979) <doi:10.1002/nav.3800260304>). |
Authors: | Thomas Trikalinos [aut, cre, cph] , Yuliia Sereda [aut] |
Maintainer: | Thomas Trikalinos <[email protected]> |
License: | GPL (>= 3) |
Version: | 1.0.0 |
Built: | 2024-10-24 04:27:32 UTC |
Source: | CRAN |
This is a wrapper to the package's specific functions, and thus somewhat slower. For time-intensive simulations prefer one of the specific functions.
draw( Lambda = NULL, Lambda_inv = NULL, lambda = NULL, line_majorizer_intercept = NULL, line_majorizer_slope = NULL, line_majorizer_is_loglinear = FALSE, step_majorizer_vector = NULL, t_min = NULL, t_max = NULL, atmost1 = FALSE, atleast1 = FALSE )
draw( Lambda = NULL, Lambda_inv = NULL, lambda = NULL, line_majorizer_intercept = NULL, line_majorizer_slope = NULL, line_majorizer_is_loglinear = FALSE, step_majorizer_vector = NULL, t_min = NULL, t_max = NULL, atmost1 = FALSE, atleast1 = FALSE )
Lambda |
(function, double vector) the integrated (cumulative) rate of the NHPPP |
Lambda_inv |
(function, double vector) the inverse of ‘Lambda()’ |
lambda |
(function) the instantaneous rate |
line_majorizer_intercept |
The intercept |
line_majorizer_slope |
The slope |
line_majorizer_is_loglinear |
(boolean) if |
step_majorizer_vector |
(vector, double) |
t_min |
(double) the lower bound of the interval |
t_max |
(double) the upper bound of the interval |
atmost1 |
boolean, draw at most 1 event time |
atleast1 |
boolean, draw at least 1 event time in interval |
a vector of event times
Sample NHPPP times using the inversion method
draw_cumulative_intensity(Lambda, Lambda_inv, t_min, t_max, atmost1 = FALSE)
draw_cumulative_intensity(Lambda, Lambda_inv, t_min, t_max, atmost1 = FALSE)
Lambda |
(function, double vector) a continuous increasing R to R map which is the integrated rate of the NHPPP |
Lambda_inv |
(function, double vector) the inverse of |
t_min |
(double) the lower bound of the time interval |
t_max |
(double) the upper bound of the time interval |
atmost1 |
boolean, draw at most 1 event time |
a vector of event times (t_); if no events realize, a vector of length 0
Sample from NHPPPs given the intensity function This is a wrapper to the package's specific functions, and thus somewhat slower. For time-intensive simulations prefer one of the specific functions.
draw_intensity( lambda, line_majorizer_intercept = NULL, line_majorizer_slope = NULL, line_majorizer_is_loglinear = FALSE, step_majorizer_vector = NULL, t_min = NULL, t_max = NULL, atmost1 = FALSE )
draw_intensity( lambda, line_majorizer_intercept = NULL, line_majorizer_slope = NULL, line_majorizer_is_loglinear = FALSE, step_majorizer_vector = NULL, t_min = NULL, t_max = NULL, atmost1 = FALSE )
lambda |
(function) the instantaneous rate |
line_majorizer_intercept |
The intercept |
line_majorizer_slope |
The slope |
line_majorizer_is_loglinear |
(boolean) if |
step_majorizer_vector |
(vector, double) |
t_min |
(double) the lower bound of the interval |
t_max |
(double) the upper bound of the interval |
atmost1 |
boolean, draw at most 1 event time |
a vector of event times
Sample NHPPP times from a linear intensity function
using the inversion method, optionally using an rstream
generator
draw_sc_linear(intercept, slope, t_min, t_max, atmost1 = FALSE)
draw_sc_linear(intercept, slope, t_min, t_max, atmost1 = FALSE)
intercept |
(double) the intercept |
slope |
(double) the slope |
t_min |
(double) lower bound of the time interval |
t_max |
(double) upper bound of the time interval |
atmost1 |
boolean, draw at most 1 event time |
a vector of event times (t_); if no events realize, a vector of length 0
x <- draw_sc_linear(intercept = 0, slope = 0.2, t_min = 0, t_max = 10)
x <- draw_sc_linear(intercept = 0, slope = 0.2, t_min = 0, t_max = 10)
Sample NHPPP times from an log linear intensity function
using the inversion method, optionally using an rstream
generator
draw_sc_loglinear(intercept, slope, t_min, t_max, atmost1 = FALSE)
draw_sc_loglinear(intercept, slope, t_min, t_max, atmost1 = FALSE)
intercept |
(double) the intercept in the exponent |
slope |
(double) the slope in the exponent |
t_min |
(double) lower bound of the time interval |
t_max |
(double) upper bound of the time interval |
atmost1 |
boolean, draw at most 1 event time |
a vector of event times (t_); if no events realize, a vector of length 0
x <- draw_sc_loglinear(intercept = 0, slope = 0.2, t_min = 0, t_max = 10)
x <- draw_sc_loglinear(intercept = 0, slope = 0.2, t_min = 0, t_max = 10)
(t_min, t_max]
(inversion method)
The intervals need not have the same length.Simulate a piecewise constant-rate Poisson Point Process over (t_min, t_max]
(inversion method)
The intervals need not have the same length.
draw_sc_step(lambda_vector, time_breaks, atmost1 = FALSE, atleast1 = FALSE)
draw_sc_step(lambda_vector, time_breaks, atmost1 = FALSE, atleast1 = FALSE)
lambda_vector |
(scalar, double) |
time_breaks |
(vector, double) |
atmost1 |
boolean, draw at most 1 event time |
atleast1 |
boolean, draw at least 1 event time |
a vector of event times t if no events realize, it will have 0 length
x <- draw_sc_step(lambda_vector = rep(1, 5), time_breaks = c(0:5))
x <- draw_sc_step(lambda_vector = rep(1, 5), time_breaks = c(0:5))
Sampling from NHPPPs with piecewise constant intensities with same interval lengths (non-vectorized)
draw_sc_step_regular( Lambda_vector = NULL, lambda_vector = NULL, t_min = NULL, t_max = NULL, atmost1 = FALSE, atleast1 = FALSE )
draw_sc_step_regular( Lambda_vector = NULL, lambda_vector = NULL, t_min = NULL, t_max = NULL, atmost1 = FALSE, atleast1 = FALSE )
Lambda_vector |
(scalar, double) |
lambda_vector |
(scalar, double) |
t_min |
(scalar, double) lower bound of the time interval |
t_max |
(scalar, double) upper bound of the time interval |
atmost1 |
boolean, draw at most 1 event time |
atleast1 |
boolean, draw at least 1 event time |
a vector of event times t if no events realize, it will have 0 length
x <- draw_sc_step_regular(Lambda_vector = 1:5, t_min = 0, t_max = 5)
x <- draw_sc_step_regular(Lambda_vector = 1:5, t_min = 0, t_max = 5)
breaks
argument).Return a piecewise constant (step) majorizer for K-Lipschitz functions
over an interval. The function is vectorized over the breaks
argument.
get_step_majorizer(fun, breaks, is_monotone = TRUE, K = 0)
get_step_majorizer(fun, breaks, is_monotone = TRUE, K = 0)
fun |
A function object with a single argument |
breaks |
(vector or matrix) The set of |
is_monotone |
(boolean) Is the function monotone? (Default is |
K |
(double) A non-negative number for the Lipschitz cone. (Default is 0.) |
A vector of length M
with the values of the piecewise constant majorizer
get_step_majorizer(fun = abs, breaks = -5:5, is_monotone = FALSE, K = 1)
get_step_majorizer(fun = abs, breaks = -5:5, is_monotone = FALSE, K = 1)
Simulate a homogeneous Poisson Point Process in (t_min, t_max]
ppp(rate, t_min, t_max, atmost1 = FALSE, tol = 10^-6)
ppp(rate, t_min, t_max, atmost1 = FALSE, tol = 10^-6)
rate |
(scalar, double) constant instantaneous rate |
t_min |
(scalar, double) the lower bound of the time interval |
t_max |
(scalar, double) the upper bound of the time interval |
atmost1 |
boolean, draw at most 1 event time |
tol |
the probability that we will have more than the drawn events in (t_min, t_max] |
a vector of event times t if no events realize, it will have 0 length
x <- ppp(rate = 1, t_min = 0, t_max = 10, tol = 10^-6)
x <- ppp(rate = 1, t_min = 0, t_max = 10, tol = 10^-6)
n
points from a homogeneous Poisson Point Process over (t_min, t_max]Simulate exactly n
points from a homogeneous Poisson Point Process over (t_min, t_max]
ppp_exactly_n(n, t_min, t_max)
ppp_exactly_n(n, t_min, t_max)
n |
(int) the number of points to be simulated |
t_min |
(double) the lower bound of the time interval |
t_max |
(double) the upper bound of the time interval |
a vector of event times of size n
x <- ppp_exactly_n(n = 10, t_min = 0, t_max = 10)
x <- ppp_exactly_n(n = 10, t_min = 0, t_max = 10)
Simulate n events from a homogeneous Poisson Point Process.
ppp_next_n(n = 1, rate = 1, t_min = 0, rng_stream = deprecated())
ppp_next_n(n = 1, rate = 1, t_min = 0, rng_stream = deprecated())
n |
scalar number of samples |
rate |
scalar instantaneous rate |
t_min |
scalar for the starting time value |
rng_stream |
a vector with event times t (starting from t_min)
x <- ppp_next_n(n = 10, rate = 1, t_min = 0)
x <- ppp_next_n(n = 10, rate = 1, t_min = 0)
This is a wrapper to the package's specific functions, and thus slightly slower. For time-intensive simulations prefer one of the specific functions.
vdraw( lambda = NULL, lambda_args = NULL, Lambda_maj_matrix = NULL, lambda_maj_matrix = NULL, Lambda = NULL, Lambda_inv = NULL, Lambda_args = NULL, Lambda_inv_args = NULL, t_min = NULL, t_max = NULL, rate_matrix_t_min = NULL, rate_matrix_t_max = NULL, tol = 10^-6, atmost1 = FALSE, atleast1 = FALSE, atmostB = NULL )
vdraw( lambda = NULL, lambda_args = NULL, Lambda_maj_matrix = NULL, lambda_maj_matrix = NULL, Lambda = NULL, Lambda_inv = NULL, Lambda_args = NULL, Lambda_inv_args = NULL, t_min = NULL, t_max = NULL, rate_matrix_t_min = NULL, rate_matrix_t_max = NULL, tol = 10^-6, atmost1 = FALSE, atleast1 = FALSE, atmostB = NULL )
lambda |
(function) intensity function, vectorized |
lambda_args |
(list) optional arguments to pass to |
Lambda_maj_matrix |
(matrix) integrated intensity rates at the end of each interval |
lambda_maj_matrix |
(matrix) intensity rates, one per interval |
Lambda |
(function, double vector) an increasing function which is the integrated rate of the NHPPP. It should take a vectorized argument t for times and an optional arguments list. |
Lambda_inv |
(function, double vector) the inverse of |
Lambda_args |
(list) optional arguments to pass to Lambda. |
Lambda_inv_args |
(list) optional arguments to pass to Lambda_inv(). |
t_min |
(scalar | vector | column matrix) is the lower bound
of a subinterval of (rate_matrix_t_min, rate_matrix_t_max]. If set,
times are sampled from the subinterval.
If omitted, it is equivalent to |
t_max |
(scalar | vector | column matrix) is the upper bound
of a subinterval of (rate_matrix_t_min, rate_matrix_t_max]. If set,
times are sampled from the subinterval.
If omitted, it is equivalent to |
rate_matrix_t_min |
(scalar | vector | column matrix) is the lower bound of the time interval for each row of (Lambda|lambda)_maj_matrix. The length of this argument is the number of point processes that should be drawn. |
rate_matrix_t_max |
(scalar | vector | column matrix) the upper bound of the time interval for each row of (Lambda|lambda)_maj_matrix. The length of this argument is the number of point processes that should be drawn. |
tol |
(scalar, double) tolerance for the number of events |
atmost1 |
boolean, draw at most 1 event time |
atleast1 |
boolean, draw at least 1 event time |
atmostB |
If not NULL, draw at most B (B>0) event times. NULL means ignore. |
a vector of event times
Sample NHPPP times using the cumulative intensity function and its inverse.
vdraw_cumulative_intensity( Lambda, Lambda_inv, t_min, t_max, Lambda_args = NULL, Lambda_inv_args = NULL, tol = 10^-6, atmost1 = FALSE, atleast1 = FALSE )
vdraw_cumulative_intensity( Lambda, Lambda_inv, t_min, t_max, Lambda_args = NULL, Lambda_inv_args = NULL, tol = 10^-6, atmost1 = FALSE, atleast1 = FALSE )
Lambda |
(function, double vector) an increasing function which is the integrated rate of the NHPPP. It should take a vectorized argument t for times and an optional arguments list. |
Lambda_inv |
(function, double vector) the inverse of |
t_min |
(scalar | vector | column matrix) the lower bound of the interval for each sampled point process The length of this argument is the number of point processes that should be drawn. |
t_max |
(scalar | vector | column matrix) the upper bound of the interval for each sampled point process The length of this argument is the number of point processes that should be drawn. |
Lambda_args |
(list) optional arguments to pass to Lambda. |
Lambda_inv_args |
(list) optional arguments to pass to Lambda_inv(). |
tol |
the tolerange for the calulations. |
atmost1 |
boolean, draw at most 1 event time per sampled point process. |
atleast1 |
boolean, draw at least 1 event time |
a matrix of event times with one row per sampled point process.
Vectorized sampling from a non homogeneous Poisson Point Process (NHPPP) from an interval (thinning method) with piecewise constant_majorizers. The majorizers are step functions over equal-length time intevals.
vdraw_intensity( lambda = NULL, lambda_args = NULL, Lambda_maj_matrix = NULL, lambda_maj_matrix = NULL, rate_matrix_t_min = NULL, rate_matrix_t_max = NULL, t_min = NULL, t_max = NULL, tol = 10^-6, atmost1 = FALSE, atleast1 = FALSE, atmostB = NULL )
vdraw_intensity( lambda = NULL, lambda_args = NULL, Lambda_maj_matrix = NULL, lambda_maj_matrix = NULL, rate_matrix_t_min = NULL, rate_matrix_t_max = NULL, t_min = NULL, t_max = NULL, tol = 10^-6, atmost1 = FALSE, atleast1 = FALSE, atmostB = NULL )
lambda |
(function) intensity function, vectorized |
lambda_args |
(list) optional arguments to pass to |
Lambda_maj_matrix |
(matrix) integrated intensity rates at the end of each interval |
lambda_maj_matrix |
(matrix) intensity rates, one per interval |
rate_matrix_t_min |
(scalar | vector | column matrix) is the lower bound of the time interval for each row of (Lambda|lambda)_maj_matrix. The length of this argument is the number of point processes that should be drawn. |
rate_matrix_t_max |
(scalar | vector | column matrix) the upper bound of the time interval for each row of (Lambda|lambda)_maj_matrix. The length of this argument is the number of point processes that should be drawn. |
t_min |
(scalar | vector | column matrix) is the lower bound
of a subinterval of (rate_matrix_t_min, rate_matrix_t_max]. If set,
times are sampled from the subinterval.
If omitted, it is equivalent to |
t_max |
(scalar | vector | column matrix) is the upper bound
of a subinterval of (rate_matrix_t_min, rate_matrix_t_max]. If set,
times are sampled from the subinterval.
If omitted, it is equivalent to |
tol |
(scalar, double) tolerance for the number of events |
atmost1 |
boolean, draw at most 1 event time |
atleast1 |
boolean, draw at least 1 event time |
atmostB |
If not NULL, draw at most B (B>0) event times. NULL means ignore. |
a matrix of event times (columns) per draw (rows) NAs are structural empty spots
x <- vdraw_intensity( lambda = function(x, ...) 0.1 * x, lambda_maj_matrix = matrix(rep(1, 5), nrow = 1), rate_matrix_t_min = 1, rate_matrix_t_max = 5 )
x <- vdraw_intensity( lambda = function(x, ...) 0.1 * x, lambda_maj_matrix = matrix(rep(1, 5), nrow = 1), rate_matrix_t_min = 1, rate_matrix_t_max = 5 )
Simulate a piecewise constant-rate Poisson Point Process over (t_min, t_max]
(inversion method)
where the intervals have the same length (are "regular").
vdraw_sc_step_regular( lambda_matrix = NULL, Lambda_matrix = NULL, rate_matrix_t_min = NULL, rate_matrix_t_max = NULL, t_min = NULL, t_max = NULL, tol = 10^-6, atmost1 = FALSE, atmostB = NULL, atleast1 = FALSE )
vdraw_sc_step_regular( lambda_matrix = NULL, Lambda_matrix = NULL, rate_matrix_t_min = NULL, rate_matrix_t_max = NULL, t_min = NULL, t_max = NULL, tol = 10^-6, atmost1 = FALSE, atmostB = NULL, atleast1 = FALSE )
lambda_matrix |
(matrix) intensity rates, one per interval |
Lambda_matrix |
(matrix) integrated intensity rates at the end of each interval |
rate_matrix_t_min |
(scalar | vector | column matrix) is the lower bound of the time interval for each row of (Lambda|lambda)_maj_matrix. The length of this argument is the number of point processes that should be drawn. |
rate_matrix_t_max |
(scalar | vector | column matrix) the upper bound of the time interval for each row of (Lambda|lambda)_maj_matrix. The length of this argument is the number of point processes that should be drawn. |
t_min |
(scalar | vector | column matrix) is the lower bound
of a subinterval of (rate_matrix_t_min, rate_matrix_t_max]. If set,
times are sampled from the subinterval.
If omitted, it is equivalent to |
t_max |
(scalar | vector | column matrix) is the upper bound
of a subinterval of (rate_matrix_t_min, rate_matrix_t_max]. If set,
times are sampled from the subinterval.
If omitted, it is equivalent to |
tol |
(scalar, double) tolerance for the number of events |
atmost1 |
boolean, draw at most 1 event time |
atmostB |
If not NULL, draw at most B (B>0) event times. NULL means ignore. |
atleast1 |
boolean, draw at least 1 event time |
a vector of event times t if no events realize, it will have 0 length
x <- vdraw_sc_step_regular( Lambda_matrix = matrix(1:5, nrow = 1), rate_matrix_t_min = 100, rate_matrix_t_max = 110, atmost1 = FALSE )
x <- vdraw_sc_step_regular( Lambda_matrix = matrix(1:5, nrow = 1), rate_matrix_t_min = 100, rate_matrix_t_max = 110, atmost1 = FALSE )
Sample zero-truncated NHPPP times using the order statistics method,
optionally using an rstream
generator
ztdraw_cumulative_intensity(Lambda, Lambda_inv, t_min, t_max, atmost1 = FALSE)
ztdraw_cumulative_intensity(Lambda, Lambda_inv, t_min, t_max, atmost1 = FALSE)
Lambda |
(function, double vector) a continuous increasing R to R map which is the integrated rate of the NHPPP |
Lambda_inv |
(function, double vector) the inverse of |
t_min |
(double) the lower bound of the time interval |
t_max |
(double) the upper bound of the time interval |
atmost1 |
(boolean) draw at most 1 event time |
a vector of at least 1 event times
size
samples from a zero-truncated non homogeneous Poisson Point Process (zt-NHPPP) from
(t_min, t_max) with linear intensity functionSample zero-truncated NHPPP times from a linear intensity function
using the inversion method, optionally using an rstream
generator
ztdraw_sc_linear(intercept, slope, t_min, t_max, atmost1 = FALSE)
ztdraw_sc_linear(intercept, slope, t_min, t_max, atmost1 = FALSE)
intercept |
(double) the intercept |
slope |
(double) the slope |
t_min |
(double) the lower bound of the time interval |
t_max |
(double) the upper bound of the time interval |
atmost1 |
(boolean) draw 1 event time |
a vector of at least 1 event times
x <- ztdraw_sc_linear(intercept = 0, slope = 0.2, t_min = 0, t_max = 10)
x <- ztdraw_sc_linear(intercept = 0, slope = 0.2, t_min = 0, t_max = 10)
Sample zt-NHPPP times from an log-linear intensity function
ztdraw_sc_loglinear(intercept, slope, t_min, t_max, atmost1 = FALSE)
ztdraw_sc_loglinear(intercept, slope, t_min, t_max, atmost1 = FALSE)
intercept |
(double) the intercept in the exponent |
slope |
(double) the slope in the exponent |
t_min |
(double) the lower bound of the time interval |
t_max |
(double) the upper bound of the time interval |
atmost1 |
boolean, 1 event time |
a vector of at least 1 event times
x <- ztdraw_sc_loglinear(intercept = 0, slope = 0.2, t_min = 0, t_max = 10)
x <- ztdraw_sc_loglinear(intercept = 0, slope = 0.2, t_min = 0, t_max = 10)
Simulate a zero-truncated homogeneous Poisson Point Process over (t_min, t_max]
ztppp(rate, t_min, t_max, atmost1 = FALSE)
ztppp(rate, t_min, t_max, atmost1 = FALSE)
rate |
(scalar, double) constant instantaneous rate |
t_min |
(scalar, double) lower bound of the time interval |
t_max |
(scalar, double) upper bound of the time interval |
atmost1 |
boolean, draw at most 1 event time |
a vector of event times of size size
x <- ztppp(t_min = 0, t_max = 10, rate = 0.001)
x <- ztppp(t_min = 0, t_max = 10, rate = 0.001)