예제 #1
0
        private void LoadTrainingData(IDBLoader loader)
        {
            this.trainingData = new Dictionary<Guid, IRecipeClassification>();

            this.breakfastIndex = new RecipeIndex();
            this.lunchIndex = new RecipeIndex();
            this.dinnerIndex = new RecipeIndex();
            this.dessertIndex = new RecipeIndex();

            var data = loader.LoadTrainingData();

            foreach (var recipeClassification in data)
            {
                this.trainingData.Add(recipeClassification.Recipe.Id, recipeClassification);

                if (recipeClassification.IsBreakfast)
                {
                    this.breakfastIndex.Add(recipeClassification.Recipe);
                }
                if (recipeClassification.IsLunch)
                {
                    this.lunchIndex.Add(recipeClassification.Recipe);
                }
                if (recipeClassification.IsDinner)
                {
                    this.dinnerIndex.Add(recipeClassification.Recipe);
                }
                if (recipeClassification.IsDessert)
                {
                    this.dessertIndex.Add(recipeClassification.Recipe);
                }
            }
        }
예제 #2
0
        private void Compete(Recipe entry, RecipeIndex first, RecipeIndex second, Ranking rankBreakfast, Ranking rankLunch, Ranking rankDinner, Ranking rankDessert)
        {
            var chance = this.GetPrediction(entry, first, second);
            if (chance > 0.5f - Tolerance && chance < 0.5f + Tolerance)
            {
                return; // No winner
            }

            var diff = (float)Math.Abs(chance - 0.5);
            var winner = chance < 0.5 ? second : first;

            if (winner == this.breakfastIndex)
            {
                rankBreakfast.Score += diff;
            }

            if (winner == this.lunchIndex)
            {
                rankLunch.Score += diff;
            }

            if (winner == this.dinnerIndex)
            {
                rankDinner.Score += diff;
            }

            if (winner == this.dessertIndex)
            {
                rankDessert.Score += diff;
            }
        }
예제 #3
0
        private float GetPrediction(Recipe recipe, RecipeIndex first, RecipeIndex second)
        {
            // Reset probability and invertedProbability
            this.invertedProbability = 0;
            this.probability = 0;

            var tokens = Tokenizer.Tokenize(recipe);

            foreach (var token in tokens)
            {
                var firstRITokensCount = first.GetTokenCount(token);
                var secondRITokensCount = second.GetTokenCount(token);

                this.CalcProbability(firstRITokensCount, first.EntryCount, secondRITokensCount, second.EntryCount);
            }

            var prediction = this.probability / (this.probability + this.invertedProbability);
            return prediction;
        }