@@ -92,16 +92,16 @@ def bvn(r: Tensor, xl: Tensor, yl: Tensor, xu: Tensor, yu: Tensor) -> Tensor:
9292def bvnu (r : Tensor , h : Tensor , k : Tensor ) -> Tensor :
9393 r"""Solves for `P(x > h, y > k)` where `x` and `y` are standard bivariate normal
9494 random variables with correlation coefficient `r`. In [Genz2004bvnt]_, this is (1)
95- ```
96- L(h, k, r) = P(x < -h, y < -k)
97- = 1/(a 2\pi) \int_{h}^{\infty} \int_{k}^{\infty} f(x, y, r) dy dx,
98- ```
95+
96+ ` L(h, k, r) = P(x < -h, y < -k) \
97+ = 1/(a 2\pi) \int_{h}^{\infty} \int_{k}^{\infty} f(x, y, r) dy dx,`
98+
9999 where `f(x, y, r) = e^{-1/(2a^2) (x^2 - 2rxy + y^2)}` and `a = (1 - r^2)^{1/2}`.
100100
101101 [Genz2004bvnt]_ report the following integation scheme incurs a maximum of 5e-16
102- error when run in double precision: if |r| >= 0.925, use a 20-point quadrature rule
103- on a 5th order Taylor expansion; else, numerically integrate in polar coordinates
104- using no more than 20 quadrature points.
102+ error when run in double precision: if ` |r| >= 0.925` , use a 20-point quadrature
103+ rule on a 5th order Taylor expansion; else, numerically integrate in polar
104+ coordinates using no more than 20 quadrature points.
105105
106106 Args:
107107 r: Tensor of correlation coefficients.
@@ -137,10 +137,10 @@ def _bvnu_polar(
137137 r : Tensor , h : Tensor , k : Tensor , num_points : Optional [int ] = None
138138) -> Tensor :
139139 r"""Solves for `P(x > h, y > k)` by integrating in polar coordinates as
140- ```
141- L(h, k, r) = \Phi(-h)\Phi(-k) + 1/(2\pi) \int_{0}^{sin^{-1}(r)} f(t) dt
142- f(t) = e^{-0.5 cos(t)^{-2} (h^2 + k^2 - 2hk sin(t))}
143- ```
140+
141+ ` L(h, k, r) = \Phi(-h)\Phi(-k) + 1/(2\pi) \int_{0}^{sin^{-1}(r)} f(t) dt \
142+ f(t) = e^{-0.5 cos(t)^{-2} (h^2 + k^2 - 2hk sin(t))}`
143+
144144 For details, see Section 2.2 of [Genz2004bvnt]_.
145145 """
146146 if num_points is None :
@@ -168,12 +168,13 @@ def _bvnu_taylor(r: Tensor, h: Tensor, k: Tensor, num_points: int = 20) -> Tenso
168168 r"""Solves for `P(x > h, y > k)` via Taylor expansion.
169169
170170 Per Section 2.3 of [Genz2004bvnt]_, the bvnu equation (1) may be rewritten as
171- ```
172- L(h, k, r) = L(h, k, s) - s/(2\pi) \int_{0}^{a} f(x) dx
173- f(x) = (1 - x^2){-1/2} e^{-0.5 ((h - sk)/ x)^2} e^{-shk/(1 + (1 - x^2)^{1/2})},
174- ```
171+
172+ ` L(h, k, r) = L(h, k, s) - s/(2\pi) \int_{0}^{a} f(x) dx \
173+ f(x) = (1 - x^2){-1/2} e^{-0.5 ((h - sk)/ x)^2} e^{-shk/(1 + (1 - x^2)^{1/2})},`
174+
175175 where `s = sign(r)` and `a = sqrt(1 - r^{2})`. The term `L(h, k, s)` is analytic.
176- The second integral is approximated via Taylor expansion.
176+ The second integral is approximated via Taylor expansion. See Sections 2.3 and
177+ 2.4 of [Genz2004bvnt]_.
177178 """
178179 _0 , _1 , _ni2 , _i2pi , _sq2pi = get_constants_like (
179180 values = (0 , 1 , - 0.5 , _inv_2pi , _sqrt_2pi ), ref = r
@@ -246,13 +247,13 @@ def bvnmom(
246247 r"""Computes the expected values of truncated, bivariate normal random variables.
247248
248249 Let `x` and `y` be a pair of standard bivariate normal random variables having
249- correlation `r`. This function computes `E([x,y] | [xl,yl] < [x,y] < [xu,yu])`.
250+ correlation `r`. This function computes `E([x,y] \ | [xl,yl] < [x,y] < [xu,yu])`.
250251
251252 Following [Muthen1990moments]_ equations (4) and (5), we have
252- ```
253- E(x | [xl, yl] < [x, y] < [xu, yu])
254- = Z^{-1} \phi(xl) P(yl < y < yu | x=xl) - \phi(xu) P(yl < y < yu | x=xu)
255- ```
253+
254+ ` E(x \ | [xl, yl] < [x, y] < [xu, yu]) \
255+ = Z^{-1} \phi(xl) P(yl < y < yu \ | x=xl) - \phi(xu) P(yl < y < yu \ | x=xu),`
256+
256257 where `Z = P([xl, yl] < [x, y] < [xu, yu])` and `\phi` is the standard normal PDF.
257258
258259 Args:
@@ -264,7 +265,8 @@ def bvnmom(
264265 p: Tensor of probabilities `P(xl < x < xu, yl < y < yu)`, same shape as `r`.
265266
266267 Returns:
267- `E(x | [xl, yl] < [x, y] < [xu, yu])` and `E(y | [xl, yl] < [x, y] < [xu, yu])`.
268+ `E(x \| [xl, yl] < [x, y] < [xu, yu])` and
269+ `E(y \| [xl, yl] < [x, y] < [xu, yu])`.
268270 """
269271 if not (r .shape == xl .shape == xu .shape == yl .shape == yu .shape ):
270272 raise UnsupportedError ("Arguments to `bvn` must have the same shape." )
0 commit comments