Exemplo n.º 1
0
 def quantile(self, level: Tensor) -> Tensor:
     F = self.F
     exp = F.exp(
         self.mu
         + (self.sigma * F.sqrt(F.full(1, 2)) * erfinv(F, 2 * level - 1))
     )
     return exp / (1 + exp)
Exemplo n.º 2
0
def test_erfinv() -> None:
    try:
        from scipy.special import erfinv as scipy_erfinv
    except:
        pytest.skip("scipy not installed skipping test for erf")

    x = np.linspace(-1.0 + 1.0e-4, 1 - 1.0e-4, 11)
    y_mxnet = util.erfinv(mx.nd, mx.nd.array(x)).asnumpy()
    y_scipy = scipy_erfinv(x)
    assert np.allclose(y_mxnet, y_scipy, rtol=1e-3)
Exemplo n.º 3
0
    def quantile(self, level: Tensor) -> Tensor:
        F = self.F
        # we consider level to be an independent axis and so expand it
        # to shape (num_levels, 1, 1, ...)
        for _ in range(self.all_dim):
            level = level.expand_dims(axis=-1)

        return F.broadcast_add(
            self.mu,
            F.broadcast_mul(self.sigma,
                            math.sqrt(2.0) * erfinv(F, 2.0 * level - 1.0)),
        )
Exemplo n.º 4
0
def test_erfinv() -> None:
    try:
        from scipy.special import erfinv as scipy_erfinv
    except:
        pytest.skip("scipy not installed skipping test for erf")

    x = np.linspace(-1.0 + 1.0e-4, 1 - 1.0e-4, 11)
    y_scipy = scipy_erfinv(x)

    # Text np
    y_np = erfinv(x)
    assert np.allclose(y_np, y_scipy, rtol=1e-3)
Exemplo n.º 5
0
def test_erfinv() -> None:
    try:
        from scipy.special import erfinv as scipy_erfinv
    except:
        pytest.skip("scipy not installed skipping test for erf")

    x = np.linspace(-1.0 + 1.0e-4, 1 - 1.0e-4, 11)
    y_scipy = scipy_erfinv(x)

    # Test mx.nd
    y_mxnet = util.erfinv(mx.nd, mx.nd.array(x)).asnumpy()
    assert np.allclose(y_mxnet, y_scipy, rtol=1e-3)

    # Test mx.sym
    X = mx.symbol.Variable("x")
    func = util.erfinv(mx.sym, X)
    func_exec = func.bind(ctx=mx.cpu(), args={"x": mx.nd.array(x)})
    func_exec.forward()
    y_mxnet_sym = func_exec.outputs[0].asnumpy()
    assert np.allclose(y_mxnet_sym, y_scipy, rtol=1e-3)

    # Text np
    y_np = util.erfinv(np, x)
    assert np.allclose(y_np, y_scipy, rtol=1e-3)
Exemplo n.º 6
0
 def standard_gaussian_ppf(y: np.array) -> np.array:
     y_clipped = np.clip(y, a_min=1.0e-6, a_max=1.0 - 1.0e-6)
     return np.sqrt(2.0) * erfinv(2.0 * y_clipped - 1.0)