Skip to content
advanced

Update a Bayesian Model of an Opponent’s Actions

Frequency counting answers with a single number and no error bar. It cannot tell you how much evidence you actually have, and it has no place to put what…

Published 2026-10-02Updated 2026-10-0412 min read
A child focuses on a chess game with blurry background outdoors.
A child focuses on a chess game with blurry background outdoors. Photo by Engin Akyurt on Pexels.

Four identical actions in a row. Is that a tendency or a coincidence?

Frequency counting answers with a single number and no error bar. It cannot tell you how much evidence you actually have, and it has no place to put what you already believed before the first observation. The fix is to stop tallying actions and start maintaining a belief over the opponent's action distribution. That belief has a two-line update rule, a predictive probability you can compute on paper, and exactly one assumption holding it together.

This article assumes you already accept that predicting another learner can improve adaptation. The question here is narrower and more mechanical: how do you represent that prediction as a probability distribution, and how does it change when new actions arrive?

What You Are Actually Estimating

Before any notation, fix the target. You are not modeling a sequence of decisions. You are modeling the opponent as a fixed conditional distribution over actions — a single object that generates every action it takes.

The unknown quantity is the parameter vector of that distribution, not the next action. This distinction matters because it changes what your belief is about. The opponent's action is sampled; the parameter is inferred. You observe the sample, and you reason backward to the thing that produced it.

Two assumptions make this tractable, and you should name them now because the last section dismantles the first:

  • Stationarity. The opponent's action distribution does not change over the horizon you care about.
  • Independence. The opponent's strategy does not depend on your behavior.

Both are strong. Both are also the reason the update stays closed-form and cheap. Hold that trade in mind.

Notation and the Categorical Likelihood

Let the opponent choose from an action set of size KK. Index actions 11 through KK. The parameter vector is

θ=(θ1,…,θK),θk≥0,∑k=1Kθk=1.\theta = (\theta_1, \dots, \theta_K), \quad \theta_k \ge 0, \quad \sum_{k=1}^{K} \theta_k = 1.

Each θk\theta_k is the probability the opponent plays action kk. The constraint is not decoration — it defines the space the parameter lives in, and the prior you choose later has to respect it.

The likelihood of a single observed action at=ka_t = k is just the matching entry:

P(at=k∣θ)=θk.P(a_t = k \mid \theta) = \theta_k.

For a sequence of TT independent actions, the likelihood is a product:

P(a1:T∣θ)=∏t=1Tθat=∏k=1Kθknk,P(a_{1:T} \mid \theta) = \prod_{t=1}^{T} \theta_{a_t} = \prod_{k=1}^{K} \theta_k^{n_k},

where nkn_k is the number of times action kk appeared. That last step is the important one: the product collapses into counts per action. The likelihood depends only on n1,…,nKn_1, \dots, n_K, not on the order in which the actions arrived.

Order-independence is a real modeling commitment, not a convenience. It is precisely what stationarity buys you. If the opponent's distribution were drifting, the order would carry information, and collapsing to counts would throw it away. For now, assume it does not drift. This count vector is the sufficient statistic — everything the data can tell you about θ\theta is already in it.

The multinomial distribution is the general form for TT draws; the categorical is the single-draw case. You will use the categorical likelihood above and the multinomial when you batch observations.

Knowledge check

Check your understanding

Answer this question before you continue.

Under the article’s independent, stationary categorical model, why can the likelihood be written using only the count of each action?
Single Choice

Focus: Explain why action counts are sufficient for the stated categorical model.

Why the Dirichlet Prior Fits

You need a prior over θ\theta. The Dirichlet distribution is the natural choice, for two reasons.

First, its support is the simplex — the same constrained space θ\theta lives in. The prior never assigns probability mass to parameter vectors that violate ∑kθk=1\sum_k \theta_k = 1. A Gaussian prior would, and you would spend effort correcting for it.

Second, each Dirichlet parameter behaves like a prior observation count. Write the prior as

P(θ∣α)∝∏k=1Kθkαk−1,P(\theta \mid \alpha) \propto \prod_{k=1}^{K} \theta_k^{\alpha_k - 1},

with concentration parameters α=(α1,…,αK)\alpha = (\alpha_1, \dots, \alpha_K), each αk>0\alpha_k > 0. Read αk\alpha_k as "how many times I have already seen action kk before collecting any data." A uniform prior with all αk=1\alpha_k = 1 is a weak belief. A prior with α1=50\alpha_1 = 50 and the rest at 11 is a confident claim that action 11 dominates, and it will resist contradicting data.

The third reason is conjugacy: the Dirichlet is the conjugate prior for the categorical and multinomial likelihoods. Multiply the two and you get another Dirichlet. That is what keeps the update closed-form.

Note: A bad prior is not wrong. It is slow to be corrected. If you set α1\alpha_1 high and the opponent actually favors action 22, your posterior will lag reality for many observations. That lag is the visible cost of an overconfident prior, and it shows up as delayed adaptation.

Knowledge check

Check your understanding

Answer this question before you continue.

Which feature makes the Dirichlet prior’s support match the categorical parameter θ?
Comparison Reasoning

Focus: Identify why the Dirichlet distribution is a suitable prior for categorical probabilities.

Deriving the Posterior Update

Now the Bayes step, done explicitly so you can see where the addition comes from.

The posterior is likelihood times prior, normalized:

P(θ∣a1:T)=P(a1:T∣θ) P(θ∣α)P(a1:T∣α).P(\theta \mid a_{1:T}) = \frac{P(a_{1:T} \mid \theta)\, P(\theta \mid \alpha)}{P(a_{1:T} \mid \alpha)}.

Substitute both pieces. The likelihood contributes ∏kθknk\prod_k \theta_k^{n_k} and the prior contributes ∏kθkαk−1\prod_k \theta_k^{\alpha_k - 1}. Multiply them — the exponents add:

P(θ∣a1:T)∝∏k=1Kθknk+αk−1.P(\theta \mid a_{1:T}) \propto \prod_{k=1}^{K} \theta_k^{n_k + \alpha_k - 1}.

That is a Dirichlet with updated parameters. Name them:

αk′=αk+nk.\alpha_k' = \alpha_k + n_k.

The posterior concentration equals the prior concentration plus the observed count, per action. That is the whole update. No iteration, no gradient, no tuning.

The normalizing constant is a ratio of beta functions, B(α)/B(α′)B(\alpha)/B(\alpha'), and you almost never compute it for prediction — the proportionality is enough.

Read the update as a ledger. Prior counts on one side, evidence counts on the other, sum them. The posterior mean is

E[θk∣a1:T]=αk′∑j=1Kαj′=αk+nk∑j(αj+nj).\mathbb{E}[\theta_k \mid a_{1:T}] = \frac{\alpha_k'}{\sum_{j=1}^{K} \alpha_j'} = \frac{\alpha_k + n_k}{\sum_j (\alpha_j + n_j)}.

Warning: If you set some αk=0\alpha_k = 0, the prior assigns zero mass to that action, and if you never observe it, the posterior keeps it at zero forever. No amount of other evidence revives it. That is a modeling choice with permanent consequences — avoid zero concentrations unless you genuinely mean "impossible."

Knowledge check

Check your understanding

Answer this question before you continue.

A three-action model has prior parameters α = (2, 3, 1) and observes counts n = (1, 0, 4). What are the posterior parameters?
Single Choice

Focus: Derive posterior Dirichlet parameters by combining prior parameters with action counts.

Worked Example: Three Actions, Six Observations

Three linked stages show prior alpha (2, 1, 1) plus observed counts (4, 1, 1) producing posterior alpha (6, 2, 2), then normalization by 10 to give predictive probabilities (0.60, 0.20, 0.20).
Adding action counts updates the Dirichlet parameters; normalizing them gives the next-action prediction.

Let K=3K = 3. Choose a deliberately weak, slightly asymmetric prior so you can see its influence without it dominating:

α=(2,1,1).\alpha = (2, 1, 1).

The opponent plays the sequence: action 1, action 3, action 1, action 1, action 2, action 1. Tally the counts:

n=(4,1,1).n = (4, 1, 1).

Apply the update by addition:

α′=(2+4,  1+1,  1+1)=(6,2,2).\alpha' = (2 + 4,\; 1 + 1,\; 1 + 1) = (6, 2, 2).

The posterior mean is α′\alpha' divided by its total, which is 1010:

E[θ∣data]=(0.60,  0.20,  0.20).\mathbb{E}[\theta \mid \text{data}] = (0.60,\; 0.20,\; 0.20).

Compare that against the raw empirical frequency, n/T=(0.667,0.167,0.167)n / T = (0.667, 0.167, 0.167). The prior pulled action 1 down from 0.6670.667 to 0.600.60 and nudged the others up. That pull is the prior's weight showing through — small here, because the prior total is 44 against 66 observations.

The posterior predictive probability of the next action is the probability of that action given the data, integrating over your uncertainty about θ\theta:

P(aT+1=k∣a1:T)=∫P(aT+1=k∣θ) P(θ∣a1:T) dθ=αk′∑jαj′.P(a_{T+1} = k \mid a_{1:T}) = \int P(a_{T+1} = k \mid \theta)\, P(\theta \mid a_{1:T})\, d\theta = \frac{\alpha_k'}{\sum_j \alpha_j'}.

For this model, the predictive mean equals the posterior mean. So the next-action prediction is (0.60,0.20,0.20)(0.60, 0.20, 0.20).

Now add a second round. Suppose the opponent plays action 2 four more times. The new counts are n=(4,5,1)n = (4, 5, 1), and the posterior becomes

α′=(6,6,2),E[θ]=(0.429,0.429,0.143).\alpha' = (6, 6, 2), \quad \mathbb{E}[\theta] = (0.429, 0.429, 0.143).

The prior's pull has shrunk. With 1010 observations against a prior total of 44, the data now dominates. That is the behavior you want: weak priors get out of the way fast, strong priors do not.

ActionPrior αk\alpha_kObserved nkn_kPosterior αk′\alpha_k'Posterior mean
12460.60
21120.20
31120.20

Knowledge check

Check your understanding

Answer this question before you continue.

In the worked example, after the first six observations the posterior parameters are (6, 2, 2). What is the posterior predictive probability of action 2 on the next draw?
Output Prediction

Focus: Calculate a posterior predictive action probability from updated Dirichlet parameters.

Reading Uncertainty, Not Just the Mean

The mean is the headline. The spread is the story.

The total concentration ∑kαk′\sum_k \alpha_k' controls how peaked the posterior is. Two opponents can share an identical posterior mean with very different credible intervals. If one posterior is (60,20,20)(60, 20, 20) and another is (6,2,2)(6, 2, 2), both have mean (0.60,0.20,0.20)(0.60, 0.20, 0.20) — but the first is a confident belief and the second is a shrug.

Here is the part that trips people up. For this model, the one-step posterior predictive probabilities are exactly the posterior mean, regardless of concentration. Both posteriors above predict the next action with the same (0.60,0.20,0.20)(0.60, 0.20, 0.20) vector. Concentration does not change that vector.

What concentration changes is your uncertainty about the parameters, and that matters for decisions in a different way. A narrow posterior means you are confident the opponent's true θ\theta is near (0.60,0.20,0.20)(0.60, 0.20, 0.20). A wide posterior means the true θ\theta could be anywhere in a broad region — the mean is just its center of mass. If you exploit the mean aggressively, you are betting that the true distribution is close to it. That bet is cheap when the posterior is narrow and expensive when it is wide.

So the honest statement is this: the predictive vector tells you what to expect on the next draw; the posterior width tells you how much to trust that expectation when you act on it. Risk-sensitive planning and value-of-information calculations use the width. A greedy action selection that only reads the predictive vector ignores it.

Common mistake: Assuming that a wide posterior produces a "flatter" predictive distribution. It does not. A wide posterior centered on the same mean produces the same one-step predictive. The width shows up in multi-step predictions, in risk, and in how much a single new observation can move your belief — not in the next-action probability vector.

When the Stationary Assumption Breaks

Everything above rests on the opponent's distribution being fixed. Here is what happens when it is not.

Policy drift. The opponent's true θ\theta changes while your posterior keeps accumulating counts. Old evidence is silently weighted as if it were current. Your model becomes a historian of a strategy that no longer exists.

Strategic response. The opponent conditions on your behavior. This violates independence directly: the likelihood P(at∣θ)P(a_t \mid \theta) assumes the opponent's action does not depend on yours, and now it does. The model is misspecified, and no amount of data fixes a wrong likelihood.

The diagnostic signature is specific and worth memorizing: the posterior becomes confidently wrong. It narrows and centers on a stale value. This is worse than being uncertain, because a narrow wrong belief drives aggressive exploitation of a pattern that has already changed. Uncertainty keeps you cautious; false confidence gets you punished.

Mitigations exist, each with a cost:

ApproachMechanismCost
Exponential forgettingDecay old counts by a factor each stepTrades sample efficiency for responsiveness
Windowed countsKeep only the last WW observationsDiscards potentially useful history
Change-point / switching modelExplicitly model regime changesMore parameters, more inference

Each buys responsiveness by giving up the statistical efficiency that came from pooling all history. That is the real trade: the stationary model is sample-efficient precisely because it trusts old data, and that trust is what breaks under drift.

Common mistake: Reaching for a forgetting factor before confirming the opponent is actually non-stationary. If the opponent is a fixed scripted policy, decayed counts just add noise to a model that was already correct. Diagnose drift first.

Where This Fits in a Multi-Agent Loop

The posterior is a belief state. It summarizes what you know about the opponent in a fixed-size vector, and you feed it into planning or value estimation as an input feature. It does not replace your policy; it informs it.

Keep the prediction problem and the control problem separate. A good posterior does not automatically produce a good response — that is a second design decision about how aggressively to exploit what you believe.

And watch the coupling. If your policy exploits the posterior hard, you change the opponent's behavior, which invalidates the model you are exploiting. This is the loop that turns a clean Bayesian update into a moving target, and it is the reason opponent modeling in multi-agent reinforcement learning is harder than the single-agent case.

Natural extensions follow from here: condition the model on state, condition it on the opponent's information set, or replace the fixed prior with a hierarchical one over opponent types so the model can represent "this is one of several kinds of player" rather than one fixed distribution.

The Decision Rule

Use the Dirichlet-categorical model when the opponent is plausibly fixed within the horizon you care about. The update is two lines, the prediction is a division, and the uncertainty comes for free.

Switch to decayed counts or a switching model the moment you see a narrow posterior that keeps mispredicting. That symptom — confidence without accuracy — is the signal that stationarity has failed.

Here is your next move. Implement the update in a few lines: keep a count vector, add observations, divide by the total. Run it against a scripted opponent and confirm the posterior converges to the true distribution. Then run it against an opponent that changes strategy halfway through and watch the posterior lie to you with a straight face. The gap between those two runs is the entire lesson.

Knowledge check

Final check

Finish the article by checking the ideas you just learned.

Two posteriors have the same mean (0.60, 0.20, 0.20), but one has much greater total concentration. What follows for this model?
Question 1 of 2Misconception Check

Focus: Distinguish posterior parameter uncertainty from the one-step posterior predictive distribution.

An opponent changes its action distribution in response to your actions. Which assumption of the article’s likelihood is directly violated?
Question 2 of 2Scenario Interpretation

Focus: Diagnose which modeling assumption is violated when an opponent conditions actions on the learner’s behavior.

References

  1. Bayes' Bluff: Opponent Modelling in Pokerarxiv.org
  2. Opponent Modeling in Deep Reinforcement Learningproceedings.mlr.press
Practical resource

Build a stronger RL mental model

Use structured resources to connect equations, algorithms, and observable agent behavior.

Browse resources
Related sites

Continue across related AI foundations

Use LearnPyFast for Python foundations and LearnLLMFast for practical language-model and agent application concepts.

Python tutorialstutorial

LearnPyFast

Beginner-friendly Python tutorials, examples, and learning paths for practical programming foundations.

PythonProgrammingBeginners
Visit LearnPyFast
LLM tutorialstutorial

LearnLLMFast

Practical LLM tutorials for builders who want to understand prompting, workflows, agents, and AI applications.

LLMAIBuilders
Visit LearnLLMFast

Keep learning

Related reinforcement learning tutorials

Continue with nearby RL concepts, algorithms, and experiments that build on the same decision process.