Statistics & probability

Generalized Polya urn calculator with a replacement matrix and exact draw distributions

Enumerate reinforced urn composition probabilities from initial counts and a color-specific replacement matrix.

Your numbers

Valid JSON.
Valid JSON; preserve the shown array or object structure.

Calculated on your device. Your inputs aren’t sent to us.

Your result

Ready when you are

Enter your inputs and select Calculate.

Report an issue

Behind the numbers

How this calculation works

A generalized Polya urn updates its composition after every random draw. The replacement matrix specifies which balls are added after each color appears, so later probabilities depend on the realized history.

THE FORMULAState DP overintegercompositioncountvectors c. Startingmass1 atc0. Drawcolori withprob c_i/sumc, then updatec←c+R_i (replacementrow isnetaddition afterdrawnballreturned). Rnonnegativeintegers forfirstversion. Aggregateequalstates exactlyusingrational probabilitiesor stablefloatwithmasscheck. Trackdrawcountvector as additionalstate only if finalcompositionnotinjective underR. Expectedfinalcomposition fromDP,notbalanceassumption. Finitecapabortwithoutpartialdistribution.

A worked example

With the prefilled inputs, expectedCounts = [2.5,2.5].

Good to know

Drawn ball returned first, then replacement ROW added; nonnegative replacement, double-precision exact-state DP rather than exact rational arithmetic.

Reinforcement changes future draws

A generalized Polya urn updates its composition after every random draw. The replacement matrix specifies which balls are added after each color appears, so later probabilities depend on the realized history.

This differs from drawing repeatedly from a fixed probability vector. Reinforcement can create a broad distribution of final compositions even when the initial urn is perfectly balanced.

Two-draw Polya final distributionPolya reinforcement: three final compositions1/3(3,1)1/3(2,2)1/3(1,3)Initial counts (1,1); add one of drawn colorTwo draws; the mixed composition includes two draw orders.
Scroll across to see the full diagram.
With initial(1,1) and identity net replacement, final compositions(3,1),(2,2),(1,3) each have probability1/3 after two draws.

Compare with the Occupied boxes probability calculator for random allocations. Propagate path-dependent reinforced sampling with cross-color replacement; independent allocations and fixed-probability multinomial models do not update draw probabilities.

State the replacement convention

Use the prefilled input structure and preserve the declared column or index order. Here the drawn ball is returned and the selected matrix row is then added as a net increment. An identity matrix therefore adds one extra ball of the drawn color.

Some descriptions instead count the returned ball within the replacement row. Check the convention before copying a published matrix, because the same entered numbers can otherwise describe a different process. All initial color counts are positive integers between one and twenty. The two to four replacement rows contain nonnegative integers from zero through four, and the number of draws lies between one and twenty. Drawing a color first returns that same ball, then adds the selected replacement row. If a convention instead removes the ball before replacement, its effective count update is different and must not be compared without translation. Zero replacement is allowed; it means that a draw leaves the composition unchanged under the returned-ball convention.

Choose a supported urn

The bounded version uses nonnegative integer additions and an initial composition with a positive total. Empty colors can become available later if another draw adds balls of that color.

Negative replacements need explicit rules for legal removals and tenability. They should not be interpreted by a nonnegative-addition calculator that would otherwise assign probabilities to impossible states.

Propagate complete state probabilities

At each step, multiply a state's probability by its current color proportions and send the resulting mass to the updated states. Histories reaching the same composition can be combined.

A state cap limits this exact finite-horizon enumeration. Reaching the cap means the distribution is unresolved, rather than permission to omit remaining states and renormalize a partial table.

A two-draw classical example

Start with one red and one blue ball and add one ball of the drawn color after returning it. After two draws, final compositions are(3,1),(2,2) and(1,3).

Each composition has probability one-third. The mixed composition combines two draw orders, while a same-color order has probability one-half times two-thirds, also one-third.

Separate composition from draw counts

Two replacement matrices can produce the same final composition through different color-count histories. Final urn counts therefore do not always reveal how often each color was drawn.

If draw-count probabilities are requested, they need their own tracked state information. A calculator should not infer them by inverting a replacement rule that may be singular or nonunique. The final count totals can differ across states when replacement row sums differ. Consequently, expected proportions cannot generally be obtained by dividing expected counts by one deterministic total. Compute a probability-weighted ratio when that is the intended summary.

Interpret finite-horizon output

The final distribution and expected counts describe the chosen number of draws. They do not establish an asymptotic limiting law for an arbitrary replacement matrix.

Inspect total probability, support and color expectations together. Those checks can reveal a convention error early, before a long run produces an apparently elaborate but incorrectly specified distribution. Dynamic programming merges histories that lead to the same count vector. Their probabilities add, even when different draw orders produced the identical final composition. The resulting support is therefore a distribution over final urn states rather than a list of individual color sequences. Enumeration is complete within the finite state cap, but probabilities are stored in floating point and are not returned as exact rational fractions. Total probability and expected color counts are useful conservation checks. A large replacement matrix can generate many distinct states before the draw limit is reached; an exceeded state cap remains unresolved rather than returning a renormalized partial distribution. Drawn ball returned first, then replacement ROW added; nonnegative replacement, double-precision exact-state DP rather than exact rational arithmetic.

A few questions, answered

Does the replacement row include the returned ball?

In this convention it is a net addition after the drawn ball has been returned.

Can I enter negative matrix values?

Not in the nonnegative-addition mode; removal urns require separate tenability rules.

Why are the final compositions not binomial?

The draw probabilities change with the reinforced urn composition after each observation.

What happens when enumeration is too large?

The calculation should report that the exact distribution is unresolved rather than show a renormalized partial distribution.

Find your calculator

Start typing to explore the library.