Main content
Course: LeBron asks > Unit 1
Lesson 1: LeBron asks- LeBron Asks: What muscles do we use when shooting a basket?
- LeBron Asks: How does shooting a basketball illustrate Newton's 3rd Law?
- LeBron Asks: If Earth's history were a basketball game, when did humans appear?
- LeBron Asks: Why does sweating cool you down?
- LeBron Asks: Why does humidity make it feel hotter?
- Free-throw probability
- Three-pointer vs free-throw probability
- Monte Carlo simulation to answer LeBron's question
© 2024 Khan AcademyTerms of usePrivacy PolicyCookie Notice
Monte Carlo simulation to answer LeBron's question
When down 3 with 30 seconds left, is it better to take a hard 3 or an easy 2 and try to get another possession? Simulation at: http://www.khanacademy.org/cs/basketball-decisions/1024155511. Created by Sal Khan.
Want to join the conversation?
- How does the Monte Carlo simulation work?(84 votes)
- MC simulation works on the random numbers. Although it is specially suited for stochastic processes however it can be very well used in deterministic problems also.
The process involves, to check for an event to happen; generate a random number and test it against probability of that event. If the random number is less than or equal to probability count that event and vice-verse. This is very simplified description. You can check the web for details.(3 votes)
- what if you have to decide rather to shoot or pass in the same scenario ?(3 votes)
- take the three
because go to overtime because you only have 30 secs(3 votes)- In all honesty. It is better to take the best look.
30 seconds is a lot of time if you still have a timeout. No point taking a contested 3, if you can get an easy 2, and a potential easier 3 next time. Scoring with 30 seconds left, their is more than a shot clock left, so scoring is the only option. Taking the highest percentage shot and playing tough defense should be the number one priority.(1 vote)
- Who invented the Monte Carlo simulation. Is it specifically made to help coaches in the NBA to understand what to do in very close games so the team has a shot to win.(2 votes)
- According to Wikipedia, "In the 1930s, Enrico Fermi first experimented with the Monte Carlo method while stuyding neutron diffusion, but did not publish anything on it." [Enrico Fermi was a famous nuclear physicist.] It continues, "The modern version of the Markov Chain Monte Carlo method was invented in the late 1940s by Stanislaw Ulam, while he was working on nuclear weapons projects at the Los Alamos National Laboratory. Immediately after Ulam's breakthrough, John von Neumann understood its importance and programmed the eNIAC computer to carry out Monte Carlo calculations."
So, no, it's not specifically for NBA coaches. It is useful in a wide variety of areas. The "AlphaGo" computer that in March 2016 beat Baduk champion Lee Sedol -- that computer relied in part on Monte Carlo methods.(1 vote)
- Should LeBron take the three?(1 vote)
- Can this be done for soccer also? If so, how?(2 votes)
- I would think yes, because in soccer, each goal is 1 point to the score board, like basketball where you can take three or two or one to tie the game.(1 vote)
- At6:13, he has curTrial highlighted. I tried to make a Monte Carlo Simulation but when I inserted the curTrial section, as he did, I noticed and the screen told me that I had not defined curTrial. How should I define it as a variable so that it allows me to continue?(1 vote)
- You'll notice above that highlighted section, just before the beginning of the function definition, there's a line that reads:
<code>var curTrial = 0;</code>
This is the definition of the <code>curTrial</code> variable along with setting its initial value to zero.
Since I'm not sure from the phrasing of your question how familiar you are with programming concepts in general, and the JavaScript-based language used here, I post the following in the hope it will help you or another person who may be new to one or both:
It is necessary to both define and initialize (set the value of) a variable, each of which is a place to store data such as a number of runs through a function, a string of characters, or a structure or object based on multiple such primitive data such as a line to be drawn, or a chemical formula. You'll notice that the line highlighted compares the value stored in <code>curTrial</code> to the value stored in <code>trials</code>, another variable which Sal later points out as he changes the value from 10 to 1000 for a longer and more accurate run, and then to 300 for the second run with changes in the percentages of likelihood of scoring a two-pointer, a three-pointer, and of the opposing team scoring a two-pointer or free-throw, represented near the top of the code as
<code>threePtPercent,
twoPtPercent,
oppTwoPtPercent,
</code>and
<code>oppFtPercent</code> respectively.
Just as each of those is defined and instantiated at the beginning of the code, the <code>curTrials</code> variable is defined and instantiated before running the trials in order to keep track of how many times each has been run. This particular variable has to be defined independently (outside) of the function because the functions can't change the value each time they're run. So, to review, the two variables <code>curTrials</code> and <code>trials</code> need to be defined and instantiated before the comparison (<code>curtrials < trials</code>) can be made.(2 votes)
- how does monte carlo simulation work(2 votes)
- MC simulation works on the random numbers. Although it is specially suited for stochastic processes however it can be very well used in deterministic problems also.
The process involves, to check for an event to happen; generate a random number and test it against probability of that event. If the random number is less than or equal to probability count that event and vice-verse. This is very simplified description. You can check the web for details.(1 vote)
- Doesn't it all count on the statistics? If so, isn't it technically impossible to calculate your chances?(1 vote)
- Well its also about the day who taking the shoot .... like if your tired you will have less of a chance to make it then if your still warm..... but also its how loud the crowd is and how nervous you are and also how experienced the shooter is(1 vote)
- what does he use to swich the numbers up??(1 vote)
Video transcript
LeBron: It's LeBron here. I got
a quick brain teaser for you. If I'm down 3 with 30 seconds left is it better to take the 3? Or is it easier to take
the 2 and attempt to fowl a bad free throw shooter and
get another possession? Here's my friend Sal with an answer. Sal: That's a very very
interesting question, LeBron. Calculating the probabilities
of if you were to take a 3 what's your probability of tying the game and then being able to win in overtime that can be done on paper but the scenario where you take
a 2 and you attempt to fowl the opposing team and
they might make none or 1 or two free-throws and then
you might get another posession and then you take another 2 That's more complicated. You
could attempt to do it on paper but instead, I've written a
little computer simulation here and this type of a simulation is called
a Monte-Carlo simulation and literally, it'll run the scenarios and
it will do it as many times as we put in this variable over
here. So we're gonna set it up so we get an accurate number.
We're gonna do it a THOUSAND times for each of those scenarios and
see what fraction in each scenario which fraction do we end up winning?
And that's a pretty good estimate of the probability of us
actually winning the game depending on which strategy we choose. The rest of these things, these
variables that we set right over here these are the parameters
that will essentially drive the outcomes. This three-point
percentage, this is your three-point percentage, I have
it low here because I'm assuming it's going to be a hard 3.
It's going to be lower than a typical 3 point percentage. But obviously if this
number, if you set it higher than the three will look
better. If you set it lower than the 2 is going to look better. This is your 2 point
percentage. I'm assuming here it's going to be a relatively
easy 2 because the other team isn't going to be defending
as heavily against a 2. So I put it a little higher but
you can play with the numbers to see what you get in
different scenarios. This is the probability of
the opponent taking a 2, this is the opponent's
free-throw percentage. Once again if this is very
high than the fowling is not going to look as good. If this is
low the fowling might make sense. And I put this a little bit
lower than the league average because I'm assuming
you'll attempt to fowl or you have a reasonable chance of fowling
one of the weaker free-throw shooters. This is how much time goes off
the clock when you take a 2 This is how long it takes you to
fowl. This is offensive rebound percentage. And then I have a slightly different thing that I separated out is the, the percent chance of
a team taking a free-throw. If they miss their second free-throw the
percent chance that they'll actually be able to rebound it. So that's
15% you can play with that And this is just a probability,or
your percent chance of winning in overtime. And
I just put that at 50/50 and the rest of this really
just uses those parameters to go through the simulations.
This is a little code right over here just to draw the
background or actually load the images This is the meat. These two functions. So take 3 is a scenario
where we go for the 3. So we try to make the 3,
if we make the 3 then we have essentially tied the game
and now we're going into overtime and if we win in overtime, then we win! If neither of those things are true, or if one of those things
end up not being true either we make the 3 and
we lose in overtime, or we don't make the 3, then
false, we didn't win. And this function is going to
be called as many times as that variable trials. So it could
be called a thousand times a million times, whatever we
set it to, to figure out what fraction of the scenarios do we win in? This does the same thing for the
taking the 2 and trying to fowl. It gets a little bit more
complicated but it's not too bad. And it's a very simple simulation, I
think a lot of people listening might be able to add some,
little bit more complexity to maybe make it a
little bit more accurate. But what it does, it keeps
of who has the posession, how many points you're
down,how much time is left, and the way I implimented it, it
really only works for specific scenario we talked about. You would
probably want to make it fancier if you had more time on
the clock or if you wanted to cover more scenarios of different point spreads. But this
is essentially saying, look, while we're gonna
keep running this scenario, while there's time left on the
clock, this clause is talking about what do we do if we have the possession? If we're down by more than 3,
then we're gonna want to take it as quickly as possible and
we just take the minimum time off necessary to shoot a 2.
Otherwise, we would acutally want to run down the
clock. So if we happened, for whatever reason while going
through this over and over again to be up, we would probably
want to run the clock down before we take a shot. Now
this right over here says, remember, this is a scenario
where we're taking a 2, so this says, okay, lets try
to go for the 2 if we make it, then we're down by 2 less. And then we,
the possession goes to the other team. If we do not make it, does
the opposing team rebound it? So this is essentially
saying, if the opposing team makes the rebound, so we
did not make the offensive rebound, then they now
have the possession. This clause over is, what about the
cases where we don't have the possession? This is essentially what we say
if we're down by a more than zero points than we're
going to try to fowl. We're going to take the
time off the clock to fowl. Then the opponent is going
to take their two free-throws right over here, and there's
a little bit of code to see if in the situation that they
missed the second free-throw, there's some probability that
the opponant might actually be able to get the offensive rebound, so
we actually put that in there as well. Then there's the scenarios where
maybe we just happen not to be down, in which case, the opponent
is likely to take a 2. At least we assume that.
This is a case where I think other people could modify
it more. The bottom line is if we're not down, we
definitely do not want to fowl. So we're not fowling in this scenario. Remember, we're in this 2 point scenario. This essentially says,
look, when the clock ends, when time goes to zero, if
we're down by more than zero we lost. If we're down by
less than zero, we won. Otherwise, it's tied
and we go into overtime. So this clause right over here
tests to see if we win in overtime. All of the other things
are really just to draw. This draws the bars, this draws
some of the numbers on top of it Then, this is we actually run the trial. So we call this as many
times as there are trials that trials variables, and
we count how many times do we win taking a 3? How many
times do we lose taking a 3? How many times do we win
taking a 2? How many times lose taking a 2? Then we just
display everything right over there. Now that we have a decent
understanding of the program itself, let's get a
little bit of a drumroll, and see whether it makes
sense to take the 3, given these assumptions.
Instead of having ten trials let's give it a big number.
Let's say a thousand trials, let me reset this this thing.
So restart it right over here. You see its getting better approximations. This is what fraction of
the trial so far resulted in a victory. So right now taking
a 2, looks like it's about 15-16%, looks like we got
a victory. Here its 12-13% As we got more and more trials
we're more likely to have a much much more accurate
sense of our probabilities. A more accurate approximation
of the probabilities. But let's see, it's getting close... And we get... 2. Well based on
this, it looks like there's... Based on the assumptions that
we made, and this is important, based on these assumptions, it
looks like we were better off by a little bit, slightly higher,
taking the easy 2 then trying to fowl. But if we change things, and
I'll make it lower trials so that we don't have to wait all
day, let's make it 300 trials, if you were to raise your
3 point percentage to say, let's say it's 35% and let's
say the 2 is much harder than we had before, let's
say its 40% and let's say your opponent is a really
good free-throw shooter so let's say it's 80%, I suspect that
you will have a different outcome. Let's restart it and see what happens. Now all of a sudden, it looks
like you're much better off given these assumptions. You're much
better off going for the 3 to tie. and go into overtime. So these
are really the assumptions that drive it for this simulation.