public void MishTest() { var a = new Matrix(2, 2); a.InRandomize(); var b = a.Duplicate(); a = new Mish().Forward(a); b.InMap((x) => x * Math.Tanh(Math.Log(1 + Math.Exp(x)))); Assert.IsTrue(Math.Abs(a.FrobeniusNorm() - b.FrobeniusNorm()) < 0.1, new Mish().Type().ToString() + " Activation."); }
public void MishPrimeTest() { var a = new Matrix(2, 2); a.InRandomize(); var b = a.Duplicate(); a = new Mish().Backward(a); b.InMap((x) => Math.Exp(x) * (4 * (x + 1) + 4 * Math.Exp(2 * x) + Math.Exp(3 * x) + Math.Exp(x) * (4 * x + 6)) / Math.Pow(2 * Math.Exp(x) + Math.Exp(2 * x) + 2, 2)); Assert.IsTrue(Math.Abs(a.FrobeniusNorm() - b.FrobeniusNorm()) < 0.1, new Mish().Type().ToString() + " Derivative."); }