public void TanhLayer_Forward() { var layer = new TanhLayer(); layer.Setup(bottom, top); layer.Forward(bottom, top); Assert.Equal(bottom.Count, top.Count); using (var topCpu = top.OnCpu()) using (var bottomCpu = bottom.OnCpu()) { int count = bottom.Count; for (int i = 0; i < bottom.Num; i++) { for (int j = 0; j < bottom.Channels; j++) { for (int k = 0; k < bottom.Height; k++) { for (int l = 0; l < bottom.Width; l++) { var v = (Math.Exp(2 * bottomCpu.DataAt(i, j, k, l)) - 1) / (Math.Exp(2 * bottomCpu.DataAt(i, j, k, l)) + 1); Assert.True(MathHelpers.Equality(topCpu.DataAt(i, j, k, l), v, 1e-4f)); } } } } } }
public void TanhLayer_Setup() { var layer = new TanhLayer(); layer.Setup(bottom, top); Assert.Equal(bottom.Num, top.Num); Assert.Equal(bottom.Channels, top.Channels); Assert.Equal(bottom.Height, top.Height); Assert.Equal(bottom.Width, top.Width); }