pub struct BatchBvnd { /* private fields */ }Expand description
Context for quickly evaluating bvnd at many points with a single value of rho
Implementations§
Source§impl BatchBvnd
impl BatchBvnd
Sourcepub fn new(rho: f64) -> Self
pub fn new(rho: f64) -> Self
Precompute for the evaluation of bivariate normal CDF at several points with this value of rho (correlation coefficient)
rho must be in the range [-1.0, 1.0].
Sourcepub fn bvnd(&self, x: f64, y: f64) -> f64
pub fn bvnd(&self, x: f64, y: f64) -> f64
Evaluate Pr[ X > x, Y > y ] for X, Y standard normals of correlation coefficient rho.
If x or y = +∞, the result will be 0.0.
If x or y = -∞, the result will be the value of the univariate CDF at the location of the other parameter.
If both are -∞, the result will be 1.0.
Sourcepub fn bvnd_with_precomputed_phi(
&self,
x: f64,
y: f64,
phi_minus_x: f64,
phi_minus_y: f64,
) -> f64
pub fn bvnd_with_precomputed_phi( &self, x: f64, y: f64, phi_minus_x: f64, phi_minus_y: f64, ) -> f64
Same as bvnd, but faster if you already know values of phi(-x), phi(-y).
Note that no checking of the values you provide is performed.
Here phi(-z) := 0.5 erfc(z/sqrt(2))
If you know the standard normal CDF value of z or -z, then you probably already have a decent value for phi.
Sourcepub fn grid_bvnd(&self, xs: &[f64], ys: &[f64], out: &mut [f64])
pub fn grid_bvnd(&self, xs: &[f64], ys: &[f64], out: &mut [f64])
Batch evaluate bvnd at all points of a grid.
This computes and reuses values of phi, the univariate normal CDF,
which improves performance significantly for large grids,
while keeping the API relatively easy to use from the caller’s perspective.
This routine does not allocate, but uses an output parameter to store results.
Input:
xs: The x-values of the grid, as&[f64]ys: The y-values of the grid, as&[f64]out: A&mut[f64]where computed values are stored.
Pre-conditions:
-
outhas length(xs.len() + 1) * (ys.len() + 1), and will be interpreted as a(Y+1) * (X+1)matrix. -
In the following, we use the notation
out[y_idx][x_idx] := out[y_idx * (xs.len() + 1) + x_idx ]. -
You may pass +∞ as an element of
xsorys, and that row or column will be entirely 0.0. -
If you pass -∞, that row or column will just be a duplicate of the 0th row or column.
Post-conditions:
-
The routine adds an “imaginary” value of -∞ to the beginning of your
xsarray andysarray. Then,out[y_idx][x_idx] = bvnd(xs'[x_idx], ys'[y_idx]), wherexs'ys'arexsandyswith those imaginary entries.- Here,
bvnd(x,y) := Pr[ X > x, Y > y]for X and Y standard normal of correlation coefficientrho.
- Here,
-
In other words, to find the answer to the query corresponding to indices
(x_idx, y_idx)in the input data, you have to add 1 tox_idxand toy_idxwhen you go to the output. The entries in row 0 or column 0 of the output are special, and correspond toxorybeing -∞. -
When
xoryis -∞, the bivariate normal cdf degenerates to the univariate normal cdf,phi. So,out[0][x_idx] = Pr[ X > xs'[x_idx] ] = phi(-xs'[x_idx])out[y_idx][0] = Pr[ Y > ys'[y_idx] ] = phi(-ys'[y_idx])out[0][0]will always be1.0.
-
When
xoryis ∞, the result will be0.0.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for BatchBvnd
impl RefUnwindSafe for BatchBvnd
impl Send for BatchBvnd
impl Sync for BatchBvnd
impl Unpin for BatchBvnd
impl UnwindSafe for BatchBvnd
Blanket Implementations§
§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
§unsafe fn clone_to_uninit(&self, dest: *mut u8)
unsafe fn clone_to_uninit(&self, dest: *mut u8)
clone_to_uninit)