// 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; } }
public void AIPrep(snake[] snakes) { IsAI = true; XsnakesHeads = new double[snakes.Length]; YsnakesHeads = new double[snakes.Length]; nn = new neuralnetwork(numOfneuronsRows, length, inputLength, outputLength); }
// 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(); }
// 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; } } }
public void Load(neuralnetwork nn2) { nn.Load(nn2); }