コード例 #1
0
ファイル: Neuro.cs プロジェクト: vurf/neural-network
 private static void WriteModel(ResultModel model)
 {
     var str = string.Format("Входной образ: {0}. Вес: {1}. Кол-во итераций: {2}. Эталон: {3}.",
         model.Enter,
         model.Weight,
         model.Iterations,
         model.Error
         );
     Console.WriteLine(str);
     model.Array.WriteArray();
     Console.WriteLine();
 }
コード例 #2
0
ファイル: Neuro.cs プロジェクト: vurf/neural-network
        public void Start()
        {
            var enters = new[] {x1, x2, x3};
            var weights = new[] {w1, w2, w3};
            var outers = new List<ResultModel>();

            for (int i = 0; i < enters.Length; i++)
            {
                for (int j = 0; j < weights.Length; j++)
                {
                    var error = -1;

                    var model = new ResultModel();
                    model.Weight = j;
                    model.Enter = i;
                    model.Iterations = 0;
                    model.Array = new int[weights[j].Length];

                    do
                    {
                        var array = Multiplication(enters[i], weights[j]);
                        var sum = Summation(array);

                        var y = sum <= 60 ? 0 : 1;
                        error = y;
                        var delta = d[i, j] - y;
                        for (int k = 0; k < weights[j].Length; k++)
                        {
                            weights[j][k] = weights[j][k] + 1 * delta * enters[i][k];
                        }

                        model.Iterations += 1;
                        model.Error = error;
                        weights[j].CopyTo(model.Array, 0);

                        if (error == d[i, j])
                        {
                            outers.Add(model);
                        }
                    } while (error != d[i, j]);
                }
            }

            WriteResult(outers);
        }