static void Main(string[] args)
        {
            // 階層型ニューラルネットワークを構成
            var nn = new HierarchicalNetwork(2, 2, 1);
            nn[1, 0].Weights[0] = 10.0;
            nn[1, 0].Weights[1] = 10.0;
            nn[1, 0].Threshold = -5.0;
            nn[1, 1].Weights[0] = 10.0;
            nn[1, 1].Weights[1] = 10.0;
            nn[1, 1].Threshold = -15.0;
            nn[2, 0].Weights[0] = 10.0;
            nn[2, 0].Weights[1] = -10.0;
            nn[2, 0].Threshold = -5.0;

            // 発火
            nn.SetInputs(new ConstOutput(0.0), new ConstOutput(1.0));
            nn.Fire();

            // グラフを出力
            var gen = new GraphGenerator();
            using (var writer = new StreamWriter("graph.gv"))
            {
                gen.Generate(writer, nn);
            }
        }
        static void Main(string[] args)
        {
            Func<double, double> f = ((double x) => 1 / (1 + Math.Exp(-x)));
            Func<double, double> df = (x => f(x) * (1 - f(x)));

            // ネットワークの情報読み込み
            HierarchicalNetwork nn;
            var examples = new List<Tuple<double[], double[]>>();

            Console.Error.Write("path >");
            var path = Console.ReadLine();
            using (var reader = new StreamReader(path))
            {
                nn = new HierarchicalNetwork(reader.ReadLine().Split(' ').Select(v => int.Parse(v)).ToArray());
                var exNum = int.Parse(reader.ReadLine());
                for (var i = 0; i < exNum; ++i)
                {
                    var io = reader.ReadLine().Split('|').ToList();
                    examples.Add(Tuple.Create(
                        io[0].Split(' ').Select(v => double.Parse(v)).ToArray(),
                        io[1].Split(' ').Select(v => double.Parse(v)).ToArray()
                        ));
                }
            }

            // 学習
            var bp = new Backpropagation(nn, df, 0.8, 0.75);
            var rnd = new Random();
            using (var writer = new StreamWriter("error.csv"))
            {
                for (var i = 0; i < 1000; ++i)
                {
                    var ex = examples.OrderBy(v => Guid.NewGuid()).ToArray(); // shuffle
                    var errSum = 0.0;
                    for (var j = 0; j < ex.Length; ++j)
                    {
                        bp.Train(ex[j].Item1, ex[j].Item2);
                        errSum += bp.Error;
                    }
                    writer.WriteLine("{0},{1}", i, errSum / ex.Length);
                }
            }

            while (true)
            {
                Console.Error.Write("input >");
                var inputs = Console.ReadLine().Split(' ').Select(v => new ConstOutput(double.Parse(v))).ToArray();
                nn.SetInputs(inputs);
                nn.Fire();
                foreach (var o in nn.GetOutputs())
                {
                    Console.WriteLine("{0:0.0########################################################}", o);
                }
            }
        }