def test_softplus(self): v_orig = mx.nd.array([-10.], dtype=np.float64) p = PositiveTransformation() v_pos = p.transform(v_orig) v_inv_trans = p.inverseTransform(v_pos) assert v_orig.asnumpy()[0] < 0 assert v_pos.asnumpy()[0] > 0 assert v_inv_trans.asnumpy()[0] < 0 npt.assert_allclose(v_inv_trans.asnumpy()[0], v_orig.asnumpy()[0], rtol=1e-7, atol=1e-10)
def test_softplus_numerical(self, x, rtol, atol): p = PositiveTransformation() mf_pos = p.transform(x) mf_inv = p.inverseTransform(mf_pos) np_pos = np.log1p(np.exp(x.asnumpy())) np_inv = np.log(np.expm1(np_pos)) npt.assert_allclose(mf_pos.asnumpy(), np_pos, rtol=rtol, atol=atol) npt.assert_allclose(mf_inv.asnumpy(), np_inv, rtol=rtol, atol=atol) npt.assert_allclose(mf_inv.asnumpy(), x.asnumpy(), rtol=rtol, atol=atol)