def test_erf() -> None: try: from scipy.special import erf as scipy_erf except: pytest.skip("scipy not installed skipping test for erf") x = np.array([-1000, -100, -10] + np.linspace(-5, 5, 1001).tolist() + [10, 100, 1000]) y_scipy = scipy_erf(x) # Test mx.nd y_mxnet = util.erf(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.erf(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.erf(np, x) assert np.allclose(y_np, y_scipy, atol=1e-7)
def test_erf() -> None: try: from scipy.special import erf as scipy_erf except: pytest.skip("scipy not installed skipping test for erf") x = np.array([-1000, -100, -10] + np.linspace(-5, 5, 1001).tolist() + [10, 100, 1000]) y_mxnet = util.erf(mx.nd, mx.nd.array(x)).asnumpy() y_scipy = scipy_erf(x) assert np.allclose(y_mxnet, y_scipy)
def test_erf() -> None: try: from scipy.special import erf as scipy_erf except: pytest.skip("scipy not installed skipping test for erf") x = np.array([-1000, -100, -10] + np.linspace(-5, 5, 1001).tolist() + [10, 100, 1000]) y_scipy = scipy_erf(x) # Text np y_np = erf(x) assert np.allclose(y_np, y_scipy, atol=1e-7)
def standard_gaussian_cdf(x: np.array) -> np.array: u = x / (np.sqrt(2.0)) return (erf(u) + 1.0) / 2.0
def cdf(self, x): F = self.F u = self.F.broadcast_div(self.F.broadcast_minus(x, self.mu), self.sigma * math.sqrt(2.0)) return (erf(F, u) + 1.0) / 2.0