Exemplo n.º 1
0
        static void TestStandardPerceptron()
        {
            IPerceptron brain = new StandardPerceptron(2, 0.01m, Functions.Activation.BinaryStep, Functions.ActivationDerivatives.BinaryStep);

            Dictionary <decimal[], decimal> data = new Dictionary <decimal[], decimal>();

            data.Add(new decimal[] { 0, 0 }, 0);
            data.Add(new decimal[] { 1, 0 }, 0);
            data.Add(new decimal[] { 0, 1 }, 0);
            data.Add(new decimal[] { 1, 1 }, 1);

            Console.WriteLine("BEFORE TRAINING");
            Console.WriteLine($"0, 0 -> {brain.CalculateOutput(new decimal[] { 0, 0 })}");
            Console.WriteLine($"1, 0 -> {brain.CalculateOutput(new decimal[] { 1, 0 })}");
            Console.WriteLine($"0, 1 -> {brain.CalculateOutput(new decimal[] { 0, 1 })}");
            Console.WriteLine($"1, 1 -> {brain.CalculateOutput(new decimal[] { 1, 1 })}");

            brain.StartTraining(data, 1000);

            Console.WriteLine("AFTER TRAINING");
            Console.WriteLine($"0, 0 -> {brain.CalculateOutput(new decimal[] { 0, 0 })}");
            Console.WriteLine($"1, 0 -> {brain.CalculateOutput(new decimal[] { 1, 0 })}");
            Console.WriteLine($"0, 1 -> {brain.CalculateOutput(new decimal[] { 0, 1 })}");
            Console.WriteLine($"1, 1 -> {brain.CalculateOutput(new decimal[] { 1, 1 })}");

            Console.ReadKey();
        }
Exemplo n.º 2
0
        static void TestPerceptronParametersDirectVisualization()
        {
            IPerceptron perceptron = new StandardPerceptron(12, 0, null, null);

            foreach (decimal w in perceptron.Weights)
            {
                Console.WriteLine(w);
            }

            IDirectParametersVisualizer visualizer = new PerceptronDirectParametersVisualizer(perceptron, DirectParametersVisualizationType.SquareOfRGB);
            Bitmap img = visualizer.Visualize();

            for (int y = 0; y < img.Height; y++)
            {
                for (int x = 0; x < img.Width; x++)
                {
                    Color c = img.GetPixel(x, y);
                    Console.WriteLine($"{x}, {y} = [{c.R}, {c.G}, {c.B}]");
                }
            }

            Console.ReadKey();
        }