void TranslateInstance(Frame frame) { // Create a new Linear kernel IKernel kernel = new Linear(); // Create a new Multi-class Support Vector Machine with one input, // using the linear kernel and for four disjoint classes. var machine = new MulticlassSupportVectorMachine(5, kernel, numOfClasses); // Create the Multi-class learning algorithm for the machine var teacher = new MulticlassSupportVectorLearning(machine, inputs, outputs); // Configure the learning algorithm to use SMO to train the // underlying SVMs in each of the binary class subproblems. teacher.Algorithm = (svm, classInputs, classOutputs, i, j) => new SequentialMinimalOptimization(svm, classInputs, classOutputs); // Run the learning algorithm double error = teacher.Run(); // output should be 0 double[] distances = new double[5]; distances = LeapEventListener.getDistances(frame); int decision = machine.Compute(distances); //svm AI output.Text = output.Text + Char2SvmClass.class2svm(decision); }
private void TranslateBtn_Click(object sender, EventArgs e) { double[] distances = new double[5]; distances = LeapEventListener.getDistances(currentFrame); if (LeapEventListener.isZeros(distances) == true) { MessageBox.Show("The frame is null.\n Try reconnecting the Leap device", "Application Error", MessageBoxButtons.OKCancel, MessageBoxIcon.Warning); } else { // Create a new Linear kernel IKernel kernel = new Linear(); // Create a new Multi-class Support Vector Machine with one input, // using the linear kernel and for four disjoint classes. var machine = new MulticlassSupportVectorMachine(5, kernel, numOfClasses); // Create the Multi-class learning algorithm for the machine var teacher = new MulticlassSupportVectorLearning(machine, inputs, outputs); // Configure the learning algorithm to use SMO to train the // underlying SVMs in each of the binary class subproblems. teacher.Algorithm = (svm, classInputs, classOutputs, i, j) => new SequentialMinimalOptimization(svm, classInputs, classOutputs); // Run the learning algorithm double error = teacher.Run(); // output should be 0 int decision = machine.Compute(distances); //svm AI output.Text = output.Text + Char2SvmClass.class2svm(decision); } }
private void InitializeSVM() { // ============================================== Database ============================================== connection = new OleDbConnection(); command = new OleDbCommand(); double thumb, index, middle, ring, pinky; int svmClass = 0; connection.ConnectionString = @"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=|DataDirectory|\SVMdataset.accdb"; command.Connection = connection; string q = "select * from DataSet"; command.CommandText = q; connection.Open(); dr = command.ExecuteReader(); int k = 0; DataTable dt = new DataTable(); dt.Load(dr); outputs = new int[dt.Rows.Count]; inputs = new double[dt.Rows.Count][]; dr = command.ExecuteReader(); if (dr.HasRows) // run over the table and put it on the list { while (dr.Read()) { char c = Convert.ToChar(dr[1]); svmClass = Char2SvmClass.char2class(c);//static method that converts the char to a class ; thumb = Convert.ToDouble(dr[2]); index = Convert.ToDouble(dr[3]); middle = Convert.ToDouble(dr[4]); ring = Convert.ToDouble(dr[5]); pinky = Convert.ToDouble(dr[6]); inputs[k] = new double[] { thumb, index, middle, ring, pinky }; outputs[k] = svmClass; k++; } } connection.Close(); //get from DB the number of classes command.Connection = connection; q = "select Distinct DataSet.Letter from DataSet"; command.CommandText = q; connection.Open(); dr = command.ExecuteReader(); dt = new DataTable(); dt.Load(dr); numOfClasses = dt.Rows.Count; connection.Close(); }