static void AccuracyTestPerc() { Console.WriteLine("Accuracy test perc:"); int[] neurons = new int[] { 3, 4, 2 }; bool[] delays = new bool[] { false, false }; string[] afs = new string[] { "Binary Step", "Identity" }; float[][] w = new float[][] { new float[] { 1.0f / 2, 1.0f / 3, -1.0f / 5, 1, 1.0f / 2, -1.0f / 4, 1.0f / 2, -1, 1.0f / 2, -1, 1.0f / 4, 1.0f / 3 }, new float[] { 1.0f / 2, -1.0f / 3, 1.0f / 4, -1, 1, -1.0f / 2, -1.0f / 3, 1.0f / 4 } }; PerceptronManaged p = new PerceptronManaged(new PerceptronTopology(3, neurons, delays, afs)); p.SetWeights(w); var p2 = p.Copy(); float[] y = p2.Solve(new float[] { 1, 0, 1 }); float[] answer = { 5.0f / 12, 1.0f / 6 }; float EPS = 1e-5f; if ((Math.Abs(y[0] - answer[0]) > EPS) || (Math.Abs(y[1] - answer[1]) > EPS)) { Console.WriteLine("FAIL"); } else { Console.WriteLine("PASS"); } }
static void PerformanceTest() { Console.WriteLine("Performance test"); Stopwatch sw = new Stopwatch(); int N = 1000000; int layers = 7; int[] neurons = new int[] { 5, 55, 70, 100, 60, 15, 2 }; bool[] delays = new bool[] { true, true, true, true, true, false }; string af = "Logistic"; string[] afs = new string[] { af, af, af, af, af, af }; sw.Start(); PerceptronTopology topology = new PerceptronTopology(layers, neurons, delays, afs); sw.Stop(); Console.WriteLine("topology creation = " + sw.ElapsedMilliseconds); sw.Start(); PerceptronManaged perc = new PerceptronManaged(topology); perc.SetWeights(GenerateWeights(neurons, delays)); sw.Stop(); Console.WriteLine("perc creation = " + sw.ElapsedMilliseconds); float[] x = { 1.0f, 0.0f, 0.0f, 1.0f, 0.0f }; sw.Start(); for (int i = 0; i < N; i++) { float[] y = perc.Solve(x); } sw.Stop(); Console.WriteLine("calc = " + sw.ElapsedMilliseconds); }