1. Home
  2. Explore
  3. Computer Science
  4. Probability and Federalist Papers

Study methods

Flashcards
Quiz
Fill in the blanks
Written test
Lesson
Notes
Podcast
Content

Probability and Federalist Papers

Probabilistic Models and the Multinomial Distribution

Normal Distribution Review

The normal distribution is one of the most important continuous probability distributions. Its probability density function (PDF) has the classic bell-shaped curve. The cumulative distribution function (CDF), denoted F(x)=P(X≤x)F(x) = P(X \leq x)F(x)=P(X≤x), is monotonic increasing.

The key formula for computing probabilities with a normal random variable XXX with mean μ\muμ and variance σ2\sigma^2σ2 is:

P(X<x)=Φ(x−μσ)P(X < x) = \Phi\left( \frac{x - \mu}{\sigma} \right)P(X<x)=Φ(σx−μ​)

where Φ\PhiΦ is the CDF of the standard normal (mean 0, variance 1). The standard normal CDF is pre-computed and available in tables or computer functions.

Example: Server Capacity Planning for Singles Day

A real-world problem illustrates how to work backwards using the normal CDF. Alibaba's Singles Day (11/11) is their busiest shopping day. Assume the number of requests in the busiest minute follows a Gaussian distribution with mean μ=106\mu = 10^6μ=106 and standard deviation σ=104\sigma = 10^4σ=104. Each server can handle 10,000 requests. The goal is to buy enough servers so that the probability of not dropping any requests is greater than 0.99999.

Let RRR be the number of requests; we want rrr such that P(R<r)=0.99999P(R < r) = 0.99999P(R<r)=0.99999. Using the normal CDF:

P(R<r)=Φ(r−μσ)=0.99999P(R < r) = \Phi\left( \frac{r - \mu}{\sigma} \right) = 0.99999P(R<r)=Φ(σr−μ​)=0.99999

Apply the inverse Phi function (quantile function) on both sides:

r−μσ=Φ−1(0.99999)≈3.71902\frac{r - \mu}{\sigma} = \Phi^{-1}(0.99999) \approx 3.71902σr−μ​=Φ−1(0.99999)≈3.71902

Then solve for rrr:

r=μ+3.71902⋅σ≈106+3.71902×104=1,037,190 requestsr = \mu + 3.71902 \cdot \sigma \approx 10^6 + 3.71902 \times 10^4 = 1,037,190 \text{ requests}r=μ+3.71902⋅σ≈106+3.71902×104=1,037,190 requests

Number of servers needed = ⌈r/10,000⌉=⌈103.719⌉=104\lceil r / 10,000 \rceil = \lceil 103.719 \rceil = 104⌈r/10,000⌉=⌈103.719⌉=104 servers.

Key insight: For continuous random variables, P(R≤r)=P(R<r)P(R \leq r) = P(R < r)P(R≤r)=P(R<r) because the probability of any exact value is zero. This equality does not hold for discrete variables.


Logarithms and Counting Review

Logarithm Properties

The natural logarithm ln⁡(x)\ln(x)ln(x) (or simply log⁡(x)\log(x)log(x)) is the inverse of the exponential function: log⁡(ey)=y\log(e^y) = ylog(ey)=y and elog⁡x=xe^{\log x} = xelogx=x. Important properties for probability calculations:

  • log⁡(a⋅b)=log⁡a+log⁡b\log(a \cdot b) = \log a + \log blog(a⋅b)=loga+logb (product becomes sum)

  • log⁡(a/b)=log⁡a−log⁡b\log(a / b) = \log a - \log blog(a/b)=loga−logb

  • log⁡(ab)=b⋅log⁡a\log(a^b) = b \cdot \log alog(ab)=b⋅loga

These properties are crucial in computer science because multiplying many small probabilities (e.g., from a chain of events) leads to underflow — the computer cannot represent numbers that are extremely close to zero. Working in log-space (adding log probabilities) avoids this issue and is standard practice in probabilistic models.

Multinomial Counting

A counting problem that will appear in the multinomial distribution: Given nnn distinct objects, the number of ways to put n1n_1n1​ into bucket 1, n2n_2n2​ into bucket 2, ..., nrn_rnr​ into bucket rrr is:

n!n1! n2! ⋯ nr!\frac{n!}{n_1! \, n_2! \, \cdots \, n_r!}n1​!n2​!⋯nr​!n!​

This is also the number of distinct permutations of a multiset (e.g., the letters in "MISSISSIPPI").


💡 Introduction to Probabilistic Models

So far, course topics have focused on single random variables. Many interesting real-world problems involve multiple random variables simultaneously. For example, WebMD® uses symptoms (headache, dizziness) and diseases (migraine, stroke) — many random variables interacting.

Joint Probability Mass Function (PMF)

For two discrete random variables XXX and YYY, the joint probability mass function is:

pX,Y(x,y)=P(X=x,Y=y)p_{X,Y}(x,y) = P(X = x, Y = y)pX,Y​(x,y)=P(X=x,Y=y)

This gives the probability of a specific joint assignment — both variables taking particular values simultaneously. If you know the joint PMF, you can answer any probabilistic question about XXX and YYY.

Example: Dice Roll

Roll two fair six-sided dice. Let XXX be the outcome of the first die, YYY of the second. The joint PMF is constant:

pX,Y(x,y)=136p_{X,Y}(x,y) = \frac{1}{36}pX,Y​(x,y)=361​ for all x,y∈{1,2,3,4,5,6}x,y \in \{1,2,3,4,5,6\}x,y∈{1,2,3,4,5,6}.

Example: Student Year and Relationship Status

Real data from a CS109 class:

Year ↓ / Status →

Single

Relationship

Complicated

Freshman

0.02

0.08

0.01

Sophomore

0.05

0.13

0.02

Junior

0.10

0.10

0.03

Senior

0.08

0.09

0.02

5th year+

0.15

0.05

0.07

Each cell is the probability that a randomly selected student belongs to that year and that status. The sum of all 15 entries equals 1.

Properties of a joint PMF:

  • Each entry is a probability (0≤p≤10 \leq p \leq 10≤p≤1).

  • Sum over all possible (x,y)(x,y)(x,y) combinations equals 1.

  • Entries are mutually exclusive (a student cannot be both a freshman and a senior).

Marginalization

Suppose we want the probability that a student is in a relationship — we don't care about their year. From the joint table, we sum over all years:

P(Relationship)=∑yearP(year,Relationship)P(\text{Relationship}) = \sum_{\text{year}} P(\text{year}, \text{Relationship})P(Relationship)=∑year​P(year,Relationship)

This is called marginalization. The resulting distribution for a single variable (ignoring the others) is the marginal distribution.

Formally, for discrete XXX and YYY:

pX(x)=∑ypX,Y(x,y)p_X(x) = \sum_{y} p_{X,Y}(x, y)pX​(x)=∑y​pX,Y​(x,y)

The name "marginal" comes from the historical practice of writing the sums in the margins of the joint table.

Connection to Law of Total Probability: The law of total probability is the theoretical justification for marginalization. If {Bi}\{B_i\}{Bi​} partition the sample space, then P(A)=∑iP(A∩Bi)P(A) = \sum_i P(A \cap B_i)P(A)=∑i​P(A∩Bi​). Here AAA corresponds to "X = x" and BiB_iBi​ to "Y = y_i".

The Curse of Dimensionality: Large Joint Tables

Joint tables become exponentially large as the number of random variables grows. For example, with 3 variables:

  • DDD (disease): 2 values (0 or 1)

  • SSS (smell symptom): 2 values (no, yes)

  • FFF (fever status): 3 values (none, low, high)

Number of entries: 2×2×3=122 \times 2 \times 3 = 122×2×3=12. That's manageable. But for a realistic model like WebMD with 10 variables each taking 5 values, the table has 510=9,765,6255^{10} = 9,765,625510=9,765,625 entries — too many for a scientist to manually specify probabilities.

With 100 variables, 51005^{100}5100 is astronomical. Therefore, we need more efficient representations of the joint distribution, often by making simplifying assumptions (e.g., conditional independence).


📊 The Multinomial Distribution

The multinomial distribution is the generalization of the binomial distribution from 2 outcomes to mmm outcomes. It models the counts of each outcome in nnn independent trials, where each trial has mmm possible results with probabilities p1,p2,…,pmp_1, p_2, \dots, p_mp1​,p2​,…,pm​ (summing to 1).

Definition

Let X1,X2,…,XmX_1, X_2, \dots, X_mX1​,X2​,…,Xm​ be the random variables representing the number of times outcome iii occurs. Then the joint PMF is:

P(X1=c1,X2=c2,…,Xm=cm)=n!c1! c2! ⋯ cm!  p1c1p2c2⋯pmcmP(X_1 = c_1, X_2 = c_2, \dots, X_m = c_m) = \frac{n!}{c_1! \, c_2! \, \cdots \, c_m!} \; p_1^{c_1} p_2^{c_2} \cdots p_m^{c_m}P(X1​=c1​,X2​=c2​,…,Xm​=cm​)=c1​!c2​!⋯cm​!n!​p1c1​​p2c2​​⋯pmcm​​

where ∑i=1mci=n\sum_{i=1}^m c_i = n∑i=1m​ci​=n and ci≥0c_i \geq 0ci​≥0.

The multinomial coefficient n!c1!⋯cm!\frac{n!}{c_1! \cdots c_m!}c1​!⋯cm​!n!​ counts the number of distinct sequences (orderings) of the nnn trials that produce exactly c1c_1c1​ of outcome 1, c2c_2c2​ of outcome 2, etc.

Relation to Binomial

The binomial distribution is a special case with m=2m=2m=2: X1X_1X1​ = number of successes, X2=n−X1X_2 = n - X_1X2​=n−X1​, and p2=1−p1p_2 = 1 - p_1p2​=1−p1​. Then

n!c1!(n−c1)!p1c1(1−p1)n−c1\frac{n!}{c_1! (n-c_1)!} p_1^{c_1} (1-p_1)^{n-c_1}c1​!(n−c1​)!n!​p1c1​​(1−p1​)n−c1​

which matches the binomial PMF.

Example: Rolling 7 Dice

Roll 7 fair dice (each outcome probability =16= \frac{1}{6}=61​). Observe: one 1, one 2, zero 3's, two 4's, zero 5's, three 6's. The probability of this specific count vector is:

7!1! 1! 0! 2! 0! 3!(16)7\frac{7!}{1!\,1!\,0!\,2!\,0!\,3!} \left(\frac{1}{6}\right)^71!1!0!2!0!3!7!​(61​)7

The multinomial coefficient accounts for the different orderings of the dice rolls.

Application: Natural Language Processing

Documents can be modeled as multinomial draws from a "word dice". Each word in the document is a trial; there are as many outcomes as unique words in the vocabulary (≈ 1 million for English). The probability of each word is the relative frequency of that word in the language (or in a specific author's writing).

For a document of nnn words, the multinomial gives the probability of that exact word count vector under a given word probability distribution.

Example: Spam Detection

A spam email might contain the words "Viagra", "free", "click", "credit". The probability of seeing a particular multiset of words can be computed:

P(document)=n!∏wcw!∏wpwcwP(\text{document}) = \frac{n!}{\prod_w c_w!} \prod_w p_w^{c_w}P(document)=∏w​cw​!n!​∏w​pwcw​​

where cwc_wcw​ is the count of word www in the document, and pwp_wpw​ is the probability of word www according to a "spam language model" or a "normal English model". Comparing these probabilities helps classify the email.


🏛️ Application: Authorship of The Federalist Papers

The Federalist Papers (85 essays) were written under the pseudonym Publius by Alexander Hamilton, James Madison, and John Jay. Some essays have disputed authorship; particularly, Paper 53 was claimed by both Hamilton and Madison. The goal is to determine, based on word usage, who wrote it.

Data

  • Hamilton's known essays: a collection of text (counts of words)

  • Madison's known essays: another collection

  • Unknown.txt: Federalist Paper 53

We can estimate the probability that Hamilton (or Madison) would use a particular word by taking the relative frequency from their known works.

Probabilistic Model

We want P(Hamilton∣document)P(\text{Hamilton} \mid \text{document})P(Hamilton∣document) — the probability that Hamilton wrote the document given the observed word counts.

From Bayes' theorem:

P(H∣D)=P(D∣H) P(H)P(D)P(H \mid D) = \frac{P(D \mid H) \, P(H)}{P(D)}P(H∣D)=P(D)P(D∣H)P(H)​

Similarly for Madison. The term P(D∣H)P(D \mid H)P(D∣H) is the probability of the observed word counts under Hamilton's word distribution — exactly the multinomial PMF.

To avoid computing P(D)P(D)P(D) (the normalization constant), we can compare the ratio:

P(H∣D)P(M∣D)=P(D∣H) P(H)P(D∣M) P(M)\frac{P(H \mid D)}{P(M \mid D)} = \frac{P(D \mid H) \, P(H)}{P(D \mid M) \, P(M)}P(M∣D)P(H∣D)​=P(D∣M)P(M)P(D∣H)P(H)​

With equal priors (P(H)=P(M)=0.5P(H) = P(M) = 0.5P(H)=P(M)=0.5), this simplifies to:

P(H∣D)P(M∣D)=P(D∣H)P(D∣M)\frac{P(H \mid D)}{P(M \mid D)} = \frac{P(D \mid H)}{P(D \mid M)}P(M∣D)P(H∣D)​=P(D∣M)P(D∣H)​

If this ratio > 1, Hamilton is more likely; if < 1, Madison is more likely.

Furthermore, the multinomial coefficients cancel because they are identical for the same document:

P(D∣H)P(D∣M)=∏wpH,wcw∏wpM,wcw\frac{P(D \mid H)}{P(D \mid M)} = \frac{\prod_w p_{H,w}^{c_w}}{\prod_w p_{M,w}^{c_w}}P(D∣M)P(D∣H)​=∏w​pM,wcw​​∏w​pH,wcw​​​

where pH,wp_{H,w}pH,w​ is the probability Hamilton writes word www, and cwc_wcw​ is the count of word www in the unknown document.

The Problem: Zero Probabilities

When students computed these probabilities, both P(D∣H)P(D \mid H)P(D∣H) and P(D∣M)P(D \mid M)P(D∣M) came out as zero. This is because many words in the unknown document might not appear in the training data for that author, leading to pw=0p_{w}=0pw​=0 for some word. Multiplying by zero yields zero overall probability.

Key issue: The multinomial model cannot handle unseen words unless smoothing or other techniques are applied.

Preview of Solution

The mystery will be resolved on the next lecture day (Friday), likely by discussing smoothing (e.g., Laplace smoothing) to assign small non-zero probabilities to words not seen in the training data, allowing the product to be non-zero. This makes the model robust for real text analysis.

Ask anything

We've read this whole study set, so questions about it get the best answers.

FlashcardsQuizFill in the blanksWritten testLessonNotesPodcastContent