示例#1
0
        // ANN constructor. Input and Hidden layers contain the same number of neurons.
        public ANN(int inputnum, int layernum, int neuronnum, int outputnum,
                   double threshold, double lr, Random rand)
        {
            InputNum  = inputnum;
            LayerNum  = layernum;
            NeuronNum = neuronnum;
            OutputNum = outputnum;
            LR        = lr;
            Threshold = threshold;
            rnd       = rand;
            // creating the network
            Network = new ANNLayer[LayerNum];
            // creating the input layer
            Network[0] = new ANNLayer(NeuronNum, InputNum, Threshold, LR);
            // assigning random weights
            for (int j = 0; j < NeuronNum; j++)
            {
                for (int k = 0; k < InputNum; k++)
                {
                    int sign = (rnd.Next(101) < 50) ? -1 : 1;
                    Network[0].Neurons[j].Weights[k] = sign * rnd.NextDouble();
                }
            }
            // creating hidden layers
            int i;

            for (i = 1; i < LayerNum - 1; i++)
            {
                Network[i] = new ANNLayer(NeuronNum, NeuronNum, Threshold, LR);
                // assigning random weights
                for (int j = 0; j < NeuronNum; j++)
                {
                    for (int k = 0; k < NeuronNum; k++)
                    {
                        int sign = (rnd.Next(101) < 50) ? -1 : 1;
                        Network[i].Neurons[j].Weights[k] = sign * rnd.NextDouble();
                    }
                }
            }
            // creating the output layer
            Network[LayerNum - 1] = new ANNLayer(OutputNum, NeuronNum, Threshold, LR);
            // assigning random weights
            for (int j = 0; j < OutputNum; j++)
            {
                for (int k = 0; k < NeuronNum; k++)
                {
                    Network[LayerNum - 1].Neurons[j].Weights[k] = rnd.NextDouble();
                }
            }
        }
 // ANN constructor. Input and Hidden layers contain the same number of neurons.
 public ANN(int inputnum, int layernum, int neuronnum, int outputnum,
             double threshold, double lr, Random rand)
 {
     InputNum = inputnum;
     LayerNum = layernum;
     NeuronNum = neuronnum;
     OutputNum = outputnum;
     LR = lr;
     Threshold = threshold;
     rnd = rand;
     // creating the network
     Network = new ANNLayer[LayerNum];
     // creating the input layer
     Network[0] = new ANNLayer(NeuronNum, InputNum, Threshold, LR);
     // assigning random weights
     for (int j = 0; j < NeuronNum; j++)
         for (int k = 0; k < InputNum; k++)
         {
             int sign = (rnd.Next(101) < 50) ? -1 : 1;
             Network[0].Neurons[j].Weights[k] = sign*rnd.NextDouble();
         }
     // creating hidden layers
     int i;
     for (i = 1; i < LayerNum - 1; i++)
     {
         Network[i] = new ANNLayer(NeuronNum, NeuronNum, Threshold, LR);
         // assigning random weights
         for (int j = 0; j < NeuronNum; j++)
             for (int k = 0; k < NeuronNum; k++)
             {
                 int sign = (rnd.Next(101) < 50) ? -1 : 1;
                 Network[i].Neurons[j].Weights[k] = sign * rnd.NextDouble();
             }
     }
     // creating the output layer
     Network[LayerNum - 1] = new ANNLayer(OutputNum, NeuronNum, Threshold, LR);
     // assigning random weights
     for (int j = 0; j < OutputNum; j++)
         for (int k = 0; k < NeuronNum; k++)
             Network[LayerNum - 1].Neurons[j].Weights[k] = rnd.NextDouble();
 }