private static NdArray CND(NdArray X) { DATA a1 = 0.31938153f, a2 = -0.356563782f, a3 = 1.781477937f, a4 = -1.821255978f, a5 = 1.330274429f; var L = X.Abs(); var K = 1.0f / (1.0f + 0.2316419f * L); var w = 1.0f - 1.0f / ((DATA)Math.Sqrt(2 * Math.PI)) * (-L * L / 2.0f).Exp() * (a1 * K + a2 * (K.Pow(2)) + a3 * (K.Pow(3)) + a4 * (K.Pow(4)) + a5 * (K.Pow(5))); var mask1 = (NdArray)(X < 0); var mask2 = (NdArray)(X >= 0); w = w * mask2 + (1.0f - w) * mask1; return w; }
private static NdArray CND(NdArray X) { DATA a1 = 0.31938153f, a2 = -0.356563782f, a3 = 1.781477937f, a4 = -1.821255978f, a5 = 1.330274429f; var L = X.Abs(); var K = 1.0f / (1.0f + 0.2316419f * L); var w = 1.0f - 1.0f / ((DATA)Math.Sqrt(2 * Math.PI)) * (-L * L / 2.0f).Exp() * (a1 * K + a2 * (K.Pow(2)) + a3 * (K.Pow(3)) + a4 * (K.Pow(4)) + a5 * (K.Pow(5))); var mask1 = (NdArray)(X < 0); var mask2 = (NdArray)(X >= 0); w = w * mask2 + (1.0f - w) * mask1; return(w); }
private static NdArray <bool> IsCloseWithTolerence <P>(NdArray <P> lhs, NdArray <P> rhs, P absoluteTolerence, P relativeTolerence) { var absoluteTolerenceScalar = NdArray <P> .ScalarLike(lhs, absoluteTolerence); var relativeTolerenceScalar = NdArray <P> .ScalarLike(lhs, relativeTolerence); /// NOTE This is not symmetric. /// https://docs.scipy.org/doc/numpy-1.15.0/reference/generated/numpy.isclose.html var absDiff = NdArray <P> .Abs(lhs - rhs); var absRhs = NdArray <P> .Abs(rhs); return(absDiff <= absoluteTolerenceScalar + (relativeTolerenceScalar * absRhs)); }