Probability for Computer Scientists
Probability, Artificial Intelligence, and Counting
Probability as a foundation for computing and decision-making
Probability provides a mathematical way to reason about uncertainty. It helps describe what may happen, interpret evidence, and update beliefs when new information becomes available. In computer science, probabilistic reasoning appears in machine learning, algorithms, recommendation systems, and decisions made with incomplete information.
Probability is useful beyond artificial intelligence. It can help explain how algorithms perform, how long a process may take, or which action is sensible when the result is uncertain. A sound understanding of probability also helps people assess claims that are expressed in probabilistic terms.
How artificial intelligence approaches changed
Early artificial-intelligence research was highly optimistic. Researchers expected that computers could quickly perform tasks requiring human-level intelligence. Some early successes—such as computers playing checkers and proving mathematical theorems—encouraged the idea that intelligence could be built by writing down the necessary rules.
A prominent version of this approach was symbolic AI: developers tried to represent knowledge explicitly through rules and symbols. Translation illustrates the difficulty. A system might attempt to translate a sentence by applying a large collection of grammatical and linguistic rules. Yet a phrase such as “the spirit is willing, but the flesh is weak” could be translated back as something like “the vodka is good, but the meat is rotten.” The system’s failure reflects the complexity, ambiguity, and context-dependence of language. Writing enough rules to cover every case proved far harder than early expectations suggested.
This gap between ambitious predictions and actual capabilities contributed to periods of reduced confidence and investment, often called AI winters. The broader lesson is that apparently simple human abilities can depend on enormous amounts of background knowledge and processing.
Later progress included increasingly capable systems in areas such as chess, autonomous driving, speech recognition, and question answering. Protein structure prediction became another important example: a system can use an amino-acid sequence to predict a protein’s three-dimensional structure, helping researchers study biology and develop treatments. AI also operates in familiar services, such as systems that help plan routes between locations.
The development of AI is not a steady march toward a final solution. New capabilities often make new problems visible. Progress in one area can create opportunities in another while leaving important challenges unresolved.
Classification: assigning examples to categories
A common machine-learning task is classification: given an input, assign it to one of a set of categories.
Examples include:
Classifying an image as a Chihuahua or a muffin.
Classifying a handwritten digit as one of the digits from 0 through 9.
Classifying a skin image as indicating cancer or not indicating cancer.
For a computer, an image begins as a collection of numerical pixel values. The computer must use those values to infer what the image represents. Humans may experience recognition as immediate, but it relies on substantial visual processing. What seems easy to a person can therefore be a difficult computational problem.
A useful classification system should aim to be accurate and should also be evaluated for fairness. Accuracy concerns how often its predictions are correct; fairness concerns whether its performance or effects are equitable across relevant groups. A system need not be perfect to be useful, but its limitations matter.
Neural networks as probabilistic models
A simplified model of a biological neuron receives inputs. Those inputs contribute to an internal signal, and the neuron fires when that signal is sufficiently strong. A computational neuron models this idea with weighted inputs and a mathematical function.
Suppose the inputs are x1,x2,…,xn and their corresponding weights are w1,w2,…,wn. The neuron combines them into a weighted sum and passes that sum through a function that constrains the output:
Here, b is a bias term, and σ is a nonlinear squashing function. The output can be interpreted as a score or, in suitable models, as a probability. For example, an output of 0.9 might represent a model’s estimated probability that an image belongs to a particular class.
A single computational neuron has limited capability. A neural network connects many such units, commonly in layers:
An input layer receives data, such as pixel values.
Hidden layers transform the inputs into increasingly useful representations.
An output layer produces predictions, such as probabilities for possible digit classes.
Each layer computes from the outputs of earlier layers. Combining many units can produce a model capable of representing complex relationships.
Why weights matter
The structure of a network does not by itself provide useful intelligence. Much of what the network learns is represented by its weights. Poorly chosen weights can produce poor predictions; well-adjusted weights can capture patterns that support useful predictions.
The weights are generally not chosen by manually inspecting every connection. Instead, the model learns from examples.
Learning from examples and minimizing error
In supervised learning, a model receives examples paired with their correct labels. For instance, it may see an image labeled as a 0 and produce a prediction that it is a 1. The difference between the model’s prediction and the correct answer can be measured by a loss function.
The learning process aims to adjust the weights so that the loss becomes smaller:
The model makes a prediction for an example.
The prediction is compared with the correct label.
A loss value measures how wrong the prediction was.
The model calculates how changes to its weights would affect the loss.
The weights are adjusted to reduce the loss.
The process is repeated over many examples.
In mathematical terms, the model seeks weight changes that reduce the loss. Derivatives describe how the loss changes with respect to each weight; these derivatives guide the updates. A quantity such as ∂wi∂L describes the sensitivity of loss L to weight wi.
Over many examples, these updates can make the model’s predictions more useful. The central idea is that a model can improve through experience rather than relying on people to write every rule that governs the task.
Modern generative AI and probability distributions
Generative systems can use a prompt to produce new content. For example, an image-generation system can take a text description and produce images that fit it.
A simplified probabilistic view is:
The system interprets the text prompt.
It represents a distribution over images related to that prompt.
It samples an image from that distribution.
The generated image is not necessarily a photograph retrieved from the internet. It can be a newly constructed result produced by the model. In this framing, probability connects the prompt to a range of plausible outputs, while computation makes it possible to sample from that range.
Generative systems illustrate how probability and programming work together: probability represents uncertainty over possible outputs, and algorithms carry out the computations needed to produce one.
What AI can do—and what remains difficult
Machine-learning systems can perform striking tasks, but they do not solve every problem. A contrast is one-shot learning: recognizing a new symbol after seeing only one example. People can often generalize from a single example, while many machine-learning systems need very large collections of examples to learn a category reliably.
This difference highlights that machine intelligence remains incomplete. Success on a task such as classification does not imply that a system can learn in the flexible, data-efficient way that people often can.
Probabilistic reasoning is also useful in areas that are not usually described as deep learning. Recommendation systems, for example, can use conditional probabilities to estimate which items a person may prefer. Probability can also help analyze the expected behavior and running time of algorithms.
Applications and social responsibilities
Probabilistic and machine-learning tools can support work in many fields:
Medicine: identifying patterns related to heart disease or cancer.
Entertainment: estimating which films or other media a person may like.
Biology: analyzing DNA data and predicting protein structures.
Computer science: analyzing algorithms and improving their efficiency.
Decision-making: comparing possible actions when outcomes are uncertain.
Technology policy: assessing fairness, appropriate use, and potential misuse.
Technical ability is not the only consideration. As AI becomes more influential, people also need to understand how systems could be used incorrectly, how their effects may differ across groups, and how ethical principles may be reflected in laws and other rules. Building useful technology and evaluating its consequences are connected responsibilities.
Adaptive eye testing as a probabilistic decision problem
A conventional eye test often presents letters in a fixed sequence. A more adaptive test can use the answers already given to estimate how well a person can see.
The process can be understood as maintaining a belief distribution over possible levels of visual acuity:
The test begins with uncertainty about the person’s visual ability.
It presents a letter and records whether the person identifies it correctly.
That evidence updates the estimated distribution over visual ability.
The test selects the next letter based on the updated estimate.
The process continues until the estimate is sufficiently precise.
The choice of the next letter is a decision made under uncertainty. A carefully selected prompt can provide more useful information than simply following a fixed sequence. The result can be a test that is both more accurate and shorter.
This example shows how probability can turn a measurement problem into an adaptive algorithm: evidence updates a model of the person, and that model guides what to do next.
Bayes’ rule and the importance of base rates
A test result is not the same thing as the truth it is meant to detect. A positive result does not automatically mean that a person has a disease. The probability of disease after a positive test depends on at least three factors:
The probability that a randomly selected person has the disease, called the prior probability or base rate.
The probability of a positive result when the person has the disease, called the sensitivity.
The probability of a positive result when the person does not have the disease, called the false-positive rate.
Let D mean that a person has a disease and + mean that the test is positive. Bayes’ rule gives:
Suppose a test returns a positive result for 90% of people who have the disease and for 7% of people who do not. Even with those test characteristics, the chance that a person has the disease after a positive result can still be low when the disease is rare. For example, a prior prevalence of about 0.76% yields a posterior probability close to 9%.
The reason is that, when the disease is rare, the much larger group without the disease can produce many false positives. Therefore, the test’s accuracy among people who have the disease cannot be considered by itself. The base rate must also be taken into account.
As more evidence becomes available, probability provides a systematic way to update beliefs. A new test, symptom, or observation can be incorporated into the current estimate rather than being treated as an isolated fact.
Counting as a foundation for probability
Probability often begins with counting possible outcomes. Counting also appears throughout computer science—for example, when determining how many cases an algorithm must process.
An experiment is an action or process that can produce an outcome. The collection of all possible outcomes is its outcome space. An event is a set of outcomes satisfying a condition. For example, rolling a die is an experiment, and getting an even number is an event.
If a standard six-sided die is rolled, there are six possible outcomes: 1, 2, 3, 4, 5, and 6. The event of rolling an even number contains three outcomes: 2, 4, and 6.
Two fundamental counting strategies are:
Count a process as a sequence of steps, which typically leads to multiplication.
Count outcomes that can arise in one case or another, which typically leads to addition.
These strategies form the basis for many more advanced counting techniques.
The step rule: counting sequences of choices
Suppose an experiment has two steps. The first step has m possible outcomes, and, no matter which outcome occurs in the first step, the second step has n possible outcomes. Then the total number of outcomes is:
For several steps, the same principle extends by multiplying the number of choices at each step, provided the number of choices at each later step does not depend on which earlier choice was made:
The number of choices themselves may depend on earlier decisions in some problems. The rule still applies when the number of choices available at each step remains fixed, even if the particular choices differ.
Example: rolling two dice
The first die has 6 possible outcomes. For each of those outcomes, the second die also has 6 possible outcomes. Thus, the pair of rolls has:
possible outcomes.
Example: colors and pixel images
A pixel represented with the red, green, and blue color channels has 256 possible values for each channel. Choosing a color can therefore be treated as three steps:
So a pixel can represent approximately 17 million colors.
An image with n independently chosen pixels has approximately 17 million choices for each pixel. The step rule gives:
For 12 pixels, this is:
That is far more than the often-estimated number of atoms in the observable universe, approximately 1080. This illustrates how quickly the number of possible combinations grows, even when each individual component has a finite number of possibilities.
Example: why a channel has 256 values
A color channel represented using 8 bits has 8 positions, each of which can be either 0 or 1. By the step rule, the number of possible patterns is:
The same principle explains why sequences of bits grow rapidly in number as their length increases.
The sum rule: counting mutually exclusive alternatives
Suppose an outcome can arise from set A or set B, and no outcome belongs to both sets. Such sets are mutually exclusive. If A contains ∣A∣ outcomes and B contains ∣B∣ outcomes, the total number of outcomes is:
For example, if an object belongs either to a category containing 2 objects or a separate category containing 3 objects, and the categories do not overlap, there are 2+3=5 objects altogether.
The sum rule is useful when a problem offers alternative cases, but the cases must not overlap. If the same outcome appears in both cases, simply adding their sizes counts that outcome twice.
Inclusion–exclusion: correcting for overlap
When sets A and B overlap, their shared outcomes are counted once in ∣A∣ and again in ∣B∣. To correct for that double counting, subtract the size of the intersection:
This is the inclusion–exclusion principle for two sets. It allows outcomes to be counted by alternatives even when some outcomes satisfy more than one case.
Example: six-bit strings
A six-bit string is a sequence of six values, each either 0 or 1. Consider strings that:
Start with 01, or
End with 10.
For strings starting with 01, the first two positions are fixed and the remaining four positions are free. Each free position has 2 choices, so there are:
such strings.
For strings ending with 10, the final two positions are fixed and the first four are free. There are also:
such strings.
However, some strings meet both conditions. Such a string has the form 01__10: the first two and last two positions are fixed, while the two middle positions are free. The overlap therefore contains:
strings. Applying inclusion–exclusion gives:
Thus, there are 28 six-bit strings that start with 01 or end with 10.
Counting arrangements and repeated elements
Arrangements can also be counted by the step rule.
If four distinct letters are arranged in a row, there are 4 choices for the first position, 3 remaining choices for the second, 2 for the third, and 1 for the last:
Although the specific choices available change after each selection, the number of choices at each step is fixed. The step rule therefore applies.
When some letters are repeated, counting all letters as distinct would count the same visible arrangement multiple times. For BOBA, there are 4! arrangements if the two copies of B are temporarily treated as distinct. Swapping those identical copies does not create a new visible arrangement, so each arrangement has been counted 2! times. The number of unique arrangements is:
More generally, if there are n total items, with repeated groups of sizes n1,n2,…,nr, the number of distinct arrangements is:
For MISSISSIPPI, there are 11 letters: 1 M, 4 I’s, 4 S’s, and 2 P’s. The number of distinct arrangements is:
The step rule, the sum rule, and inclusion–exclusion provide a foundation for these and many other counting problems. Counting the possible outcomes carefully is also a foundation for assigning and reasoning about probabilities.

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