Пример #1
0
        public bool startRealtimeKNN(string id, string name)
        {
            EmoEngine engine = EmoEngine.Instance;

            engine.UserAdded += new EmoEngine.UserAddedEventHandler(engine_UserAdded_Event);
            engine.FacialExpressionEmoStateUpdated += new EmoEngine.FacialExpressionEmoStateUpdatedEventHandler(engine_FacialExpressionEmoStateUpdated);
            engine.Connect();
            EdkDll.IEE_DataChannel_t[] channelList = new EdkDll.IEE_DataChannel_t[7] {
                EdkDll.IEE_DataChannel_t.IED_AF3, EdkDll.IEE_DataChannel_t.IED_AF4, EdkDll.IEE_DataChannel_t.IED_T7,
                EdkDll.IEE_DataChannel_t.IED_T8, EdkDll.IEE_DataChannel_t.IED_O1, EdkDll.IEE_DataChannel_t.IED_GYROX, EdkDll.IEE_DataChannel_t.IED_GYROY
            };
            bool ready = false;

            ready = knn.buildKNNCorpus(name);
            IntPtr state = new IntPtr(1);
            Thread newThread;
            int    itr = 0;

            double[] alpha     = new double[1];
            double[] low_beta  = new double[1];
            double[] high_beta = new double[1];
            double[] gamma     = new double[1];
            double[] theta     = new double[1];
            double[] data      = new double[25];
            while (ready)
            {
                itr++;
                engine.ProcessEvents(10);

                if (userID < 0)
                {
                    continue;
                }
                for (int i = 0, j = 0; i < 5; i++)
                {
                    engine.IEE_GetAverageBandPowers((uint)userID, channelList[i], theta, alpha, low_beta, high_beta, gamma);
                    data[j++] = theta[0];
                    data[j++] = alpha[0];
                    data[j++] = low_beta[0];
                    data[j++] = high_beta[0];
                    data[j++] = gamma[0];
                }
                if (data[0] != 0 && data[24] != 0)
                {
                    newThread = new Thread(() => Form1.Instance.moveTestObject(knn.knnClassifier(data)));
                    newThread.Start();
                }
                Thread.Sleep(500);
            }
            return(ready);
        }
Пример #2
0
        public bool startRealtimeKNN(string id, string name)
        {
            EmoEngine engine = EmoEngine.Instance;

            engine.UserAdded += new EmoEngine.UserAddedEventHandler(engine_UserAdded_Event);
            engine.Connect();
            EdkDll.IEE_DataChannel_t[] channelList = new EdkDll.IEE_DataChannel_t[5] {
                EdkDll.IEE_DataChannel_t.IED_AF3, EdkDll.IEE_DataChannel_t.IED_AF4, EdkDll.IEE_DataChannel_t.IED_T7,
                EdkDll.IEE_DataChannel_t.IED_T8, EdkDll.IEE_DataChannel_t.IED_O1
            };
            bool ready = false;

            ready = knn.buildCorpusSimple(name);

            IntPtr state = new IntPtr(1);
            Thread newThread;
            int    itr = 0;

            double[] alpha     = new double[1];
            double[] low_beta  = new double[1];
            double[] high_beta = new double[1];
            double[] gamma     = new double[1];
            double[] theta     = new double[1];
            double[] data      = new double[25];
            while (ready)
            {
                itr++;
                //if (EdkDll.IS_FacialExpressionIsLeftWink(state))
                //  MessageBox.Show("Left Eye Wink Detected!");

                //if (EdkDll.IS_FacialExpressionIsRightWink(state))
                // MessageBox.Show("Right Eye Wink Detected!");
                engine.ProcessEvents(10);

                if (userID < 0)
                {
                    continue;
                }
                for (int i = 0, j = 0; i < 5; i++)
                {
                    engine.IEE_GetAverageBandPowers((uint)userID, channelList[i], theta, alpha, low_beta, high_beta, gamma);
                    data[j++] = theta[0];
                    data[j++] = alpha[0];
                    data[j++] = low_beta[0];
                    data[j++] = high_beta[0];
                    data[j++] = gamma[0];
                }
                //up simple data taken form karrarUp.csv
                //
                //data = new double[] { 4.651620563, 5.212359266, 10.90409395, 5.157308481, 4.170539408, 5.10950104, 6.035994062, 12.41738389, 4.743290343, 3.866878481, 2.873242245, 4.77619567, 2.151664297, 1.760807141, 3.082304127, 3.986381183, 10.31494602, 9.029601134, 2.233667016, 2.991145428, 0.244647851, 0.618714049, 0.239897275, 0.36874583, 0.333496459 };
                //data = new double[] { 2.254629381, 1.60659665, 1.328094785, 1.882520841, 1.027082428, 2.57410163, 2.209505082, 1.17652227, 0.9200791, 0.524185866, 2.047865372, 1.76506681, 1.091739745, 0.690766561, 0.820688245, 1.643871005, 5.476966707, 1.084435047, 1.055108772, 0.556177084, 335.9026309, 186.3244237, 140.337729, 67.65089061, 25.64029729 };

                if (data[0] != 0 && data[24] != 0)
                {
                    newThread = new Thread(() => Form1.Instance.moveObject(knn.knnClassifier(data)));
                    newThread.Start();
                    //newThread = new Thread(() => Form1.Instance.moveObject(knn.knnClassifier(pca.testDataPCA(data))));
                }
                Thread.Sleep(2000);
            }
            return(ready);
        }
Пример #3
0
        public double calculateKNNAccuracy()
        {
            if (fileExistance)
            {
                KNN knn = new KNN();

                if (rightTestData != null)
                {
                    knn.setRight(rightTrainData);
                }

                if (leftTestData != null)
                {
                    knn.setLeft(leftTrainData);
                }

                if (upTestData != null)
                {
                    knn.setUp(upTrainData);
                }

                if (downTestData != null)
                {
                    knn.setDown(downTrainData);
                }

                if (neutralTestData != null)
                {
                    knn.setNeutral(neutralTrainData);
                }

                double tp = 0, fp = 0;
                if (rightTestData != null)
                {
                    for (int i = 0; i < rightTestData.Length; i++)
                    {
                        if (knn.knnClassifier(rightTestData[i]) == "Right")
                        {
                            tp++;
                        }
                        else
                        {
                            fp++;
                        }
                    }
                }
                if (leftTestData != null)
                {
                    for (int i = 0; i < leftTestData.Length; i++)
                    {
                        if (knn.knnClassifier(leftTestData[i]) == "Left")
                        {
                            tp++;
                        }
                        else
                        {
                            fp++;
                        }
                    }
                }
                if (upTestData != null)
                {
                    for (int i = 0; i < upTestData.Length; i++)
                    {
                        if (knn.knnClassifier(upTestData[i]) == "Up")
                        {
                            tp++;
                        }
                        else
                        {
                            fp++;
                        }
                    }
                }
                if (downTestData != null)
                {
                    for (int i = 0; i < downTestData.Length; i++)
                    {
                        if (knn.knnClassifier(downTestData[i]) == "Down")
                        {
                            tp++;
                        }
                        else
                        {
                            fp++;
                        }
                    }
                }
                if (neutralTestData != null)
                {
                    for (int i = 0; i < neutralTestData.Length; i++)
                    {
                        if (knn.knnClassifier(neutralTestData[i]) == "Neutral")
                        {
                            tp++;
                        }
                        else
                        {
                            fp++;
                        }
                    }
                }
                double accuracy = (tp / (tp + fp)) * 100;
                return(accuracy);
            }
            else
            {
                return(0);
            }
        }