Exemplo n.º 1
0
 /// <summary>
 /// Copies all the variables into the given neural network
 /// </summary>
 internal void Copy(NetworkVectors into)
 {
     for (int layer = 1; layer < Dimensions.Count; layer++)
     {
         for (int neuron = 0; neuron < Weights[layer - 1].Count; neuron++)
         {
             for (int connection = 0; connection < Weights[layer - 1][neuron].Length; connection++)
             {
                 into.Weights[layer - 1][neuron][connection] = Weights[layer - 1][neuron][connection];
             }
         }
     }
 }
Exemplo n.º 2
0
        /// <summary>
        /// Save a neural network under a certain name in the program's folder.
        /// </summary>
        public static void SaveSerializable(NetworkVectors net, string NetName)
        {
            string path = NetName + FileExtention;

            try
            {
                Stream saveFile = File.Open(path, FileMode.Create); // Open the save file
                // Serialize and save the file
                BinaryFormatter binaryFormatter = new BinaryFormatter();
                binaryFormatter.Serialize(saveFile, net);
                saveFile.Close();
            }
            catch (Exception e)
            {
                Console.WriteLine("Error saving the serializable object: {0}", e.Message);
            }
        }
Exemplo n.º 3
0
        /// <summary>
        /// Loads a neural network with a specific name from the program's folder
        /// </summary>
        public static NetworkVectors LoadNetworkVectors(string NetName)
        {
            string path = NetName + FileExtention;

            try
            {
                Stream saveFile = File.Open(path, FileMode.Open); // Open the save file
                // Load, deserialize and return the network
                BinaryFormatter binaryFormatter = new BinaryFormatter();
                NetworkVectors  networkVectors  = (NetworkVectors)binaryFormatter.Deserialize(saveFile);
                saveFile.Close();
                return(networkVectors);
            }
            catch
            {
                Console.WriteLine("Error saving the serializable object");
                return(null);
            }
        }