29 Mar 2025, 4:39 PM
06 Apr 2025, 1:37 PM

Quests about Random Variables

1. Distance to the Hogwarts Express

You are tracking the distance to the Hogwarts Express. A magical instrument reports it’s 100 leagues away. Before the reading, your belief about the distance D was a Gaussian DN(µ=98,σ2=16). The instrument’s reading is the true distance plus Gaussian noise (N(0,4)).

a. What is the PDF of your prior belief of the train’s true distance?

The Probability Density Function of the prior belief about the train's true distance is given by the Gaussian distribution with µ=98 and σ2=16, that is f(x)=142πe(x98)232.

b. What is the probability density of seeing a reading of 100 leagues, given the true distance is t?

Let's call R the random variable that represents seeing a reading of r pages, in this case 100. In shorts, we have to compute P(R=100 | D=t), where R, as stated in the text, is the true distance plus a Gaussian noise (N(0,4)). This means that the distribution of R is t+N(0,4)=N(t,4). Then:

P(R=100 | t)=122πe(100t)28

c. What is the PDF of your posterior belief (after the reading) of the train’s true distance? (You can leave a constant and don’t need to simplify).

In shorts, we have to compute P(D=t | R=100). We can calculate this using Bayes' Theorem, that is:

P(D=t | R=100)=P(R=100 | D=t)×P(D=t)P(R=100)

Since the question allows us to leave a constant:

P(D=t | R=100)=C×P(R=100 | D=t)×P(D=t)

We have already found P(D=t) in part (a) and P(R=100 | D=t) in part (b), so we have only to substitute:

P(D=t|R=100)=C×122πe(100t)28×142πe(t98)232

We can combine the constant terms into a single proportionality constant:

P(D=t|R=100)=C×e(100t)28×e(t98)232=C×e(100t)28(t98)232

2. Owls arrival in Owlery

On average, 5.5 owls arrive at the Owlery per minute. What is the probability that:

a. More than 7 owls will arrive in the next minute?

First, we decide to model the owl arrivals using a Poisson distribution, since we're looking at the number of events (owl arrivals) occurring in a fixed interval of time, given a known average rate of occurrence, and assuming the events happen independently.
The Probability Mass Function (PMF) for a Poisson distribution is:

P(X=k)=λkeλk!

In this case, we want to compute P(X>7)=1P(X7), where λ=5.5.
Let's do that:

P(X>7)=1P(X7)=1k=07e5.5(5.5)kk!=0.19051

b. More than 13 owls will arrive in the next 2 minutes?

The idea is the same as before, but note that the rate is λ=5.5 owls per minute; therefore, for this case, λ=5.5×2=11. As before:

P(X>13)=1P(X13)=1k=013e11(11)kk!=0.21870

c. More than 15 owls will arrive in the next 3 minutes?

The idea is the same as before, but note that the rate is λ=5.5 owls per minute; therefore, for this case, λ=5.5×3=16.5. As before:

P(X>15)=1P(X15)=1k=015e16.5(16.5)kk!=0.58198

3. Finding the median of a random variable

The median of a continuous random variable (like the height of a gnome) having cumulative distribution function F is the value m such that F(m)=0.5. Find the median of X (in terms of distribution parameters) if:

a. XUni(a,b) (Uniform distribution, like the spread of Floo powder).

For a uniform distribution, the CDF is given by:

F(x)=xabafor axb

Setting F(m)=0.5:

maba=0.5ma=0.5(ba)

so

m=a+0.5(ba)=a+b2

b. XN(µ,σ2) (Normal distribution, like scores on the O.W.L.s).

A normal distribution is symmetric about its mean, thus the median is equal to the mean:

m=μ

4. A visit to the Hogwarts library

Let Xi be the number of students visiting the Hogwarts library in week i, where XiN(2200,52900). Assume weekly visits Xi are independent.

a. What is the probability that the total number of visitors in the next two weeks exceeds 5000?

First, we can define the total number of visitors over two weeks as S=X1+X2, and since the sum of independent normal variables is a normal, SN(2200+2200,52900+52900)=N(4400,105800).

We only need to calculate P(S>5000), using Python or using the integral, that is 0.0325.

b. What is the probability that the weekly number of visitors exceeds 2000 in at least 2 of the next 3 weeks?

Let's first compute the probability that the number of visitors exceeds 2000 for any given week:

P(Xi>2000)=10200012π52900exp((x2200)2252900) dx=0.8077.

Now, let's call Y be the number of weeks (out of 3) with more than 2000 visitors.
Surely, Y follows a binomial distribution with 3 trials and p=0.8078.

Let's compute it:

P(Y2)=P(Y=2)+P(Y=3)=(32)(0.8078)2(10.8078)+(33)(0.8078)3=3(0.8078)20.1922+(0.8078)3=0.9033

5. Distribution of magical power levels of three Hogwarts students

Let X, Y , and Z be independent random variables representing the magical power levels of three Hogwarts students, where XN(µ1,σ12) (Gryffindor), YN(µ2,σ22) (Hufflepuff), and ZN(µ3,σ32) (Ravenclaw).

a. Let A=X+Y. What is the distribution of the combined power A?

For any two independent normal random variables XN(µ1,σ12) and YN(µ2,σ22) the sum of those two random variables is another normal: A=X+YN(μ1+μ2,σ12+σ22).

b. Let B=5X+2. What is the distribution of B (perhaps after a powerenhancing charm)?

If X is a Normal such that XN(μ,σ1) and B is a linear transform of X such that B=aX+b then B is also a Normal where: BN(aμ+b,a2σ2), then BN(5μ+2,25σ2).

c. Let C=aXbY+c2Z, where a, b, and c are real-valued constants representing spell modifiers. What is the distribution (and parameters) for C? Show how you derived your answer.

As before, C is a normal. Let's start by calculating its mean, that is simply E[C]=aμ1bμ2+c2μ3

Let's now calculate the variance. Rember that the variance is not linear like expectation: Var(aX)=a2Var(X).
Then Var(C)=a2σ12+b2σ22+(c2)2σ32=a2σ12+b2σ22+c4σ32

Putting all together: CN(aμ1bμ2+c2μ3,a2σ12+b2σ22+c4σ32)

6. A strange probability density function

The joint probability density function of continuous random variables X (skill in Potions) and Y (skill in Charms) is given by fX,Y(x,y)=cyx where 0<y<x<1.

a. What is the value of c for this to be a valid probability density function?

To be a valid PDF, the total integral over the region must equal 1:

x=01y=0xcyxdydx=1

Let's compute the inner integral first:

y=0xyxdy=1x0xydy=1x[y22]0x=1xx22=x2

Now substitute into the outer integral:

x=01cx2dx=c01x2dx=c[x24]01=c14

Set this equal to 1:

c14=1c=4

b. Are Potion skill (X) and Charm skill (Y) independent? Explain.

Two variables X and Y are independent if

fX,Y(x,y)=fX(x)fY(y)

Let's compute first the marginal density function of X:

fX(x)=y=0xfX,Y(x,y)dy=0x4yxdy=4x0xydy=4xx22=2x

Now the marginal density function of Y:

fY(y)=x=y1fX,Y(x,y)dx=y14yxdx=4yy11xdx=4y[lnx]y1=4y(ln1lny)=4ylny

In the previous answer we discovered that fX,Y(x,y)=4yx, thus we can conclude that:

4yx8xyln(y)

The answer is no, X and Y are not independent.

c. What is the marginal density function of X?

We have computed it in the previous answer:

fX(x)=y=0xfX,Y(x,y)dy=0x4yxdy=4x0xydy=4xx22=2x

d. What is the marginal density function of Y?

We have computed it in the first answer:

fY(y)=x=y1fX,Y(x,y)dx=y14yxdx=4yy11xdx=4y[lnx]y1=4y(ln1lny)=4ylny

7. Choosing random house points

Choose a number X at random from the set of house points {1,2,3,4,5,6} awarded by Professor McGonagall. Now choose a number Y at random from the subset of points no larger than X, {1,...,X}.

a. Determine the joint probability mass function of X (initial points) and Y (second random selection).

Let's discuss about the random variable X.
X is uniformly distributed over {1,2,3,4,5,6}, thus:

P(X=x)=16for x{1,2,,6}

Now the random variable Y.
Given X=x, Y is uniformly distributed over {1,2,,x}, thus:

P(Y=yX=x)=1xfor yx

Putting all together:

P(X=x,Y=y)={161xif 1yx6,0otherwise

b. Determine the conditional mass function P(X=j|Y=i) as a function of i and j.

Using Bayes’ rule:

P(X=jY=i)=P(Y=iX=j)P(X=j)P(Y=i)

From the answer before, we know that P(Y=iX=j)=1j, while P(X=j)=16.

We need to compute the denominator P(Y=i), that is:

P(Y=i)=j=i6P(X=j,Y=i)=j=i616j

So putting it all together:

P(X=jY=i)=16jk=i616k=1jk=i61kfor ij

c. Are X and Y independent? Explain.

No, the value of Y is constrained by X (YX), so knowledge of Y affects the possible values of X. More formally, if X and Y are independent:

P(X=j,Y=i)=P(X=j)P(Y=i)for all i,j

From part (a) we have:

Finally:

P(X=j)P(Y=i)=16k=i616k16j

We can confirm that X and Y are not independent.