-
Notifications
You must be signed in to change notification settings - Fork 0
Probabilistic Examples
These are examples of probabilistic modeling using a C# Linq syntax and "Probabilistic C#" library. It is basically small bayesian networks with exact reasoning.
Here we encode a probabilistic variable that determines how often the bot will try to convince the user to go out for a coffee, beer or just with friends.
public static FiniteDist<bool> SuggestGoOut = from t in User.Tired
from sgo in BernoulliF(Prob(t ? 0.02 : 0.06))
select sgo;
The concept of going out depends on whether the user is tired. 'User.Tired' has some default value which is updated when the user responds the question "Do you feel tired?". In the code above we apply probabilistic inference to say that when a person is tired, then probably he has less energy and so we should not push him too much to go out. When being tired we combine that with 0.02 probability that decreases the overall probability of going out compared to not being tired which will be combined with 0.06. Then 'SuggestGoOut' is used in the 'Suggestions' distributions so when sampling from it in the case of being too tired we get less phrases that stimulate the user to go out with friends.
Here we describe the probability or the distribution over the concept how often should the bot tell the weather forecast. Weather forecast can be retrieved automatically and simplified to a single boolean variable 'IsWeatherForecastGood'.
if (Sates.IsWeatherForecastGood)
ProbVariables.Bot.TellWeatherForecast = BernoulliF(Prob(0.9)); //we should always tell a good weather
else //not a good weather
ProbVariables.Bot.TellWeatherForecast = from igm in ProbVariables.User.InAGoodMood
from twf in BernoulliF(Prob(igm ? 0.7 : 0.4))
select twf;
In this example we have a regular variables that holds a specific exact value like for example 'IsWeatherForecastGood' and probabilistic variables such as 'User.InAGoodMood'. We use both to construct the distribution over 'Bot.TellWeatherForecast'. We encode the logic that we should always inform the user when the weather is good. For that we put probability of 0.9. On the other hand if the weather is not good then we should also tell the weather, but with less probability when it was good and higher when then user is also in a bad mood, so a value of 0.7 has been chosen. In worst case both the weather and the user are in bad mood that is why we put 0.4 having the lowest chance to tell the weather.
Another "suggestion" that the bot can perform is to persuade the user to do some sport.
PureFact factSport = PureFacts.GetFacfByName("UserDoesSport");
if (factSport.IsAnswered && context.Phrases.IsNo(factSport.Value))
{
ProbVariables.Bot.SuggestGoToGym = BernoulliF(Prob(0.15));
requestRegeneration = true;
}
The main idea is that if one is not doing any sport, he should be encouraged him to do so. But we do not know when the question about sport will be asked. This question (implemented as 'PureFact') depends on the main distribution and the probability of using a pure fact and then using exactly the 'UserDoesSport'. That is why we constantly check if the user has answered the question which is stored in the pure fact 'UserDoesSport' and we update the model accordingly. So if the user does not do sport we increase the probability from its default value of 0.10 to 0.15 in order to stimulate him to do some sport. We also request that the main distribution is re-sampled in order to clear the current queued interactions that were samples with the 0.10 probability. Regeneration is required because interactions are actually sampled and buffered before being executed.