예제 #1
0
        private Queue <string> GenerateActions(string[] disabledActions)
        {
            allActions.Clear();

            #region Create a list of all possible actions

            ItemProb <string>[] items =
            {
                ItemProb(ActionsEnum.MakeSuggestion,               ProbVariables.Bot.PrMakeSuggestion[(int)PV.Current]),

                ItemProb(ActionsEnum.AskUncertanFactQuestion,      ProbVariables.Bot.PrAskUncertanFactQuestion),

                ItemProb(ActionsEnum.AskPureFactQuestionAboutUser, ProbVariables.Bot.PrAskPureFactQuestionAboutUser[(int)PV.Current]), //to be packed as one

                ItemProb(ActionsEnum.SharePureFactInfoAboutBot,    ProbVariables.Bot.PrSharePureFactInfoAboutBot[(int)PV.Current]),    //to be packed as one

                ItemProb(ActionsEnum.ChangeVisualAppearance,       SharedHelper.GetProb(ProbVariables.Bot.ChangeVisualAppearance)),

                ItemProb(ActionsEnum.ExpressMentalState,           SharedHelper.GetProb(ProbVariables.Bot.ExpressMentalState)),
            };

            #endregion

            #region Disable actions - NOT ADAPTED for category and subcategory
            if (BotConfigShared.DisableAskQuestions)
            {
                SharedHelper.LogError("NOT ADAPTED for category and subcategory");

                //two actions are removed
                //DisableAcion(ref items, ActionsEnum.AskPureFactQuestionAboutUser);
                //DisableAcion(ref items, ActionsEnum.AskUncertanFactQuestion);
            }

            //foreach (string da in disabledActions)
            //{
            //    DisableAcion(ref items, da);
            //}
            #endregion

            #region Sampling

            var Action = CategoricalF(items).Normalize();

            SharedHelper.Log("Actions Histogram:\r\n" + Action.Histogram());

            var actionDist = Action.ToSampleDist();

            for (var i = 0; i < 100; i++)
            {
                string sample = actionDist.Sample();

                allActions.Enqueue(sample);
            }
            #endregion

            return(allActions);
        }
예제 #2
0
 public static void PrintSuggestionsProbabilities()
 {
     SharedHelper.Log("SUGGESTIONS Probabilities: \r\n"
                      + "Suggest Go out: " + SharedHelper.GetProb(Bot.SuggestGoOut).Value.ToString() + "\r\n"
                      + "Tell Joke: " + SharedHelper.GetProb(Bot.TellJoke).Value.ToString() + "\r\n"
                      + "Suggest To WatchMovie: " + SharedHelper.GetProb(Bot.SuggestToWatchMovie).Value.ToString() + "\r\n"
                      + "Tell Weather Forecast: " + SharedHelper.GetProb(Bot.TellWeatherForecast).Value.ToString() + "\r\n"                          //not used
                      + "Suggest Listen To Song: " + Bot.PrSuggestListenToSong.Value.ToString() + "\r\n"
                      );
 }
예제 #3
0
 public static void PrintActionsProbabilities()
 {
     SharedHelper.Log("ACTIONS Probabilities: \r\n"
                      + "PrMakeSuggestion: " + Bot.PrMakeSuggestion[(int)PV.Current].Value.ToString() + "\r\n"
                      + "PrAskUncertanFactQuestion: " + Bot.PrAskUncertanFactQuestion.Value.ToString() + "\r\n"
                      + "PrAskPureFactQuestionAboutUser: "******"\r\n"
                      + "PrSharePureFactInfoAboutBot: " + Bot.PrSharePureFactInfoAboutBot[(int)PV.Current].Value.ToString() + "\r\n"
                      + "PrChangeVisualAppearance: " + SharedHelper.GetProb(Bot.ChangeVisualAppearance).Value.ToString() + "\r\n"
                      + "PrExpressMentalState: " + SharedHelper.GetProb(Bot.ExpressMentalState).Value.ToString() + "\r\n"
                      );
 }
예제 #4
0
        private Queue <string> GenerateSuggestions()
        {
            #region Update suggstions based on new information

            allSuggestions.Clear();

            ProbVariables.PrintSuggestionsProbabilities();

            var Suggestion = CategoricalF(

                //Multiple times
                ItemProb(SuggestionsEnum.ListenToSong, ProbVariables.Bot.PrSuggestListenToSong),

                //Can be multiple times
                ItemProb(SuggestionsEnum.TellJoke, SharedHelper.GetProb(ProbVariables.Bot.TellJoke)),     //we can say several jokes in a row, no need to reduce the probability of saying a joke

                //A few times per evening
                ItemProb(SuggestionsEnum.GoOut, SharedHelper.GetProb(ProbVariables.Bot.SuggestGoOut)),

                //A few times per evening
                ItemProb(SuggestionsEnum.WatchMovie, SharedHelper.GetProb(ProbVariables.Bot.SuggestToWatchMovie)),

                //NOT USED!
                //Once per Morning (current day) / evening (tomorrow)
                //ItemProb(Suggestions.TellWeatherForecast, ProbVariables.PrTellWeatherForecast),

                ItemProb(SuggestionsEnum.DoSport, SharedHelper.GetProb(ProbVariables.Bot.SuggestDoSport))

                ).Normalize();

            SharedHelper.Log("Suggestion Histogram:\r\n" + Suggestion.Histogram());

            var suggestionDist = Suggestion.ToSampleDist();

            for (var i = 0; i < 100; i++)
            {
                string sample = suggestionDist.Sample();

                allSuggestions.Enqueue(sample);
            }
            #endregion

            return(allSuggestions);
        }
예제 #5
0
        public bool Process(bool isPureFactUpdated, TimeSpan timeSinceStart, IKorraAIModel model)
        {
            //SharedHelper.LogWarning("Inside movies trigger");
            #region Get Fact Manager
            PureFacts pfManager = (PureFacts)model.ItemProviders.SingleOrDefault(x => x is PureFacts);
            if (pfManager == null)
            {
                SharedHelper.LogError("No manager in Process in MoviesModelUpdateTrigger.");
                return(false);
            }
            #endregion

            var context = model.GetContext();

            PureFact factJob = (PureFact)pfManager.GetByName("UserHasJob");
            PureFact factWatchedMovieYesterday = (PureFact)pfManager.GetByName("UserMovieYesterday");

            if (factJob == null || factWatchedMovieYesterday == null)
            {
                SharedHelper.LogError("factJob or factWatchedMovieYesterday is NULL in MoviesModelUpdateTrigger.");
            }

            if (!IsTimeOfDayUpdated && !isPureFactUpdated)
            {
                return(false);
            }

            SharedHelper.Log("Inside MoviesModelUpdateTrigger");

            var oldSuggestToWatchMovie = SharedHelper.GetProb(ProbVariables.Bot.SuggestToWatchMovie).Value;

            //TODO: this model can be replaced by a Bayesian network, because of the too many IFs

            //if no job or weekend
            if ((factJob.IsAnswered && context.BasePhrases.IsNo(factJob.Value)) || StatesShared.IsWeekend)
            {
                ProbVariables.Bot.SuggestToWatchMovie = BernoulliF(Prob(0.18));
                //KorraBaseHelper.Log("Prob SuggestToWatchMovie changed to: 0.18, no job or weekend");
            }
            else if (factJob.IsAnswered && context.BasePhrases.IsYes(factJob.Value)) //if has job
            {
                #region working and evening
                if (StatesShared.IsEvening /*TODO: or after work hours*/)
                {
                    //has NOT watched movie yesterday (is working and evening)
                    if (factWatchedMovieYesterday.IsAnswered && context.BasePhrases.IsNo(factJob.Value))
                    {
                        ProbVariables.Bot.SuggestToWatchMovie = BernoulliF(Prob(0.18));
                        //KorraBaseHelper.Log("Prob SuggestToWatchMovie changed to: 0.18, evening");
                    }
                    //has watched movie yesterday (is working and evening)
                    else if (factWatchedMovieYesterday.IsAnswered && context.BasePhrases.IsYes(factJob.Value))
                    {
                        ProbVariables.Bot.SuggestToWatchMovie = BernoulliF(Prob(0.12));
                        // KorraBaseHelper.Log("Prob SuggestToWatchMovie changed to: 0.12. Watched movie yesterday.");
                    }
                }
                #endregion
                else //is working and not evening, no time because working and not evening
                {
                    ProbVariables.Bot.SuggestToWatchMovie = BernoulliF(Prob(0.05));
                    //KorraBaseHelper.Log("Prob SuggestToWatchMovie changed to: 0.05");
                }
            }
            else //has job is unknown
            {
                ProbVariables.Bot.SuggestToWatchMovie = BernoulliF(Prob(0.10));
            }

            double newSuggestToWatchMovie = SharedHelper.GetProb(ProbVariables.Bot.SuggestToWatchMovie).Value;

            if (Math.Abs(oldSuggestToWatchMovie - newSuggestToWatchMovie) > (1 / 1000))
            {
                executedCount = executedCount + 1;

                SharedHelper.Log("Prob SuggestToWatchMovie changed from " + oldSuggestToWatchMovie + " to: " + SharedHelper.GetProb(ProbVariables.Bot.SuggestToWatchMovie));
                //return new ModelUpdateTriggerReturn { IsTriggered = true, IsResamplingRequired = true, Value = "" };
                return(true); //re-sampling requested
            }
            else
            {
                return(false); //no re-sampling
            }
        }