Exemplo n.º 1
0
        public double MeanCompare(WordData word, List <WordData> wordList)
        {
            double answer = 0;

            int[] timing = new int[word.GetTiming().Length];
            for (int i = 0; i < word.GetTiming().Length; ++i)
            {
                int mean = 0;
                foreach (WordData listWord in wordList)
                {
                    mean += listWord.GetTiming()[i];
                }
                mean     /= wordList.Count;
                timing[i] = mean;
            }
            WordData meanWord = new WordData(word.GetWord(), timing, -1);

            answer = Compare(word, meanWord);
            return(answer);
        }
Exemplo n.º 2
0
        public double MedianCompare(WordData word, List <WordData> wordList)
        {
            double answer = 0;

            int[] timing = new int[word.GetTiming().Length];
            for (int i = 0; i < word.GetTiming().Length; ++i)
            {
                List <int> medianList = new List <int>();
                int        median     = 0;
                foreach (WordData listWord in wordList)
                {
                    medianList.Add(listWord.GetTiming()[i]);
                }
                medianList.Sort();
                median    = medianList[(wordList.Count / 2)];
                timing[i] = median;
            }
            WordData meanWord = new WordData(word.GetWord(), timing, -1);

            answer = Compare(word, meanWord);
            return(answer);
        }
Exemplo n.º 3
0
        private KeyValuePair <int, double> predict(UserClient client)
        {
            KeyValuePair <int, double>         answer;
            List <KeyValuePair <int, double> > answerlist = new List <KeyValuePair <int, double> >(), meanAnswerList = new List <KeyValuePair <int, double> >(),
                                               medianAnswerList = new List <KeyValuePair <int, double> >();
            double          likeness = 0, meanLikeness = 0, medianLikeness = 0;
            List <WordData> predictionData = ToWords(client.GetPredictionData());

            if (predictionData.Count > 0)
            {
                UserDBDataSetWorkerTableAdapters.UserClientTableAdapter userAdapt = new UserDBDataSetWorkerTableAdapters.UserClientTableAdapter();
                UserDBDataSetWorker.UserClientDataTable userTable = userAdapt.GetUserClientData();
                foreach (UserDBDataSetWorker.UserClientRow userRow in userTable)
                {
                    int count = 0;
                    foreach (WordData word in predictionData)
                    {
                        UserDBDataSetWorkerTableAdapters.WordDataTableAdapter wordAdapt = new UserDBDataSetWorkerTableAdapters.WordDataTableAdapter();
                        UserDBDataSetWorker.WordDataDataTable wordTable = wordAdapt.GetDataByUserIDandWord(userRow.UserID, word.GetWord());
                        if (wordTable.Count > 0)
                        {
                            List <WordData> wordList = new List <WordData>();
                            foreach (UserDBDataSetWorker.WordDataRow wordRow in wordTable)
                            {
                                UserDBDataSetWorkerTableAdapters.TimingTableAdapter timeAdapt = new UserDBDataSetWorkerTableAdapters.TimingTableAdapter();
                                UserDBDataSetWorker.TimingDataTable timeTable = timeAdapt.GetDataByWordID(wordRow.WordID);
                                if (timeTable.Count > 0)
                                {
                                    int[] timing = new int[timeTable.Count];
                                    for (int i = 0; i < timeTable.Count; i++)
                                    {
                                        timing[i] = timeTable[i].Timing;
                                    }
                                    WordData learnedWord = new WordData(wordRow.Word, timing, userRow.UserID);
                                    double   comp        = Compare(word, learnedWord);
                                    if (comp > 0)
                                    {
                                        likeness += Compare(word, learnedWord);
                                        count++;
                                    }
                                    wordList.Add(learnedWord);
                                }
                            }
                            if (word.GetTiming().Length > 0)
                            {
                                meanLikeness   = MeanCompare(word, wordList);
                                medianLikeness = MedianCompare(word, wordList);
                            }
                            //meanaverage
                        }
                    }
                    likeness /= count;
                    answerlist.Add(new KeyValuePair <int, double>(userRow.UserID, likeness));
                    meanAnswerList.Add(new KeyValuePair <int, double>(userRow.UserID, meanLikeness));
                    medianAnswerList.Add(new KeyValuePair <int, double>(userRow.UserID, medianLikeness));
                    meanAList   = meanAnswerList;
                    medianAList = medianAnswerList;
                    bool problem;
                    if (likeness > 1)
                    {
                        problem = true;
                    }
                    likeness = 0;
                    count    = 0;
                }
            }
            if (answerlist.Count > 1)
            {
                switch (predictionMode)
                {
                case 0:                            //compare
                    answer = MaxValue(answerlist); //most probable prediction
                    break;

                case 1:                                //mean
                    answer = MaxValue(meanAnswerList); //most probable prediction
                    break;

                default:
                case 2:                                  //median
                    answer = MaxValue(medianAnswerList); //most probable prediction
                    break;
                }
            }
            else
            {
                answer = new KeyValuePair <int, double>(0, 0);
            }
            return(answer);
        }