public void PoissonTest() { var actual = new Matrix(4, 1); var expected = new Matrix(4, 1); actual.InRandomize(); expected.InRandomize(); var autoErr = new Poisson().Evaluate(actual, expected); var error = 0.0; for (var i = 0; i < actual.Rows; i++) { for (var j = 0; j < actual.Columns; j++) { error += actual[i, j] - expected[i, j] * Math.Log(actual[i, j] + double.Epsilon); } } error /= actual.Rows * actual.Columns; Assert.IsTrue(Math.Abs(error - autoErr) < 0.01, new Poisson().Type().ToString() + " Forward!"); var autoDErr = new Poisson().Backward(actual, expected); var dErr = new Matrix(actual.Rows, actual.Columns); for (var i = 0; i < actual.Rows; i++) { for (var j = 0; j < actual.Columns; j++) { dErr[i, j] = 1.0 - expected[i, j] / (actual[i, j] + double.Epsilon); } } Assert.IsTrue(Math.Abs(dErr.FrobeniusNorm() - autoDErr.FrobeniusNorm()) < 0.01, new Poisson().Type().ToString() + " Backward!"); }