410 likes | 618 Views
VTL03. Infer.NET Building software with intelligence. John Winn and John Guiver Microsoft Research, Cambridge, UK. Intelligent Software. It should be easier to write software that can adapt, learn and reason…. Word?. Search result?. Who’s the best?. Clicks. Gestures. Game results.
E N D
VTL03 Infer.NETBuilding software with intelligence John Winn and John Guiver Microsoft Research, Cambridge, UK
Intelligent Software • It should be easier to write software that can adapt, learn and reason… Word? Search result? Who’s the best? Clicks Gestures Game results
Reasoning Backwards • Need to reason backwards from things we can measure to things we can’t Word? Search result? Who’s the best? Gestures Clicks Game results
Probability • Can be multiple possible interpretations of some measurements • “Hello” 70% • “Halo” 20% • “Hall” 5% … Gestures
Code for Reasoning Backwards Ordinary program Probabilistic program with Infer.NET 20-30 lines of ‘simulation’ code (in any .NET language) Hours, not months! 100s-1000s of lines of code
Some Infer.NET Probabilistic Programs ...in Social Networks Recommended songs Network and music tastes Simulation of sharing of musical tastes between friends ...in Healthcare New understanding of the causes of asthma Electronic health records Clinical simulation of asthma
Some Other Infer.NET Applications • Program verification • Personalisation and recommendation • Data form entry checking • Gene expression analysis • Judgement calibration • Population modelling • Extracting plots of story books • … and many more
A Simple Probabilistic Program • I toss two fair coins • What is the probability both are heads?
C# 'Probabilistic' Program bool firstCoin = random.NextDouble()>0.5; bool secondCoin = random.NextDouble()>0.5; bool bothHeads = firstCoin & secondCoin; … T F T T … F F T T … F F F T
After a Very Large Number of Runs… • ~50% T bool firstCoin = random.NextDouble()>0.5; bool secondCoin = random.NextDouble()>0.5; bool bothHeads = firstCoin & secondCoin; • ~50% F • ~50% T • ~50% F • ~25% T • ~75% F
Reasoning Backwards • Suppose I did not get two heads • What is the probability the first coin was heads?
Probabilistic Program We observe that bothHeads is F bool firstCoin = random.NextDouble()>0.5; bool secondCoin = random.NextDouble()>0.5; bool bothHeads = firstCoin & secondCoin; … T F T T … F F T T … F F F T
Two Coins in C# example
After a Very Large Number of Runs… • ~33% T bool firstCoin = random.NextDouble()>0.5; bool secondCoin = random.NextDouble()>0.5; bool bothHeads = firstCoin & secondCoin; • ~67% F • ~33% T • ~67% F • ~0% T • ~100% F
Multiple Runs Are Very Inefficient • Illustrates how a prob. program works • But we want to reason about complex situations with 1000s of variables e.g. observing 20 binary variables needs ~220 million runs • Is there a practical approach? Infer.NET
Random Variables in Infer.NET T T var firstCoin = Variable.Bernoulli(0.5); var secondCoin = Variable.Bernoulli(0.5); var bothHeads = firstCoin & secondCoin; • 50% • 50% F • 25%
Getting the Distribution of ‘bothHeads’ varengine = newInferenceEngine(); Bernoulli result = engine.Infer<Bernoulli>(bothHeads); doubleprobTrue = result.GetProbTrue(); // ‘probTrue’ is now exactly 0.25
Adding an Observation We observe that bothHeads is F bothHeads.ObservedValue = false; Bernoulli firstDist = engine.Infer<Bernoulli>(firstCoin); double newProb = firstDist.GetProbTrue(); // ‘newProb’ is now exactly 0.333…
Two Coins in Infer.NET example
How Infer.NET Works Bernoulli(0.5) Bernoulli(0.5) firstCoin secondCoin & • Normal execution bothHeads • Backwards messages Observe F
Almost Done with the Coins! • For ‘tossing a coin’ think: • Clicking on a link • Choosing a menu option • Buying a product… • Want to learn the probability of these events • Like having a biased coin
Biased Coins • Probability of heads (p) • 10% • 50% • 90% T T T F T T F T F F T F F F T F T F
Reasoning Backwards • Beta distributions • 10% • 50% • 90% T T T F T T F T F F T F F F T F T F
Reasoning Backwards // a flat Beta distributionvarp = Variable.Beta(1,1); vartoss1 = Variable.Bernoulli(p);toss1.ObservedValue = false; vartoss2 = Variable.Bernoulli(p); toss2.ObservedValue = true; Beta result = engine.Infer<Beta>(p); // gives a Beta curve like the ones// on the last slide F T … …
The Click Log Click Log 1 2 3 4 T F T F
Aaargh! It’s relevant! Imagine One User and One Query Examine appeal Done! N Y Next? Click? Let’s look at the page … … and see if it’s useful Let’s look at the next result … … and see if it’s worth clicking on That looks promising …… let’s click Y N View relevance N Y Next? Relevant? N Y Y Next? varclick = Variable.Bernoulli(appeal[d]); var next = Variable.Bernoulli(0.2); vardoNext = Variable.Bernoulli(0.9); varisRel= Variable.Bernoulli(relevance[d]); N
A Snippet of Infer.NET code // Is user examining this item? examine[d] = examine[d - 1] &(((!click[d - 1]) & nextIfNotClick) |(click[d - 1] & nextIfClick)); // Flip the biased coins! click[d] = examine[d] & Variable.Bernoulli(appeal[d]); isRelevant[d] = click[d] & Variable.Bernoulli(relevance[d]);
Reasoning Backwards Click Log T F T T T F F F F F F T F T T F for(int d = 0; d < nRanks; d++) click[d].ObservedValue = user.clicks[d];
Click Analysis in Infer.NET example
How Good Are You at Halo? • Xbox Live • 12 million players • 2 million matches per day • 2 billion hours of gameplay • The Challenge • Tracking how good each player is to match players of similar skill. • TrueSkill™ • Months of work, 100s of lines of code Old Estimates of Players’ Skills New Estimates of Players’ Skills
3rd Place 1st Place 2nd Place Inferring Skills Game Outcome SniperEye DrSlowPlay Belief in Skill Level • Sully 0 10 20 30 40 50 Skill Level
Probabilistic Program • // Gaussian random variables for skills • var skill1 = Variable.Gaussian(oldMean1, oldStdDev1); • varskill2 = Variable.Gaussian(oldMean2, oldStdDev2); • varskill3 = Variable.Gaussian(oldMean3, oldStdDev3); • // Players’ performances are centred around their skills • varperf1 = Variable.Gaussian(skill1, beta); • var perf2 = Variable.Gaussian(skill2, beta); • var perf3 = Variable.Gaussian(skill3, beta); • // Outcomes • Variable.ConstrainPositive(perf1 – perf2); • Variable.ConstrainPositive(perf2 - perf3); • // Now we update the players’ skills • var newSkill1 =engine.Infer<Gaussian>(skill1); • varnewSkill2 =engine.Infer<Gaussian>(skill2); • varnewSkill3 =engine.Infer<Gaussian>(skill3);
‘Language’ Elements of Infer.NET Poisson Beta Gaussian Discrete Dirichlet Gamma Bernoulli Wishart Variable.If Variable.Switch Variable.ForEach Variable.Case Variable.IfNot varbias =Variable.Beta(1,1); varcoin =Variable.Bernoulli(bias); varh =Variable.GaussianFromMeanAndPrecision(m, p); vara = b > c; varz = x + y; Variable<bool>
Sometime in the Future? • varfirstCoin =Variable.Bernoulli(0.5); • varsecondCoin =Variable.Bernoulli(0.5); • varbothHeads = c1 & c2; • bothHeads.ObservedValue = false; • varie = newInferenceEngine(); • Bernoulli result =ie.Infer<Bernoulli>(firstCoin); Infer.NET API Probabilistic language?
Thank you http://research.microsoft.com/infernet
YOUR FEEDBACK IS IMPORTANT TO US! Please fill out session evaluation forms online at MicrosoftPDC.com
Learn More On Channel 9 • Expand your PDC experience through Channel 9 • Explore videos, hands-on labs, sample code and demos through the new Channel 9 training courses channel9.msdn.com/learn Built by Developers for Developers….