/// <summary> /// Deserializes the network form save.xml /// </summary> private void DeserializeNetwork() { if (File.Exists(Directory.GetCurrentDirectory() + "\\save.xml")) { try { XmlSerializer serializer = new XmlSerializer(typeof(BayesainNetwork)); using (Stream stream = new FileStream("save.xml", FileMode.Open)) using (XmlReader reader = new XmlTextReader(stream)) { this.m_Network = (BayesainNetwork)serializer.Deserialize(reader); } } catch { Console.Clear(); Console.WriteLine(@"File not found. Starting training instead"); this.StartTraining(); } } else { Console.Clear(); Console.WriteLine(@"File not found. Starting training instead"); this.StartTraining(); } }
/// <summary> /// Starts the training process upon completion serializes the network and starts the classification process /// </summary> public void StartTraining() { this.m_SerializerBackgroundWorker = new BackgroundWorker(); this.m_SerializerBackgroundWorker.DoWork += this.SerializeNetworkAsync; this.m_Network = null; this.m_Network = new BayesainNetwork(); //Actually start training this.m_Network.StartTraining(); //Serialize network this.m_SerializerBackgroundWorker.RunWorkerAsync(); Console.Clear(); Console.WriteLine(@"Continuing to Classification"); Console.ReadKey(); //Continue to classification this.ClassifyDocument(); }