Example #1
0
        public RNA(int capas)
        {
            // Definiendo el tipo de red.
            BackPropNetworkFactory factory = new BackPropNetworkFactory();

            //This is an arralist which holds the number of neurons in each layer
            ArrayList layers = new ArrayList();

            //Cant. de neuronas en la primera capa  (capa de entrada)
            layers.Add(36);

            int i;

            for (i = 0; i < capas; i++)
            {
                //Cant. de capas ocultas
                layers.Add(36);
            }

            //Can. de neuronas en la última capa (capa de salida)
            layers.Add(9);

            //Creo la red a través del patrón factory
            network = factory.CreateNetwork(layers);
        }
Example #2
0
        public Gate()
        {
            BackPropNetworkFactory factory = new BackPropNetworkFactory();

            ArrayList layers = new ArrayList();

            layers.Add(16);
            layers.Add(16);
            layers.Add(16);
            layers.Add(10);

            Network = factory.CreateNetwork(layers);
        }
Example #3
0
        public static void Demo1()
        {
            INeuralNetwork nn = new BackPropNetworkFactory().CreateNetwork(new ArrayList(new double[] { 2, 2, 1 }));//instantiate 2-2-1 neural network

            TrainingData[] xordata = new TrainingData[] {
                new TrainingData(new ArrayList(new double[] { 0, 0 }), new ArrayList(new double[] { 0 })),
                new TrainingData(new ArrayList(new double[] { 0, 1 }), new ArrayList(new double[] { 1 })),
                new TrainingData(new ArrayList(new double[] { 1, 0 }), new ArrayList(new double[] { 1 })),
                new TrainingData(new ArrayList(new double[] { 1, 1 }), new ArrayList(new double[] { 0 }))
            }; //the xor table

            Console.WriteLine("Training the network:");
            for (int i = 0; i < 5000; i++)
            {
                foreach (TrainingData data in xordata)
                {
                    nn.TrainNetwork(data);
                }
                drawpbar(i + 1, 5000);
            }

            bool done = false;

            while (!done)
            {
                Console.WriteLine("Enter two inputs (on new lines) for the neural network! Just press enter once you are done!");
                string input = Console.ReadLine();
                if (input == "")
                {
                    done = true;
                    break;
                }
                else
                {
                    try
                    {
                        double i1 = Double.Parse(input);
                        double i2 = Double.Parse(Console.ReadLine());
                        Console.WriteLine("Output: " + String.Join(" ", nn.RunNetwork(new ArrayList(new double[] { i1, i2 }))[0]));
                    }
                    catch (Exception e)
                    {
                        Console.WriteLine("There was an error: " + Environment.NewLine + e);
                    }
                }
            }
        }
Example #4
0
        public RNA()
        {
            BackPropNetworkFactory factory = new BackPropNetworkFactory();

            //This is an arralist which holds the number of neurons in each layer
            ArrayList layers = new ArrayList();

            //Cant. de neuronas en la primera capa  (capa de entrada)
            layers.Add(36);
            //Cant. de neuronas en la primera capa
            layers.Add(36);
            //Can. de neuronas en la última capa (capa de salida)
            layers.Add(9);

            //Creo la red a través del patrón factory
            network = factory.CreateNetwork(layers);
        }
Example #5
0
        public RNA()
        {
            BackPropNetworkFactory factory = new BackPropNetworkFactory();

            //This is an arralist which holds the number of neurons in each layer
            ArrayList layers = new ArrayList();

            //Cant. de neuronas en la primera capa  (capa de entrada)
            layers.Add(36);
            //Cant. de neuronas en la capa oculta
            layers.Add(36);
            //Can. de neuronas en la última capa (capa de salida)
            layers.Add(9);

            //Creo la red a través del patrón factory
            network = factory.CreateNetwork(layers);

            //Inicializamos el archivo para guardar las variaciones de Delta y Bias en cada iteracion.
            this.initializeLogFiles();
        }
        /// <summary>
        /// Initialize our network for a pixel picture
        /// </summary>
        public void InitNetwork(Size size)
        {
            // Example: We are analyzing a 20x20 pixel picture, so let us take the number
            // of total inputs as 20 x 20 = 400 neurons

            // So let us initialize a 400-400-1 network. I.e, 400 neurons in
            // input layer, 400 neurons in hidden layer and 1 neuron in the output
            // layer to represent a boolean value

            // the factory creates a Backward Propagation Neural Network
            BackPropNetworkFactory factory = new BackPropNetworkFactory();

            // the arrayList holds the number of neurons in each layer
            ArrayList layers = new ArrayList();

            // 400 neurons in first layer
            layers.Add(size.Width * size.Height);
            // 400 neurons in the second layer (the second layer is the first hidden layer)
            layers.Add(size.Width * size.Height);
            // 1 neurons in the output layer
            layers.Add(1);

            // provide the arrayList as the parameter, to create a network
            _network = factory.CreateNetwork(layers);

            _networkInitialized = DateTime.Now;
            TotalTrainingRounds.Reset();
        }