Exemplo n.º 1
0
        // loading the network from the computer memory.
        public void Load(neuralnetwork data)
        {
            for (int i = 0; i < entryLevel.Length; i++)
            {
                for (int z = 0; z < entryLevel[i].Weights.Length; z++)
                {
                    entryLevel[i].Weights[z] = data.entryLevel[i].Weights[z];
                }
                entryLevel[i].bias = data.entryLevel[i].bias;
            }
            for (int i = 0; i < numOfneuronsRows; i++)
            {
                for (int j = 0; j < length; j++)
                {
                    for (int z = 0; z < neurons[i, j].Weights.Length; z++)
                    {
                        neurons[i, j].Weights[z] = data.neurons[i, j].Weights[z];
                    }

                    neurons[i, j].bias = data.neurons[i, j].bias;
                }
            }
            for (int i = 0; i < outputLevel.Length; i++)
            {
                for (int z = 0; z < outputLevel[i].Weights.Length; z++)
                {
                    outputLevel[i].Weights[z] = data.outputLevel[i].Weights[z];
                }
                outputLevel[i].bias = data.outputLevel[i].bias;
            }
        }
Exemplo n.º 2
0
        public void AIPrep(snake[] snakes)
        {
            IsAI         = true;
            XsnakesHeads = new double[snakes.Length];
            YsnakesHeads = new double[snakes.Length];

            nn = new neuralnetwork(numOfneuronsRows, length, inputLength, outputLength);
        }
Exemplo n.º 3
0
        // saving the network to the computer memory.
        public void Save(string x)
        {
            BinaryFormatter bf = new BinaryFormatter();
            int             y  = 0;
            FileStream      file;

            if (File.Exists(x + length + "_" + (numOfneuronsRows) + "_" + y))
            {
                while (File.Exists(x + length + "_" + (numOfneuronsRows) + "_" + y))
                {
                    y++;
                }
                file = File.Create(x + length + "_" + (numOfneuronsRows) + "_" + y);
            }
            else
            {
                file = File.Create(x + length + "_" + (numOfneuronsRows) + "_" + 0);
            }
            //  "c:\\4inRow\\_neuralnetwork.dat"
            neuralnetwork data = new neuralnetwork(numOfneuronsRows, length, entryLevel.Length, outputLength);

            for (int i = 0; i < entryLevel.Length; i++)
            {
                for (int z = 0; z < entryLevel[i].Weights.Length; z++)
                {
                    data.entryLevel[i].Weights[z] = entryLevel[i].Weights[z];
                }
                data.entryLevel[i].bias = entryLevel[i].bias;
            }
            for (int i = 0; i < numOfneuronsRows; i++)
            {
                for (int j = 0; j < length; j++)
                {
                    for (int z = 0; z < neurons[i, j].Weights.Length; z++)
                    {
                        data.neurons[i, j].Weights[z] = neurons[i, j].Weights[z];
                    }

                    data.neurons[i, j].bias = neurons[i, j].bias;
                }
            }
            for (int i = 0; i < outputLevel.Length; i++)
            {
                for (int z = 0; z < outputLevel[i].Weights.Length; z++)
                {
                    data.outputLevel[i].Weights[z] = outputLevel[i].Weights[z];
                }
                data.outputLevel[i].bias = outputLevel[i].bias;
            }

            data.score = score;

            bf.Serialize(file, data);
            file.Close();
        }
Exemplo n.º 4
0
 // loading a network from a given network (duplicating the given network into this network).
 public void Load(int fileNum, string x)
 {
     if (File.Exists(x + length + "_" + (numOfneuronsRows) + "_" + fileNum))
     {
         BinaryFormatter bf   = new BinaryFormatter();
         FileStream      file = File.Open(x + length + "_" + (numOfneuronsRows) + "_" + fileNum, FileMode.Open);
         neuralnetwork   data = (neuralnetwork)bf.Deserialize(file);
         file.Close();
         for (int i = 0; i < entryLevel.Length; i++)
         {
             for (int z = 0; z < entryLevel[i].Weights.Length; z++)
             {
                 entryLevel[i].Weights[z] = data.entryLevel[i].Weights[z];
             }
             entryLevel[i].bias = data.entryLevel[i].bias;
         }
         for (int i = 0; i < numOfneuronsRows; i++)
         {
             for (int j = 0; j < length; j++)
             {
                 for (int z = 0; z < neurons[i, j].Weights.Length; z++)
                 {
                     neurons[i, j].Weights[z] = data.neurons[i, j].Weights[z];
                 }
                 neurons[i, j].bias = data.neurons[i, j].bias;
             }
         }
         for (int i = 0; i < outputLevel.Length; i++)
         {
             for (int z = 0; z < outputLevel[i].Weights.Length; z++)
             {
                 outputLevel[i].Weights[z] = data.outputLevel[i].Weights[z];
             }
             outputLevel[i].bias = data.outputLevel[i].bias;
         }
     }
 }
Exemplo n.º 5
0
 public void Load(neuralnetwork nn2)
 {
     nn.Load(nn2);
 }