BatchBvnd

Struct BatchBvnd 

Source
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

Source

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].

Source

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.

Source

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.

Source

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:

  • out has 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 xs or ys, 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 xs array and ys array. Then, out[y_idx][x_idx] = bvnd(xs'[x_idx], ys'[y_idx]), where xs' ys' are xs and ys with those imaginary entries.

    • Here, bvnd(x,y) := Pr[ X > x, Y > y] for X and Y standard normal of correlation coefficient rho.
  • 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 to x_idx and to y_idx when you go to the output. The entries in row 0 or column 0 of the output are special, and correspond to x or y being -∞.

  • When x or y is -∞, 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 be 1.0.
  • When x or y is ∞, the result will be 0.0.

Trait Implementations§

Source§

impl Clone for BatchBvnd

Source§

fn clone(&self) -> BatchBvnd

Returns a duplicate of the value. Read more
1.0.0§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for BatchBvnd

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

§

impl<T> Any for T
where T: 'static + ?Sized,

§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
§

impl<T> Borrow<T> for T
where T: ?Sized,

§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
§

impl<T> BorrowMut<T> for T
where T: ?Sized,

§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
§

impl<T> CloneToUninit for T
where T: Clone,

§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
§

impl<T> From<T> for T

§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T, U> Into<U> for T
where U: From<T>,

§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

§

impl<T> ToOwned for T
where T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.