
Stochastic urn simulation of the two-region feedback loop
Source:R/feedback_loop.R
morie_feedback_loop_sim.RdSimulates the patrol-and-discovery process step by step (C++ kernel).
Each step the patrol visits A with probability equal to the current
share and discovers a crime there with probability equal to that
region's true rate; the naive update adds the discovery to the count,
the corrected update adds it weighted by one over the presence that
produced it. Public reports, when rho > 0, arrive from a region
in proportion to the true rates regardless of presence.
Usage
morie_feedback_loop_sim(
lam_a,
lam_b,
c_a0,
c_b0,
n_steps = 1000L,
update = c("naive", "corrected"),
rho = 0,
n_sims = 100L,
seed = 0
)Arguments
- lam_a, lam_b
True crime rates (per patrol visit) of regions A and B; positive.
- c_a0, c_b0
Initial discovered-crime counts; positive.
- n_steps
Number of steps to iterate.
- update
"naive"(discovered counts fed back as they are) or"corrected"(each discovery discounted by the presence that produced it, so the increment is the true rate).- rho
Share of crimes that reach the record through public reports independent of patrol presence, in
[0, 1]. Withrho > 0the naive share is proved never to exceed \(\max(x_0, \lambda_A/(\lambda_A + \rho\lambda_B))\) (Research.P4.rho_cap): reports cap the loop strictly below 1 but strictly above the true-rate proportion unlessrho = 1.- n_sims
Number of independent runs.
- seed
Philox seed (non-negative integer). Run
idraws its uniforms from streami - 1of.morie_random_uniform, three per step whenrho > 0and two otherwise, so the R and Python arms produce identical paths for the same seed.
Value
A list with share_a (an n_sims by
n_steps + 1 matrix of share paths), final (the final
shares) and limit (the proved mean-field limit).
Examples
s <- morie_feedback_loop_sim(0.3, 0.2, 10, 10, n_steps = 2000, n_sims = 20, seed = 1)
stats::median(s$final) # near 1
#> [1] 0.7627981
s$limit$theorem
#> [1] "Research.P4.naiveShare_tendsto_one"