Example #1
0
        public NeuralNetwork(int inputSize, int hiddenLayersSize, int outputSize,
            int hiddenLayersCount, iActivationFunction f)
        {
            // tworzenie odpowiednich warstw...

                  inputLayer = new NeuralNetworkLayer(inputSize, f); //****
                  outputLayer = new NeuralNetworkLayer(outputSize, f);
                  hiddenLayers = new NeuralNetworkLayer[hiddenLayersCount];

                  for (int i=0; i<hiddenLayersCount; i++)
                    { hiddenLayers[i] = new NeuralNetworkLayer(hiddenLayersSize, f); }

                  // ...i laczenie ich ze soba.

                  //wyjsciowej z ukrytymi
                  outputLayer.AttachToLayer(hiddenLayers[hiddenLayersCount-1]);

                  //ukrytych ze sob¹
                  for (int i=(hiddenLayersCount-1); i>0; i--)

                  {
                        hiddenLayers[i].AttachToLayer(hiddenLayers[i-1]);
                  }

                  //ukrytych z wejœciow¹
                  hiddenLayers[0].AttachToLayer(inputLayer);
        }
Example #2
0
        /// <summary>
        /// initialise neural network
        /// </summary>
        /// <param name="NumberOfInputs">the number of input vectors</param>
        /// <param name="LayerVectorDescription">description of hidden layers</param>
        /// <param name="ActivationFunction">the activation function (default sigmoid)</param>
        /// <param name="Learner">Learning algorithm (default: backpropagation)</param>
        public NeuralNetwork(int NumberOfInputs, int[] LayerVectorDescription, iActivationFunction ActivationFunction = null, LearningAlgorithm Learner = null)
        {
            if (LayerVectorDescription.Length < 1)
            {
                throw new Exception("NeuralNetwork -> cannot be built, since there are no neurons");
            }
            if (NumberOfInputs < 1)
            {
                throw new Exception("NeuralNetwork -> cannot be built, since it need at least 1 input");
            }

            ProtectedNumberOfInputs = NumberOfInputs;
            if (Learner != null)
            {
                TeacherAlgorithm = Learner;
            }
            else
            {
                TeacherAlgorithm = new BackPropagationLearningAlgorithm(this);
            }

            NetworkLayers    = new Layer[LayerVectorDescription.Length];
            NetworkLayers[0] = new Layer(LayerVectorDescription[0], ProtectedNumberOfInputs);
            for (int i = 1; i < LayerVectorDescription.Length; i++)
            {
                NetworkLayers[i] = new Layer(LayerVectorDescription[i], LayerVectorDescription[i - 1], ActivationFunction);
            }
        }
        public NeuralNetworkLayer(int NeuronCount, iActivationFunction f)
        {
            Neurons = new ArrayList();

            for (int i=0; i<NeuronCount; i++)
             { AddNeuron(new Neuron(f)); }
        }
Example #4
0
 /// <summary>
 /// initialise a layer containing x inputs and n neurons
 /// </summary>
 /// <param name="NumberOfInputs">how many inputs do we have</param>
 /// <param name="NumberOfNeurons">how many neurons should this layer contain</param>
 /// <param name="f">activation function foreach neuron in this layer</param>
 public Layer(int NumberOfInputs, int NumberOfNeurons, iActivationFunction f=null)
 {
     _neurons_in_layer = NumberOfInputs;
     _inputs_of_layer = NumberOfNeurons;
     this._neurons = new Neuron[_neurons_in_layer];
     _output = new float[_neurons_in_layer];
     for (int i = 0; i < NumberOfInputs; i++)
         this._neurons[i] = new Neuron(NumberOfNeurons, f);
 }
Example #5
0
 /// <summary>
 /// initialise a layer containing x inputs and n neurons
 /// </summary>
 /// <param name="NumberOfInputs">how many inputs do we have</param>
 /// <param name="NumberOfNeurons">how many neurons should this layer contain</param>
 /// <param name="f">activation function foreach neuron in this layer</param>
 public Layer(int NumberOfInputs, int NumberOfNeurons, iActivationFunction f = null)
 {
     _neurons_in_layer = NumberOfInputs;
     _inputs_of_layer  = NumberOfNeurons;
     this._neurons     = new Neuron[_neurons_in_layer];
     _output           = new float[_neurons_in_layer];
     for (int i = 0; i < NumberOfInputs; i++)
     {
         this._neurons[i] = new Neuron(NumberOfNeurons, f);
     }
 }
Example #6
0
        public Neuron(iActivationFunction f)
        {
            Error        = 0.0;

            Output     = 0.0;

            Inputs     = new ArrayList();

            Function     = f;

            BiasWeight   = 0.0;
        }
Example #7
0
 /// <summary>
 /// initialise the neuron
 /// </summary>
 /// <param name="NumberOfInputs">number of inputs in layer before</param>
 /// <param name="ActivationFunction">activation function for current neuron (default: sigmoid function)</param>
 public Neuron(int NumberOfInputs, iActivationFunction ActivationFunction = null)
 {
     _remember_weight = new float[NumberOfInputs];
     _weight          = new float[NumberOfInputs];
     if (ActivationFunction != null)
     {
         _f = ActivationFunction;
     }
     else
     {
         _f = new SigmoidActivationFunction();
     }
 }
Example #8
0
        /// <summary>
        /// initialise neural network
        /// </summary>
        /// <param name="NumberOfInputs">the number of input vectors</param>
        /// <param name="LayerVectorDescription">description of hidden layers</param>
        /// <param name="ActivationFunction">the activation function (default sigmoid)</param>
        /// <param name="Learner">Learning algorithm (default: backpropagation)</param>
        public NeuralNetwork(int NumberOfInputs, int[] LayerVectorDescription, iActivationFunction ActivationFunction=null, LearningAlgorithm Learner=null)
        {
            if (LayerVectorDescription.Length < 1)
                throw new Exception("NeuralNetwork -> cannot be built, since there are no neurons");
            if (NumberOfInputs < 1)
                throw new Exception("NeuralNetwork -> cannot be built, since it need at least 1 input");

            ProtectedNumberOfInputs = NumberOfInputs;
            if (Learner != null)
                TeacherAlgorithm = Learner;
            else
                TeacherAlgorithm = new BackPropagationLearningAlgorithm(this);

            NetworkLayers = new Layer[LayerVectorDescription.Length];
            NetworkLayers[0] = new Layer(LayerVectorDescription[0], ProtectedNumberOfInputs);
            for (int i = 1; i < LayerVectorDescription.Length; i++)
                NetworkLayers[i] = new Layer(LayerVectorDescription[i], LayerVectorDescription[i - 1], ActivationFunction);
        }
Example #9
0
        //train point in certain viewport (generate training set and train neural network)
        private void trainPoint(BaseTypes.viewport vprt,Bitmap bmp, ref NeuralNetwork Ann, int hls, int ovs, int hlc, iActivationFunction af, double tr, int tic, int miw, int maw)
        {
            trainingSet=new ArrayList();

            switch (vprt)
            {

                case BaseTypes.viewport.XY:
                {
                    trainingSet=(ArrayList)(generateTrainingSet(BaseTypes.viewport.XY,bmp).Clone());
                    //create new neural network object
                    Ann =  new NeuralNetwork((int)Math.Pow((xyRadius*2),2),hls, ovs,hlc,af);
                    //initialize weights
                    Ann.DrawWeights(miw, maw);
                    //train network
                    trainNetwork(trainingSet,ref Ann,tr,tic);
                    break;
                }
                case BaseTypes.viewport.XZ:
                {
                    trainingSet=(ArrayList)(generateTrainingSet(BaseTypes.viewport.XZ,bmp).Clone());
                    //create new neural network object
                    Ann =  new NeuralNetwork((int)Math.Pow((xzRadius*2),2),hls, ovs,hlc,af);
                    //initialize weights
                    Ann.DrawWeights(miw, maw);
                    //train network
                    trainNetwork(trainingSet,ref Ann,tr,tic);
                    break;
                }
                case BaseTypes.viewport.YZ:
                {
                    trainingSet=(ArrayList)(generateTrainingSet(BaseTypes.viewport.YZ,bmp).Clone());
                    //create new neural network object
                    Ann =  new NeuralNetwork((int)Math.Pow((yzRadius*2),2),hls, ovs,hlc,af);
                    //initialize weights
                    Ann.DrawWeights(miw, maw);
                    //train network
                    trainNetwork(trainingSet,ref Ann,tr,tic);
                    break;
                }
            }
        }