Exemplo n.º 1
0
        static void Main(string[] args)
        {
            int[] layerSizes = new int[3] {
                3, 4, 1
            };
            TransferFunction[] TFuncs = new TransferFunction[3] {
                TransferFunction.None,
                TransferFunction.Sigmoid,
                TransferFunction.Linear
            };

            BackPropagationNetwork bpn = new BackPropagationNetwork(layerSizes, TFuncs);

            double[] input   = new double[] { 4, 6, 8 }; //, new double[] {4, 7, 5}, new double[] {7, 4, 8}, new double[] {6, 7, 5}, new double[] {7, 7, 8}};
            double[] desired = new double[] { -0.86 };   //, new double[] {0.15}, new double[] {0.72 }, new double[] {0.53 }, new double[] { 0.44 } };

            /*double[] output = new double[1];
             *
             *
             * double error = 0.0;
             *
             * for(int i = 0; i < 10; i++)
             * {
             *
             *      error = bpn.Train(ref input, ref desired, 0.15, 0.1);
             *      bpn.Run(ref input, out output);
             *      if (i % 1 == 0)
             *          Console.WriteLine("Iteration {0}: \n\t Input {1:0.000} {2:0.000} {3:0.000} Output {4:0.000} error{5:0.000}", i, input[0], input[1], input[2], output[0], error);
             *
             *
             * }*/

            double[][] inputs =
            {
                new double[] {  0.4, 11.8,  0.1 },
                new double[] {  1.9,  1.9, 19.5 },
                new double[] {  1.2, 23.2,  0.3 },
                new double[] { 20.9,  0.0,  7.9 },
                new double[] { 13.0, 19.0, 11.0 },
                new double[] { 15.5,  2.9, 68.3 }
            };

            string[] names = new string[] { "Apples", "Avocado", "Leave", "Beef Steak", "Jam", "Brazil Nuts" };

            SOM somnetwork = new SOM(3, names, inputs);

            Console.WriteLine("----");
            string row = "Water";

            double[] water  = new double[] { 0.0, 0.0, 0.0 };
            int[]    result = somnetwork.Result(water);
            Console.WriteLine(row + " " + result[0] + " " + result[1]);

            Console.ReadKey();
        }
Exemplo n.º 2
0
        private void StartButton_Click(object sender, EventArgs e)
        {
            GenerateRandomInput();               // генеруємо дані
            somnetwork = new SOM(length, input); // створюємо і вчимо мережу

            // Прив'язка таблиць до DataGriedView
            GeneratedNumbers.DataSource = GeneratedTable;
            Result.DataSource           = ResultTable;
            insert.DataSource           = ParametersTable;

            // Створення колонок у таблицях
            GeneratedTable.Columns.Add("ID");
            for (int i = 0; i < parameters; i++)
            {
                string str = Convert.ToString(i + 1);
                GeneratedTable.Columns.Add(str);
            }

            ResultTable.Columns.Add("ID");
            ResultTable.Columns.Add("Winning Neuron coordinates");
            ResultTable.Columns.Add("Cluster");

            ParametersTable.Columns.Add("Parameters");

            // Додавання рядків у таблиці
            for (int i = 0; i < size; i++)
            {
                DataRow row = GeneratedTable.NewRow();
                row[0] = i + 1;
                for (int j = 0; j < parameters; j++)
                {
                    row[j + 1] = Math.Round(input[i][j], 3);
                }
                GeneratedTable.Rows.Add(row);
            }

            int[][] result = somnetwork.Result();

            for (int i = 0; i < size; i++)
            {
                DataRow row = ResultTable.NewRow();
                row[0] = i + 1;
                row[1] = Convert.ToString(result[i][0] + "; " + result[i][1]);
                row[2] = result[i][2];
                ResultTable.Rows.Add(row);
            }

            for (int i = 0; i < parameters; i++)
            {
                DataRow row = ParametersTable.NewRow();
                ParametersTable.Rows.Add(row);
            }
        }
Exemplo n.º 3
0
        private void TestButton_Click(object sender, EventArgs e)
        {
            double[] test = new double[parameters];
            int      i    = 0;

            foreach (DataGridViewRow row in insert.Rows)
            {
                foreach (DataGridViewCell cell in row.Cells)
                {
                    test[i] = Convert.ToDouble(cell.Value.ToString());
                    i++;
                }
            }

            int[] output = new int[3];

            output = somnetwork.Result(test);

            Coordinates.Text = Convert.ToString(output[0] + "; " + output[1]);
            Cluster.Text     = Convert.ToString(output[2]);
        }