public void Train_RuningTraining_NetworkIsTrained()
        {
            var network = new SimpleNeuralNetwork(3);

            var layerFactory = new NeuralLayerFactory();

            network.AddLayer(layerFactory.CreateNeuralLayer(3, new RectifiedActivationFuncion(), new WeightedSumFunction()));
            network.AddLayer(layerFactory.CreateNeuralLayer(1, new SigmoidActivationFunction(0.7), new WeightedSumFunction()));

            network.PushExpectedValues(
                new double[][] {
                new double[] { 0 },
                new double[] { 1 },
                new double[] { 1 },
                new double[] { 0 },
                new double[] { 1 },
                new double[] { 0 },
                new double[] { 0 },
            });

            network.Train(
                new double[][] {
                new double[] { 150, 2, 0 },
                new double[] { 1002, 56, 1 },
                new double[] { 1060, 59, 1 },
                new double[] { 200, 3, 0 },
                new double[] { 300, 3, 1 },
                new double[] { 120, 1, 0 },
                new double[] { 80, 1, 0 },
            }, 10000);

            network.PushInputValues(new double[] { 1054, 54, 1 });
            var outputs = network.GetOutput();
        }
Ejemplo n.º 2
0
        public AgentSmith()
        {
            _network = new SimpleNeuralNetwork(11);
            var layerFactory = new NeuralLayerFactory();

            _network.AddLayer(layerFactory.CreateNeuralLayer(10, new RectifiedActivationFuncion(), new WeightedSumFunction()));
            _network.AddLayer(layerFactory.CreateNeuralLayer(1, new SigmoidActivationFunction(1), new WeightedSumFunction()));
        }
Ejemplo n.º 3
0
    public void NeuralNetworkInitializer()
    {
        var layerFactory = new NeuralLayerFactory();

        network.AddLayer(layerFactory.CreateNeuralLayer(5, weights.Take(10).ToArray(), new StepActivationFunction(0.5),
                                                        new WeightedSumFunction()));
        network.AddLayer(layerFactory.CreateNeuralLayer(1, weights.Skip(10).Take(5).ToArray(), new StepActivationFunction(0.5), //
                                                        new WeightedSumFunction()));
    }
Ejemplo n.º 4
0
        public void CreateNeuralLayer_NumberOfNeuronsPasses_CorrectLayerCreated()
        {
            var neuralLayerFactory = new NeuralLayerFactory();
            var neuralLayer        = neuralLayerFactory.CreateNeuralLayer(11, new StepActivationFunction(0.5), new WeightedSumFunction());

            Assert.AreEqual(11, neuralLayer.Neurons.Count);
        }
Ejemplo n.º 5
0
        private void CreateInputLayer(int inputNeurons)
        {
            var inputLayer = _layerFactory.CreateNeuralLayer(inputNeurons, new RectifiedActivationFunction(), new WeightedSumFunction());

            inputLayer.Neurons.ForEach(x => x.AddInputSynapse(0));
            this.AddLayer(inputLayer);
        }
        public void AddLayer_NeuralAddingNewLayer_LayerAdded()
        {
            var network      = new SimpleNeuralNetwork(3);
            var layerFactory = new NeuralLayerFactory();

            network.AddLayer(layerFactory.CreateNeuralLayer(3, new RectifiedActivationFuncion(), new WeightedSumFunction()));

            Assert.AreEqual(2, network._layers.Count);
        }
Ejemplo n.º 7
0
        static void Main(string[] args)
        {
            Console.WriteLine("START");
            var network = new SimpleNeuralNetwork(3);

            var layerFactory = new NeuralLayerFactory();

            network.AddLayer(layerFactory.CreateNeuralLayer(3, new RectifiedActivationFunction(), new WeightedSumFunction()));
            network.AddLayer(layerFactory.CreateNeuralLayer(1, new SigmoidActivationFunction(0.7), new WeightedSumFunction()));

            network.PushExpectedValues(
                new double[][]
            {
                new double[] { 0 },
                new double[] { 1 },
                new double[] { 1 },
                new double[] { 0 },
                new double[] { 1 },
                new double[] { 0 },
                new double[] { 0 },
            });

            Console.WriteLine("TRAINING NETWORK");
            network.Train(
                new double[][]
            {
                new double[] { 150, 2, 0 },
                new double[] { 1002, 56, 1 },
                new double[] { 1002, 59, 1 },
                new double[] { 200, 3, 0 },
                new double[] { 300, 2, 1 },
                new double[] { 120, 1, 0 },
                new double[] { 80, 1, 0 },
            }, 10000);

            network.PushInputValues(new double[] { 1054, 54, 1 });
            var outputs = network.GetOutput();

            Console.WriteLine("OUTPUT");
            outputs.ForEach(x => Console.WriteLine(x));

            Console.WriteLine("DONE");
            Console.ReadLine();
        }
        public void AddLayer_NeuralAddingNewLayer_LayerAdded()
        {
            var network      = new SimpleNeuralNetwork(6);
            var layerFactory = new NeuralLayerFactory();

            network.PushInputValues(new double[] { 23, 565, 789, 3, 90, 23 });
            network.AddLayer(layerFactory.CreateNeuralLayer(3, new RectifiedActivationFuncion(), new WeightedSumFunction()));

            Assert.AreEqual(2, network._layers.Count);
            Console.WriteLine(JsonConvert.SerializeObject(network, Formatting.Indented));
        }
    /// <summary>
    /// Helper function that creates input layer of the neural network.
    /// </summary>
    private void CreateInputLayer(int numberOfInputNeurons)
    {
        double[] weights = new double[numberOfInputNeurons];
        weights.ToList().ForEach(x => x = DEFAULT_INPUTS_WEIGHT);

        var inputLayer = _layerFactory.CreateNeuralLayer(numberOfInputNeurons,
                                                         weights, new WithoutActivationFunction(), new WeightedSumFunction());

        inputLayer.Neurons.ForEach(x => x.AddInputSynapse(0));
        this.AddLayer(inputLayer);
    }
Ejemplo n.º 10
0
        static void Main(string[] args)
        {
            var network = new SimpleNeuralNetwork(1);

            var layerFactory = new NeuralLayerFactory();

            network.AddLayer(layerFactory.CreateNeuralLayer(2, new RectifiedActivationFuncion(), new WeightedSumFunction()));

            network.AddLayer(layerFactory.CreateNeuralLayer(1, new SigmoidActivationFunction(0.4), new WeightedSumFunction()));

            double[][] expectedValues = new double[samples][];
            double[][] trainingValues = new double[samples][];

            for (int i = 0; i < samples; i++)
            {
                Random rng  = new Random();
                Random rng2 = new Random();

                int val1 = rng.Next(rng.Next() % 1000);
                int val2 = rng2.Next(i % 900);

                expectedValues[i] = new double[] { (val1 + val2) % 2 };
                trainingValues[i] = new double[] { val1, val2 };
                Console.WriteLine($"val1: {val1} val2: {val2} sum: { (val1 + val2) % 2 }");
            }

            network.PushExpectedValues(expectedValues);



            network.Train(trainingValues, 5000);



            network.PushInputValues(new double[] { 1054, 54 });
            var outputs = network.GetOutput();

            Console.WriteLine($"network output: {string.Join(", ", outputs)}");
            Console.ReadKey();
        }
        public void TrainNetwork_6Inputs_3HiddenLayer_2Outputs()
        {
            var network      = new SimpleNeuralNetwork(6, 1.95); // six input nuerons
            var layerFactory = new NeuralLayerFactory();

            network.AddLayer(layerFactory.CreateNeuralLayer(3, new SigmoidActivationFunction(0.7), new WeightedSumFunction())); // three hidden layers
            network.AddLayer(layerFactory.CreateNeuralLayer(2, new LazyOutputFunction(), new WeightedSumFunction()));           // two output layers
            network.PushExpectedValues(
                new double[][] {
                new double[] { 0.25, 0.20 },
                new double[] { 0.10, 0.05 },
                new double[] { 0.16, 0.30 },
                new double[] { 0.30, 0.10 },
                new double[] { 0.25, 0.20 },
                new double[] { 0.10, 0.05 },
                new double[] { 0.16, 0.30 },
                new double[] { 0.30, 0.10 },
            });
            network.Train(
                new double[][] {
                new double[] { 150, 0, 0, 34, 35, 56 },
                new double[] { 190, 23, 56, 0, 29, 529 },
                new double[] { 290, 3, 108, 24, 189, 20 },
                new double[] { 290, 67, 6, 0, 1, 0 },
                new double[] { 150, 0, 0, 34, 35, 56 },
                new double[] { 190, 23, 56, 0, 29, 529 },
                new double[] { 290, 3, 108, 24, 189, 20 },
                new double[] { 290, 67, 6, 0, 1, 0 },
            }, 10000);

            network.PushInputValues(new double[] { 150, 0, 0, 34, 35, 56 });

            var outputs = network.GetOutput();

            Console.WriteLine(outputs[0].ToString() + " " + outputs[1].ToString() + "\n\n" + JsonConvert.SerializeObject(network, Formatting.Indented));
        }
Ejemplo n.º 12
0
        static void Main(string[] args)
        {
            var network      = new NeuralNetwork(3);
            var layerFactory = new NeuralLayerFactory();

            network.AddLayer(layerFactory.CreateNeuralLayer(3, new RectifiedActivationFuncion(), new WeightedSumFunction()));

            //network.AddLayer(layerFactory.CreateNeuralLayer(3, new RectifiedActivationFuncion(), new WeightedSumFunction()));

            network.AddLayer(layerFactory.CreateNeuralLayer(1, new SigmoidActivationFunction(0.7), new WeightedSumFunction()));

/*            network.PushExpectedValues(
 *              new double[][] {
 *                  new double[] { 0 },
 *                  new double[] { 1 },
 *                  new double[] { 1 },
 *                  new double[] { 0 },
 *                  new double[] { 1 },
 *                  new double[] { 0 },
 *                  new double[] { 0 },
 *              });
 *
 *          network.Train(
 *              new double[][] {
 *                  new double[] { 150, 2, 0 },
 *                  new double[] { 1002, 56, 1 },
 *                  new double[] { 1060, 59, 1 },
 *                  new double[] { 200, 3, 0 },
 *                  new double[] { 300, 3, 1 },
 *                  new double[] { 120, 1, 0 },
 *                  new double[] { 80, 1, 0 },
 *              }, 10000);
 *
 *          network.PushInputValues(new double[] { 1054, 54, 1 });
 *          var outputs = network.GetOutput(); */
        }