Exemplo n.º 1
0
        public static void Run()
        {
            var    test = new double[2, 3];
            double temp = 1;

            for (int i = 0; i < test.GetLength(0); i++)
            {
                for (int j = 0; j < test.GetLength(1); j++)
                {
                    test[i, j] = temp++;
                }
            }

            Console.WriteLine("Test matrix");
            Console.WriteLine(test.Printable());

            Console.WriteLine("Test matrix transpose");
            Console.WriteLine(test.Transpose().Printable());

            Console.WriteLine("Scalar matrix multiplication");
            Console.WriteLine(MatrixUtils.Multiply(test.Transpose(), 3).Printable());

            Console.WriteLine("Matrix multiplication");
            Console.WriteLine(MatrixUtils.Multiply(test, test.Transpose()).Printable());

            var singleDim = new double[1, 1];

            for (int i = 0; i < singleDim.GetLength(0); i++)
            {
                for (int j = 0; j < singleDim.GetLength(1); j++)
                {
                    Console.WriteLine("singleDim: " + singleDim[i, j]);
                }
            }
        }
        // REVIEW: input matrix has 1 column
        public bool Train(double[,] input, double desiredValue)
        {
            double output;
            double sum = MatrixUtils.ElementsSum(MatrixUtils.Multiply(weights, input));

            output = Utils.StepF(sum, threshold);
            bool correct = output == desiredValue;

            if (!correct)
            {
                for (int i = 0; i < input.Length; i++)
                {
                    if (input[i, 0] > 0)
                    {
                        weights[i, 1] += (desiredValue - output) * learningRate;
                    }
                }
            }

            return(correct);
        }