When teaching mathematics, the traditional method of lecturing in front of a blackboard is still hard to improve upon, despite all the advances in modern technology. However, there are some nice things one can do in an electronic medium, such as this blog. Here, I would like to experiment with the ability to animate images, which I think can convey some mathematical concepts in ways that cannot be easily replicated by traditional static text and images. Given that many readers may find these animations annoying, I am placing the rest of the post below the fold.

Suppose we are in the classical (Kolmogorov) framework of probability theory, in which one has a probability space representing all possible states . One can make a distinction between *deterministic* quantities that do not depend on the state , and *random* variables (or stochastic variables) that do depend (in some measurable fashion) on the state . (As discussed in this previous post, it is often helpful to adopt a perspective that suppresses the sample space as much as possible, but we will not do so for the current discussion.)

One can visualise the distinction as follows. If I pick a deterministic integer between and , say , then this fixes the value of for the rest of the discussion:

.

However, if I pick a *random* integer uniformly from (e.g. by rolling a fair die), one can think of as a quantity that keeps changing as one flips from one state to the next:

.

Here, I have “faked” the randomness by looping together a finite number of images, each of which is depicting one of the possible values could take. As such, one may notice that the above image eventually repeats in an endless loop. One could presumably write some more advanced code to render a more random-looking sequence of ‘s, but the above imperfect rendering should hopefully suffice for the sake of illustration.

Here is a (“faked” rendering of) a random variable that also takes values in , but is non-uniformly distributed, being more biased towards smaller values than larger values:

.

For continuous random variables, taking values for instance in with some distribution (e.g. uniform in a square, multivariate gaussian, etc.) one could display these random variables as a rapidly changing dot wandering over ; if one lets some “afterimages” of previous dots linger for some time on the screen, one can begin to see the probability density function emerge in the animation. This is unfortunately beyond my ability to quickly whip up as an image; but if someone with a bit more programming skill is willing to do so, I would be very happy to see the result :).

The operation of conditioning to an event corresponds to ignoring all states in the sample space outside of the event. For instance, if one takes the previous random variable , and conditions to the event , one gets the conditioned random variable

.

One can use the animation to help illustrate concepts such as independence or correlation. If we revert to the unconditioned random variable

and let be an independently sampled uniform random variable from , one can sum the variables together to create a new random variable , ranging in :

(In principle, the above images should be synchronised, so that the value of stays the same from line to line at any given point in time. Unfortunately, due to internet lag, caching, and other web artefacts, you may experience an unpleasant delay between the two. Closing the page, clearing your cache and returning to the page may help.)

If on the other hand one defines the random variable to be , then has the same distribution as (they are both uniformly distributed on , but now there is a very strong correlation between and , leading to completely different behaviour for :

.

## 39 comments

Comments feed for this article

13 May, 2016 at 6:31 pm

scottedwards2000Nice!

13 May, 2016 at 7:47 pm

AnonymousMy opinion (It can be wrong of course, it’s just how I see it, I don’t want to argue): I always thought that it was a waste for the professor to write so much on the blackboard when he could have just show PowerPoint slides. Students copying things on notepads is a practice from the times of the Jesuits, when people had no books! Come on, we are on the age of the Internet, the professor should just put the class notes as PDF files for students to download and use the class to explain things, ask students questions, ask students to try to solve problems and explain to the other students, etc… These are some of the things that one can not get by just studying the book at home. The professor writing on the blackboard and the students just copying, not even putting any effort to follow what is being said, is a waste of their and the professor’s time! Just my opinion of course. The “best class possible” varies from student to student, but from my experience, albeit modest, the best students like to have to THINK during class. Please, I do not want to sound arrogant, I know very little about mathematics and teaching, it’s just my opinion, I do not want to argue.

13 May, 2016 at 10:43 pm

AnonymousThank you for your comments. I’m a teacher myself, and I appreciate hearing different opinions on teaching, particularly from students.

13 May, 2016 at 10:49 pm

AnonymousThis visualization seems to be precise (for finitely or countably many states ) by representing (i.e. modeling) each state as a certain (corresponding) discrete time .

14 May, 2016 at 6:11 am

J.P. McCarthyhttp://mathoverflow.net/questions/80056/using-slides-in-math-classroom/80551#80551

14 May, 2016 at 11:22 am

Chris AldrichA lovely little experiment in visual pedagogy in mathematics! We could certainly use more of these types of simple “explorations” particularly for younger math students who may not always be good at visualizing material. These seem reminiscent to me of Wilson Rugh’s java applets for digital signal processing years ago.

Some of this pedagogy argument about slides likely fits better into the area of the flipped classroom versus non-flipped. Though slides may be great (particularly if students have copies of them beforehand to take notes on as is often done commercially by many biology textbooks which have 2-4 slides down the left side of the page and note space on the right hand side) for mathematics I much prefer having notes in Livescribe .pdf format with embedded audio. This allows a student to not only relisten to the entire lecture, where often a lot of complicated material (especially in higher level abstract courses) is said very quickly and isn’t able to be written down even by some of the best transcriptionists with shorthand (and how many students know this anymore?), but they can skip around to parts they need more work on. As an example, download this .pdf file from a Lie Groups lecture and open it up in the most recent version of Adobe Reader to be able to see the visual and audio functionality.

The particular value often comes in seeing problems worked out in full detail with discussion, which some students need much more of than others. One of my favorite lecture experiences almost a decade ago was hearing an audible gasp from the classroom of undergraduates when Sol Golomb (USC) stopped in the middle of a complicated lecture on combinatorics and worked out a 4th grade simple long division problem on the board to get a final solution. Half the class had pulled out a calculator to get the answer and he’d finished before most of them had the first number input. The class learned more in that one minute of example than most did the entire lecture. Most of the best math is done in the “exploration” and practice than in a stripped down lecture as is highlighted in Ben Orlin’s recent post: The Essence of Mathematics. While it’s always lovely seeing theoretical mathematics as if it seemingly sprang fully formed from the head of Zeus, many students should see how the proverbial sausage (or laws) are actually made, especially at an earlier age.

15 May, 2016 at 3:56 am

DavetweedRegarding just downloading slide content, there is research in teaching that shows that doing some writing in general improves student understanding compared just to listening knowing the notes will be available later. I’ve known lecturers who take advantage of this while not requiring copying of everything by providing handouts of the lecture slides before the lecture with some key bits missing on each page. To get complete notes that u have to be following and occasionally fill in the blanks.

21 May, 2016 at 12:57 am

Máté WierdlLearning math is not about collecting information, so I do not understand the comment about the sufficiency of slides. As far as I can understand, lectures came about mostly because of lack of resources which necessitated bigger and bigger classes, but the ideal way of learning anything is via conversations. Learning and teaching rarely should be a one directional communication from profs to students: profs, teachers should and will learn from students as well.

Even in a traditional lecture, using slides is a mistake. Even during a lecture, students should be welcome to ask questions, make comments, and as a result, the lesson plan could and should change. Slides won’t adjust well to this dynamically changing environment.

13 May, 2016 at 11:58 pm

RahulRegarding the animation, was something like this what you had in mind?

14 May, 2016 at 8:33 am

Terence TaoYes, these are exactly what I had in mind! (Well, I had envisioned the afterimages fading a little bit as time proceeds, but you’ve still managed to make it so that the present image is the darkest and the oldest images are the lightest, so it still pretty much matches what I was imagining.) Thanks!

14 May, 2016 at 1:06 am

RahulAnother attempt at an animation. Uniform in a circle.

28 May, 2016 at 8:44 pm

aquazorcarsonYou mean a disk, not a circle.

14 May, 2016 at 7:25 am

Rahul14 May, 2016 at 8:11 am

Michael@Rahul – is there any chance you could put up an example for a bivariate normal with a correlation of say 0.75? I would love to show this collection of animations to students in an intro Stats class.

14 May, 2016 at 8:38 am

Rahul@Michael: Sure. I’ll try to post one in a bit.

14 May, 2016 at 10:01 am

Rahul@Michael:

Here’s a try. Not sure if this is what you had in mind? Not sure. To be honest, my knowledge of Stat is pretty basic.

14 May, 2016 at 11:46 am

Michael@Rahul – Yes! Thank you very much! This looks great! I hope you do not mind me showing a link directly to this in class.

14 May, 2016 at 11:50 am

Rahul@Michael

Glad I could help!

14 May, 2016 at 11:59 am

Michael@Rahul – can I ask what you used to create these? It looks like GGPlot in R and I am guessing here, but did you use a for() or an sapply() for successive plots dumping each out to a pdf and then some gif creator to put pauses between plots?

14 May, 2016 at 12:23 pm

Rahul@Michael

Yep. Almost exactly like you said. I used for(). No pdf. Used ggsave() to create a gif.

ImageMagic to combine the gifs into an agif.

It can probably be done better and faster. But I’m no R expert and it took me more than an hour to get it all figured out.

14 May, 2016 at 8:06 am

Onur SavasI see the last sum (x + z’) be equal to 5 once in a while. Is it just me? I assume there is some of race condition happening during computation.

[Oops, that was a manual typo. I’ve fixed it, although due to caching this may cause some loss of synchronisation in the images that may require one to clear one’s local cache to resolve -T.]14 May, 2016 at 10:33 am

James SmithHa! Funny, I had a conversation with one of my tutees the other day about the problems of envisioning random variables as opposed conventional ones. Specifically the fact that conventional variables are assigned a single value, albeit a variable one of course, whereas random variables you could say are assigned a set or sequence of values although even that doesn’t seem to quite hit the mark. Then the fact that you can still do algebraic manipulations with random variables despite the right hand sides of their assignments seeming somewhat ill defined. Say “roll a dice and multiply it by two”, for example, to get another random variable. I think your animations come as a good stab at this murky subject, at least murky when you try to explain it.

14 May, 2016 at 1:40 pm

Baptiste AuguieYou may be interested to see the efforts of Bret Victor as part of his “KillMath” project (not as contentious as it may sound!). On the technical aspect, he’s refined the user interface to provide truly interactive documents, which I think would be a great framework to pursue your ideas further. There’s also a pedagogical angle to this, as he shares some unique reflections on alternative, more visual and “user-oriented” interfaces to mathematical concepts, enabled by modern web technologies. http://worrydream.com/ExplorableExplanations/ is a good illustration.

16 May, 2016 at 8:13 am

Aaron SheldonHave you considered incorporating Jupyter notebooks into your lessons?

http://jupyter.org/

16 May, 2016 at 1:43 pm

DiegoI can also recommend this. I’ve been using it to teach and interactively show plots and the students enjoy it very much

16 May, 2016 at 9:46 pm

AnonymousThis is incredible. I currently am doing the second year maths undergrad program at University of St. Andrews and I had a tough time this year learning statistics. One of my biggest conceptual challenges was understanding a random variable and what a PDF/PMF actually meant. It was only in my second term, 1/2 way through learning about Confidence Intervals did I have any idea what was being discussed. The most helpful part of the course was learning R and producing graphs and visuals. I feel if more statistics classes used visuals like above, students would have a better intuition of what was happening.

18 May, 2016 at 12:41 am

1 – Visualising random variables[…] Source:https://terrytao.wordpress.com/2016/05/13/visualising-random-variables/ […]

18 May, 2016 at 1:25 pm

Jessica HullmanI’m a visualization researcher who has been studying how people understanding distributions through (visualized) hypothetical outcomes for a few years now. We call them hypothetical outcome plots, or HOPs, and have shown how people can interpret plots of two quantities better than they can a pair of error bars or other visual representations of a pdf like violin plots. We’ve written a blog post here: https://goo.gl/eORypw, and you can find more materials here: http://idl.cs.washington.edu/papers/hops. I also just gave a talk at OpenVis 2016 on the same basic idea: https://www.youtube.com/watch?v=pTVAn4oLvbc

22 May, 2016 at 7:30 am

vznvznnice topic, think that scientific visualizations are sometimes somewhat underutilized. is there a ted talk on this? there should be. reminds me of edward tufte who made nearly a career out of this topic, but not nec with newer technology. wish that tufte or a accolyte would revise his theory to the computer age. its a growing field. eg last comment by a “visualization researcher”. anyway the area of algorithm teaching has a lot of visualization possibilities that imho are still largely unexplored, lots of low hanging fruit. the classic example is sorting algorithms. some inquiry into all this in my “code” section on blog although its quite scattered right now. anyway keep up the good work. :)

23 May, 2016 at 5:23 am

MatjazGYour inquiry led me to a search around YouTube for a bit and I indeed found a very nice TEDx talk on scientific visualization: https://www.youtube.com/watch?v=Sua0xDCf8MA. Highly recommended :)

About sorting algorithms, though: those have had nice visualizations on Wikipedia for a very long time. E.g. I just checked and the animated visualization of Quicksort has been unchanged for 10 years now. Similarly for the Dijsktra’s and the A* search algorithms, which have had animated visualizations on Wikipedia for at least 5 years. I agree, though, that a nice visualization makes things so much cleared and more intuitive. Which algorithms would you like to see visualized?

23 May, 2016 at 4:54 pm

vznvznforgot to mention, there is ongoing/ active research in many visualization areas eg number theory, one of my personal favorites, wrt collatz, but Riemann has been visualized a lot also & continues to crosspollinate conventional/ technical approaches. more on Collatz https://vzn1.wordpress.com/code/collatz-conjecture-experiments/ … btw one also wonders if greats of the field have special “internal” visualization powers … eg Ramanujan etc … see my blog for pointers to great latest movie on him :)

24 May, 2016 at 9:58 am

Visualising random variables, Terence Tao style « Probability and statistics blog[…] mathematician Terence Tao posted some ruminations on how to visualize the different values a random variable could take. He created some basic animated loops that cycled through some samples from the distribution, and […]

24 May, 2016 at 10:03 am

statisticsblogdotcomI liked this idea so much I’ve added it to my probability distributions library:

http://statisticsblog.com/probability-distributions/#visualize

The values can be shown directly, or interpreted as waiting times where each arrival is shown with a flashing symbol. There are a number of options for how to display the animation and you suppress values that fall outside of a given range (conditionality).

28 May, 2016 at 9:05 pm

Máté WierdlWhat would be useful is to visualize/animate some basic statements in probability.

1) In case of a random walk, the distance from the expectation is about the square root of the number of steps.

2) In case of random walk, the distribution of the various values, properly normalized, approaches the Gaussian.

29 May, 2016 at 8:18 am

Terence TaoWell, the Galton box is a well known demonstration of both (1) and (2), and has often been animated in the past, e.g. https://rosettacode.org/wiki/Galton_box_animation

3 July, 2016 at 9:31 pm

Visualising random variables, Terence Tao style | A bunch of data[…] mathematician Terence Tao posted some ruminations on how to visualize the different values a random variable could take. He created some basic animated loops that cycled through some samples from the distribution, and […]

14 October, 2016 at 9:39 pm

davidwlockeRandom variables are distributions. Deterministic variables are single numbers. I don’t see how a series displayed one at a time enables me to visualize the underlying distribution. Both could be shown in a single graphic. The deterministic variable would be represented by a vertical line somewhere in the distribution.

In a Poisson distribution, the deterministic variable would appear as a single and only bar in a histogram. Constraints on either side of that bar would eliminate the rest of the distribution.

If you still wanted to show each value as it was “measured” build the distribution as each value arrives. Use nominal events to build more complex events. Put the nominal RV1 value in its distribution. Then, build the aggregated event (RV2) putting that value in its own distribution.

11 January, 2017 at 1:15 am

De la Statistique Descriptive à la Statistique Mathématique | A bunch of data[…] des majuscules (correspondant aux variables aléatoires sous-jacentes). Il y a quelques mois, Terry Tao suggérait d’aller un cran plus loin, en notant qu’une variable aléatoire était justement […]

4 February, 2019 at 10:59 am

Andres MatosThis sounds like a basis of nudge theory; at the very least, it reminds me of it. I am still new at this so correct me if I am wrong. Here is how I see it: The Z’=7-X is the nudge creating that strong correlation between X and Z’ leading to the expected behavior, or at least an increased chance of it.