<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom"><title>Todd Schiller - MLNs</title><link href="https://toddschiller.com/" rel="alternate"></link><link href="https://toddschiller.com/feeds/tag/mlns.atom.xml" rel="self"></link><id>https://toddschiller.com/</id><updated>2016-04-19T00:00:00-04:00</updated><subtitle>Human ✘ Artificial Intelligence</subtitle><entry><title>Markov logic networks for fun and profit: NBA playoffs edition</title><link href="https://toddschiller.com/blog/markov-logic-network-nba-playoffs.html" rel="alternate"></link><published>2016-04-19T00:00:00-04:00</published><updated>2016-04-19T00:00:00-04:00</updated><author><name>Todd Schiller</name></author><id>tag:toddschiller.com,2016-04-19:/blog/markov-logic-network-nba-playoffs.html</id><summary type="html">&lt;p&gt;Markov Logic Networks (MLNs) are a tool for capturing your beliefs
about the world and then calculating the likelihood of outcomes based
on those beliefs. Since it's the NBA playoffs, let's use MLNs and our beliefs
about the NBA to predict the 2016 NBA championship.&lt;/p&gt;
&lt;h2&gt;Specific Beliefs (Predicates)&lt;/h2&gt;
&lt;p&gt;To get …&lt;/p&gt;</summary><content type="html">&lt;p&gt;Markov Logic Networks (MLNs) are a tool for capturing your beliefs
about the world and then calculating the likelihood of outcomes based
on those beliefs. Since it's the NBA playoffs, let's use MLNs and our beliefs
about the NBA to predict the 2016 NBA championship.&lt;/p&gt;
&lt;h2&gt;Specific Beliefs (Predicates)&lt;/h2&gt;
&lt;p&gt;To get us started, I know for a fact that the Golden State Warriors won the 2015
championship. In MLN-speak &lt;a href="#tuffy"&gt;[1]&lt;/a&gt;, we write this fact as:&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;code&gt;champion(2015, Warriors)
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;Here, &lt;code&gt;champion(...)&lt;/code&gt; is a called a predicate. A predicate is either
&lt;code&gt;true&lt;/code&gt; or &lt;code&gt;false&lt;/code&gt; depending on its arguments (in this case, the year and
the team).&lt;/p&gt;
&lt;p&gt;With MLNs, we can also state beliefs that aren't certain. For example,
I'm 60% sure the Warriors will win the 2016 championship. In
MLN-speak, we write this belief by assigning a probability to the
predicate:&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;code&gt;0.6 champion(2016, Warriors)
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;h2&gt;General Beliefs (Rules)&lt;/h2&gt;
&lt;p&gt;In addition to statements about specific things, we can use MLNs to
capture rules about how the world works. For example, in the NBA, we
know there's exactly one NBA champion each year. We write this in
MLN-speak with two statements:&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;code&gt;champion(year, team!)
EXIST team champion(year, team).
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;The &lt;code&gt;team!&lt;/code&gt; in the first statement says that, by definition, there is
at most one team for which the predicate &lt;code&gt;champion(year, team)&lt;/code&gt; holds.
The second statement says that, by definition, there exists at least
one championship team each year. Together, these two statements encode
that there's exactly one championship team per year.&lt;/p&gt;
&lt;p&gt;In reality (and fantasy sports), we also have beliefs that are
generally true, but are not hard-and-fast rules, e.g.:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;A team that wins the championship will also win the next year&lt;/li&gt;
&lt;li&gt;A team with an injured starter won't win the championship&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;In MLN-speak, we write these rules as:&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;code&gt;??? champion(year1, team), year2 = year1 + 1 =&amp;gt; champion(year2, team)
??? hasInjuredStarter(year, team) =&amp;gt; !champion(year, team)
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;The &lt;code&gt;=&amp;gt;&lt;/code&gt; symbol indicates that the predicates on the left imply the predicates
on the right. That is, if the left side is true,
then the right side is also true (&lt;em&gt;but not necessarily vice versa&lt;/em&gt;). The
&lt;code&gt;!&lt;/code&gt; symbol in the second statement is negating the predicate &lt;code&gt;champion&lt;/code&gt; —
that &lt;code&gt;team&lt;/code&gt; is NOT the &lt;code&gt;champion&lt;/code&gt; for &lt;code&gt;year&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;But what probabilities should we assign these rules? If we did have
probabilities, what would the relative importance of the rules be?
Are the Golden State Warriors more likely to win even if Stephen Curry
is out with an injured ankle? For rules, instead of assigning a
probabilities, we assign them relative weights. Relative weights allow
the MLN to handle multiple, possibly conflicting, rules.&lt;/p&gt;
&lt;h3&gt;Learning Rule Importance (Weights)&lt;/h3&gt;
&lt;p&gt;If you have good historic evidence (data), a good way to assign the
weights is to have the MLN learn the weights automatically from the
evidence. The MLN will pick the weights that make the historical
outcomes most likely. In our case, it's going to pick
weights that made the previous NBA champions the most likely champions
according to our rules (upsets be damned).&lt;/p&gt;
&lt;p&gt;If the NBA just had 4 teams, the Heat, the Spurs, Warriors, and the
Cavaliers, the historic evidence for 2015 would be:&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;code&gt;hasInjuredStarter(2015, Cavaliers)
!hasInjuredStarter(2015, Heat)
hasInjuredStarter(2015, Spurs)
!hasInjuredStarter(2015, Warriors)
!champion(2015, Cavaliers)
!champion(2015, Heat)
!champion(2015, Spurs)
champion(2015, Warriors)
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;Learning the weights based on the 2013-2015 seasons, the MLN finds the
following weights:&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;code&gt;-3.7 champion(year1, team), year2 = year1 + 1 =&amp;gt; champion(year2, team)
4.2 hasInjuredStarter(year, team) =&amp;gt; !champion(year, team)
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;Here the negative weight for the first rule indicates that our
intuition was incorrect — based on the evidence, winning the
championship makes a team less likely to win the next year! Indeed,
there was no back-to-back champion in the 2013-2015 seasons (the Heat
won in 2012 and 2013). The size of the weights indicate the two rules are
roughly equally important, but in opposite directions.&lt;/p&gt;
&lt;h2&gt;Predicting the 2016 Championship (Inference)&lt;/h2&gt;
&lt;p&gt;Once we've assigned weights to the rules in our model, we can have the
MLN infer (estimate) the probability of uncertain predicates. In our
case, we want to know the probability of each team winning the 2016
championship. This is called our query:&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;code&gt;champion(2016, team)
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;Before we query our model, though, we need to provide our beliefs about
the likelihood of injury for each team in the 2016 playoffs. We provide
these beliefs by adding the predicates, with their probabilities,
to the evidence:&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;code&gt;0.9 hasInjuredStarter(2016, Warriors)
0.8 hasInjuredStarter(2016, Heat)
0.4 hasInjuredStarter(2016, Spurs)
0.2 hasInjuredStarter(2016, Cavaliers)
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;The MLN can then infer the probability of each team winning the championship.
The inferred probabilities will be consistent with the rules we captured, our
beliefs about the probability of injury, and the historical evidence:&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;code&gt;0.3500 champion(2016, Cavaliers)
0.3400 champion(2016, Spurs)
0.3000 champion(2016, Heat)
0.0100 champion(2016, Warriors)
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;The probabilities sum to 100%, which is a good sign. Our model is bearish
on the Warriors, giving them only a 1% chance of winning the championship.
The low probability is due to fact they won in 2015 and we assigned them a high
likelihood of injury this year.&lt;/p&gt;
&lt;h2&gt;Next Steps&lt;/h2&gt;
&lt;p&gt;There's a lot of different directions we could go to improve our model. We could
capture our beliefs about anything from match ups to
home court advantage to backup players to mascot popularity. In general
you'll want to target the areas that will likely have the largest
impact. These will be beliefs that either you haven't accounted for
yet, or that your current model is most sensitive to (i.e., rules with
large weights).&lt;/p&gt;
&lt;h2&gt;Summary&lt;/h2&gt;
&lt;p&gt;Markov Logic Networks (MLNs) are a tool for capturing your beliefs and
inferring the likelihood of events based on those beliefs. In this
post, we used an MLN to capture our beliefs about the NBA playoffs. We
had the MLN learn the relative importance of general rules based on
historic evidence, and then inferred the probability of each team
winning the 2016 championship.&lt;/p&gt;
&lt;h2&gt;Footnotes&lt;/h2&gt;
&lt;p&gt;[1] &lt;a name="tuffy"&gt;&lt;/a&gt; This post uses the
&lt;a href="http://i.stanford.edu/hazy/tuffy/"&gt;Tuffy&lt;/a&gt;
syntax for Markov Logic Networks.&lt;/p&gt;
</content><category term="Machine Learning"></category><category term="Markov Logic Networks"></category><category term="MLNs"></category><category term="sports"></category><category term="betting"></category></entry></feed>