ppp_n(), ppp_orderstat() and ppp_sequential() (deprecated since
0.5.0; use ppp_exactly_n(), ppp2() and ppp()) and the deprecated
rng_stream argument of ppp_next_n().rng_stream_*() helpers; rstream is no longer a
dependency. For stream-based reproducibility, set an rstream object as R's
global generator with rstream::rstream.RNG() (see ?nhppp).New features — two orthogonal truncation option classes
report_first_K, report_last_K; at most one may be set):
return only the earliest / latest min(N, K) events of the realization.
These are reporting truncations — the count law of the sampled process
is unchanged. atmost1 remains as the alias for report_first_K = 1.generate_at_least_K, generate_at_most_K;
combinable with K1 <= K2): change the sampled law to X | K1 <= N <= K2.
generate_at_least_K = 1 alone is the zero-truncated case (atleast1
remains as its alias); generate_at_least_K = generate_at_most_K = K
conditions on exactly K events — which is NOT the same object as
reporting the first K of an N >= K draw (the reported-first-K times
are biased early relative to the exactly-K law). Conditioned sampling
uses the exact order-statistics construction with a doubly-truncated
Poisson count, drawn by inversion of the CDF restricted to the
truncation region (upper-tail parameterization, numerically stable deep
in the right tail; primitives rbtpois() in R and
rbtpois/rbtpois_vec in C++). Any generation bound routes to the
order-statistics kernels; without generation bounds the sequential
inversion kernels are used (they cannot condition on the future total).vdraw_cumulative_intensity() supports the full option set: any
generation bound switches from sequential inversion to the exact
order-statistics construction on the Lambda scale (doubly-truncated
Poisson count; the ascending uniforms on
(Lambda(t_min), Lambda(t_max)) are drawn as normalized Exp(1)
spacings and mapped through Lambda_inv), and report_last_K is
honored on all paths.generate_at_least_K = 1.ppp(), draw_sc_linear(), draw_sc_loglinear(),
draw_cumulative_intensity() and draw_intensity() accept the full
option set (report_first_K, report_last_K, atleast1,
generate_at_least_K, generate_at_most_K), like draw_sc_step() and
draw(). Any generation bound routes to the zero-truncated twin
(ztppp(), ztdraw_sc_linear(), ztdraw_sc_loglinear(),
ztdraw_cumulative_intensity()); draw_intensity() supports only
generate_at_least_K = 1. The new arguments follow the existing ones, and
calls that do not use them return the same draws as before.budget_cap replaces atmostB (soft-deprecated alias with a warning):
it caps the computational event budget of the vectorized kernels and is
an approximation knob (jointly with the 1 - tol quantile bound), not
an exact reporting or conditioning contract. It is now honored uniformly
by all vectorized sc-step paths (the whole-range regular path used to
ignore atmostB silently) and never truncates the conditioned count
below generate_at_least_K.Internals
src/sc_step_core.h); whole-range sampling is
the subinterval special case. Net deletion of ~300 lines with no
performance loss: the whole-range paths are ~6x faster (the fixed-size
blocked Exp(1) draw is replaced by lazy per-event draws), the
zero-truncated paths ~1.5x faster, and the subinterval paths ~1.2x
faster in the included benchmark (benchmarks/bench_sc_step_unify.R).tol instead of a hard-coded
.99999 event-count quantile.range_t/t_min/t_max inputs are shared across rows instead of
being replicated at the R level..github/workflows/rhub.yaml) for
sanitizer and valgrind checks. The unified kernels are clean under
clang-ASan, gcc-ASan, and valgrind (the one valgrind finding is a small
leak in the rstream dependency, not in nhppp code).Structured argument containers for user functions
lambda_args, Lambda_args) now have two explicit
channels: shared (a named list of row-invariant arguments of any type,
stored once and never replicated across point processes) and row_args
(a data.frame or data.table with one row per point process, validated
for row count and automatically row-subset by the rejection loops). The
container is passed as the user function's SECOND POSITIONAL argument,
exactly as given except that row_args is already subset; the name of
the second formal is the user's choice.vector_arguments data.table convention is
deprecated (mapped onto row_args semantics, warning once per call);
Lambda_inv_args is deprecated — one Lambda_args container is
delivered to both Lambda and Lambda_inv. For
vdraw_cumulative_intensity(), flat/legacy containers keep the released
named-argument call (Lambda(t, Lambda_args = ...)) with a deprecation
warning; structured containers get the positional call. When no
arguments are supplied at all, user functions are now called with a
single argument (Lambda(t) instead of Lambda(t, Lambda_args = NULL)),
so plain one-argument closures work everywhere.row_args/vector_arguments accept plain data.frames (the data.table
requirement is dropped; data.tables are still accepted as-is, read-only,
never coerced or copied).get_step_majorizer() gains fun_args, taking the same container with
the same delivery convention, so the sampler's lambda can be used for
majorizer construction without hand-wrapping.Thinning (intensity) family
vdraw_intensity_step(): vectorized thinning sampler with piecewise
constant majorizers over arbitrary interval bounds (time_breaks, as in
vdraw_sc_step()); the target intensity remains an arbitrary vectorized
R function. Generalizes vdraw_intensity(), which assumes equal-length
intervals. Both share one C++ template core (src/intensity_step_core.h).vdraw_intensity(), vdraw_intensity_step()): conditioning is by
rejection — candidate realizations are proposed from the majorizer
conditioned on at least K1 majorizer events (exact: only the lower bound
may be pushed into the proposal), thinned, and rows whose accepted count
falls outside [K1, K2] are resampled. The per-round acceptance
probability degrades in the strictness of the bounds and in the
looseness of the majorizer; there is no iteration cap. Special case
K1 = K2 = K (exactly K events): only under-counts are rejected —
rows with more than K survivors are salvaged exactly by keeping a
uniformly random size-K subset of the events (conditionally-iid times
make the subset an exact exactly-K draw regardless of the surviving
count, with no knowledge of the integrated target intensity), avoiding
the near-zero two-sided acceptance probability when the target
integrated intensity is large relative to K. The scalar thinning
samplers support only generate_at_least_K = 1.lambda exceeds the majorizer also
on the conditioned path (the old R-only zero-truncated path silently
capped acceptance probabilities above 1, sampling from the wrong
process when the majorizer was invalid). The internal
vdraw_intensity_step_regular_forcezt() is removed, superseded by the
conditioned C++ kernel.Long-format output for the vectorized samplers
output = c("matrix", "long") argument on the sc-step samplers
(vdraw_sc_step(), vztdraw_sc_step(), vdraw_sc_step_regular() and
the _cpp kernels) and on vdraw_cumulative_intensity() / vdraw().
"long" returns list(id, time, n_draws) with one entry per event:
id is the 1-based point-process index (ascending, times ascending
within id). A point process with zero events contributes no entries —
its id is absent, and n_draws distinguishes "no events" from "not
sampled"; no NA is used. The C++ paths build the long format directly
(no dense intermediate; accumulator reserve()d from the expected
Lambda mass), so it is preferred when event counts vary widely across
point processes: in the included benchmark (10^6 processes, mean ~1
event, max ~40), 404 MB dense vs 11.5 MB long, and ~30% faster. RNG
consumption is identical across the two outputs, so a same-seed dense
and long draw hold the same event values. On the conditioned
vdraw_cumulative_intensity() path, Lambda_inv is called on the
event vector with row_args subset to one row per event (aligned by
id). The thinning samplers do not take output yet.Documentation
draw(), vdraw(),
and vdraw_cumulative_intensity() gain examples (they had none); the
structured args containers, the generation bounds (including exactly-K),
the reporting truncations, and get_step_majorizer(fun_args = ) are now
demonstrated on the reference pages. Vignette code uses budget_cap and
the reporting/generation vocabulary throughout.Breaking change (random streams only)
New features
Bug fixes (each with a regression test)
Tests and validation
enCRAN release
fixed rare overflow error in rztpois where an explicit cast from double to int was used -- now we use safe_double_to_int to avoid overflow; this overflow resulted in a segmentation fault in x86 hardware and in silent failures in AArch64 hardware. This bug should not be relevant for most practical uses of the package.
added new citation for the paper by Trikalinos and Sereda (2024, doi:10.1371/journal.pone.0311311)
Function arguments are now more consistent.
More extensive numerical checks.
Added C++ code for vectorized functions -- for computational speed and memory efficiency.
Renamed functions to start from draw (instead of nhppp_t), draw_zt (instead of ztnhppp_t), and vdraw (instead of ending in _vec())
Initial CRAN submission.