Skip to main content

sample_jump_kernel

Function sample_jump_kernel 

Source
pub fn sample_jump_kernel(jumps: &[JumpTransition], noise: f64) -> i32
Expand description

Samples a single jump from a set of competing Poisson transitions.

Each transition fires with intensity rate; the first to fire wins. Under competing exponentials the winner is transition i with probability rate_i / sum_j rate_j, so the amplitude is drawn by mapping a uniform u (via the standard-normal CDF of noise) to the cumulative rate. When the total rate is zero or u falls outside [0, 1) no jump occurs.

ยงExamples

use solver::numeric::finite_difference::discretization::{
    JumpTransition, sample_jump_kernel,
};
let jumps = [JumpTransition::new(2, 1.0), JumpTransition::new(-3, 1.0)];
// Noise far negative maps the CDF to zero, selecting the first transition.
assert_eq!(sample_jump_kernel(&jumps, -10.0), 2);
// Noise far positive maps the CDF to one, selecting the last transition.
assert_eq!(sample_jump_kernel(&jumps, 10.0), -3);
assert_eq!(sample_jump_kernel(&[], 0.0), 0);