static void Main(string[] args) { if (args.Length == 0) { Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); Application.Run(new SVMApp()); } else { string datasetPath = args[0]; string testPath = args[1]; string outputPath = args[2]; List <Data> dataSets = new List <Data>(); FillDataset(dataSets, datasetPath); var machine = new VectorMachine(new Polynomial(2), 25); var learn = new SequentialOptimization(machine, dataSets.ToArray()); _ = learn.Run(); dataSets.Clear(); List <string> paths = FillDataset(dataSets, testPath); double[] output = machine.Compute(dataSets.ToArray()); using (StreamWriter writer = new StreamWriter(outputPath)) { for (int i = 0; i < output.Length; i++) { writer.WriteLine(paths[i] + ':' + output[i]); } } } }
private void UseBtn_Click(object sender, EventArgs e) { if (!isTrained) { MessageBox.Show("Машина не обучена."); return; } OpenFileDialog openFile = new OpenFileDialog(); openFile.RestoreDirectory = true; if (openFile.ShowDialog() == DialogResult.OK) { using (Bitmap bitmap = new Bitmap(openFile.FileName)) { Data dataset = bitmap.ToDataSet(0); double output = machine.Compute(dataset.InputsSignals); int res = output > 0 ? 1 : 0; MessageBox.Show("Вероятно, это " + res.ToString()); } } }