Пример #1
0
 // neuro
 public void Reset()
 {
     if (File.Exists(filePath))
     {
         Perceptron old = Load(filePath);
         old.weights.CopyTo(weights, 0);
     }
     else
     {
         Construct(true);
     }
 }
Пример #2
0
        public static Perceptron Load(string dataFilePath)
        {
            // deserialize
            FileStream      stream     = File.OpenRead(dataFilePath);
            BinaryFormatter formatter  = new BinaryFormatter();
            Perceptron      perceptron = (Perceptron)formatter.Deserialize(stream);

            stream.Close();

            // init weights
            perceptron.weights = new Matrix <double> [perceptron.weightsSeries.Length];
            for (int i = 0; i < perceptron.weights.Length; i++)
            {
                perceptron.weights[i] = CreateMatrix.DenseOfArray(perceptron.weightsSeries[i]);
            }
            return(perceptron);
        }
Пример #3
0
        // utils
        public static void Save(string dataFilePath, Perceptron perceptron)
        {
            // prepare weights
            perceptron.weightsSeries = new double[perceptron.weights.Length][, ];
            for (int i = 0; i < perceptron.weights.Length; i++)
            {
                perceptron.weightsSeries[i] = perceptron.weights[i].ToArray();
            }

            // serialize
            FileStream      stream    = File.OpenWrite(dataFilePath);
            BinaryFormatter formatter = new BinaryFormatter();

            formatter.Serialize(stream, perceptron);
            stream.Flush();
            stream.Close();
        }