Learning something is good. Learning something using interesting examples is even better. Today I'm going to show you the power of bayesian inference by building model representing probability of you having some sex. If you want more formal introduction, please read this paper written by Christopher Bishop, famous researcher from Microsoft Research Cambridge.
Bayesian inference is a method for finding posterior distribution of dependent set of random variables, when some variables are observed and some are not interesting. That set of variables is often represented as so-called graphical model: a directed graph called Bayesian network or undirected graph called Markov network. In that kind of graph vertices represent random variables and edge connecting two vertices mean that variables associated with that vertices are dependent. That representation is not only clean and obvious, but it also allows using some fast and robust algorithms for performing inference.
Let's look at concrete example. We'll try to build simple model describing sexual relationships between boys and girls. Probability of you having sex with some girl mostly depends on the degree of she liking you (which depends on you sexuality) and her so-called slutness. I've also considered some gaussian noise in woman's head that sometimes dramaticaly imacts on her decisions. An assumption that slutness and sexuality are distributed normally around zero (which we consider as an average value for that variables) and value describing how much she likes you is also distributed normally around your sexuality allows us to build simple graphical model. Amazing tool for that is Infer.NET, .NET library for bayesian inference from Microsoft Research. Model code is quite short:
Variable<double> youAreSexy = Variable.GaussianFromMeanAndVariance(0, 1).Named("you're sexy");
Variable<double> howMuchSheLikesYou = Variable.GaussianFromMeanAndVariance(youAreSexy, 0.25).Named("how much she likes you");
Variable<double> slutness = Variable.GaussianFromMeanAndVariance(0, 1).Named("her slutness");
Variable<double> randomNoiseInHerHead = Variable.GaussianFromMeanAndVariance(0, 0.25).Named("noise in her head");
Variable<bool> willYouHaveSexToday = (howMuchSheLikesYou + randomNoiseInHerHead + slutness > 0).Named("will you have some sex?");
After compiling model in Infer.NET you'll get a graphical representation of your model which is called factor graph. It looks very similar to bayesian network but also contains special "factor" nodes representing different operations, constrains and distributions. Clickable picture below is an example of factor graph for our "sex" model:
Let's ask some questions to our model using ExpectationPropagation inference algorithm:
- slutness = -5 (she's REALLY not a slut), willYouHaveSexToday = true (yeah, you did it). Then distribution of you being sexy is Gaussian(3.514, 0.3635) which means you are beauty as a devil (I guess).
- slutness = -0.5 (she's just a girl), youAreSexy = -1 (you are not a good one). Then probability of you having sex today is 0.01695. It means that your chances are quite small.
- youAreSexy = -5 (oh, you look really bad), willYouHaveSexToday = true (but still have some sex? strange, isn't it?). Then distribution of her slutness is Gaussian(3.514, 0.3635) (oh, she is a slut... that makes sence).
So, bayesian inference helps us with different questions about girls, sex and everything. Remember that provided model is very simple and inaccurate. For example, one can consider slutness as a variance of howMuchSheLikesYou variable or add some other random variables and factors into model. Have fun with it and don't forget that math is great.

You should now touch on the drugs subject to justify the name of your blog.
ReplyDeleteCool thing is using drugs, not writing about them =)
ReplyDeleteHeh. There they've used this post as an example that some people can still talk about sex without swear words, body parts and stuff.
ReplyDeleteIsn't it "slut" a swear word?
> Cool thing is using drugs, not writing about them =)
ReplyDeleteYou don't say that sex is the thing to write about, not doing it, do you?
Oh, dude, come on.
ReplyDelete