private void TrainLOOCVNetworks() { m_AllFeaturesForLOOCV = new Dictionary <string, FeatureSet[]>(); try { // Read in each source file and create FeatureSets for (int i = 0; i < m_Source.Count; i++) { toolStripStatusLabel1.Text = "Reading Feature File " + i.ToString() + " of " + m_Source.Count.ToString(); FeatureSet[] sets = FeatureSet.GetFeatureSetsFromFile(m_Source[i]); string str = System.IO.Path.GetFileNameWithoutExtension(m_Source[i]); if (!m_AllFeaturesForLOOCV.ContainsKey(str)) { m_AllFeaturesForLOOCV.Add(str, sets); } if (!m_QueueForLOOCV.Contains(str)) { m_QueueForLOOCV.Enqueue(str); } } } catch (Exception e) { MessageBox.Show(e.Message); return; } try { m_Worker.RunWorkerAsync(m_QueueForLOOCV.Dequeue()); } catch (Exception e) { MessageBox.Show(e.Message); } }
private void buttonTest_Click(object sender, EventArgs e) { // Get the trained networks bool successful; List <string> networkFiles = General.SelectOpenFiles(out successful, "Select the trained networks to use.", "Trained Networks (*.nn)|*.nn"); if (!successful) { MessageBox.Show("Unable to get network filenames"); return; } // Load all the networks from file Dictionary <string, NeuralNetwork> networks = new Dictionary <string, NeuralNetwork>(networkFiles.Count); foreach (string file in networkFiles) { string nameShort = Path.GetFileNameWithoutExtension(file); int start = nameShort.IndexOf("Network") + "Network".Length; string username = nameShort.Substring(start); NeuralNetwork net = NeuralNetwork.LoadNetworkFromFile(file); if (!networks.ContainsKey(username)) { networks.Add(username, net); } else { MessageBox.Show("Unable to load network " + nameShort); } } // Get the filename to save results to bool saveFileSuccess; string saveFilename = General.SelectSaveFile(out saveFileSuccess, "File to save results to", "Text (*.txt)|*.txt"); if (!saveFileSuccess) { MessageBox.Show("Unable to select file to save the results to"); return; } // Run each file through the networks Dictionary <string, NeuralNetworkResults> allResults = new Dictionary <string, NeuralNetworkResults>(networks.Count); foreach (string source in m_Source) { string nameShort = Path.GetFileNameWithoutExtension(source); int start = nameShort.IndexOf("values") + "values".Length + 1; string user = nameShort.Substring(start); if (networks.ContainsKey(user)) { NeuralNetwork net = networks[user]; FeatureSet[] set = FeatureSet.GetFeatureSetsFromFile(source); bool success; NeuralNetworkResults results = net.Evaluate(set, "", out success); if (success) { if (!allResults.ContainsKey(user)) { allResults.Add(user, results); } else { MessageBox.Show("Already added results for user " + user); } } else { MessageBox.Show("Unable to evaluate with user " + user); } } else { MessageBox.Show("User: "******" does not have a definition in 'networks'"); } } StreamWriter writer = new StreamWriter(saveFilename); foreach (KeyValuePair <string, NeuralNetworkResults> entry in allResults) { int[][] matrix = entry.Value.ConfusionMatrix; writer.WriteLine(entry.Key + "," + entry.Value.Accuracy.ToString("#0.000") + "," + matrix[0][0] + "," + matrix[0][1] + "," + matrix[1][0] + "," + matrix[1][1]); /*writer.WriteLine(entry.Key + "," + entry.Value.Accuracy.ToString("#0.000") + ",Confusion Matrix,,Classified As"); * writer.WriteLine(",,,,Different Shape, Same Shape"); * * writer.WriteLine(",,Should Be,Different Shape,{0},{1}", matrix[0][0], matrix[0][1]); * writer.WriteLine(",,,Same Shape,{0},{1}", matrix[1][0], matrix[1][1]); * * writer.WriteLine();*/ } writer.Close(); }