Alias Categorical Sampling: Filling Equal-Width Columns
2026-11-18

Alias Categorical Sampling: Filling Equal-Width Columns

Alias Categorical Sampling turns a finite list of category probabilities into a small table for repeated draws. A draw first selects an equal-width column, then uses a threshold to choose that column's own category or its stored alias. The uneven category probabilities are represented by how their portions fill the columns, rather than by giving every category an equal final chance.

Separate the desired probabilities from the column choice

The SciPy DiscreteAliasUrn reference describes sampling from a finite probability vector or a probability mass function with finite support. Its input requirements include nonnegative finite weights and at least one nonzero entry. The finite table is prepared before it supplies repeated samples.

For a mathematical teaching table, use categories A, B and C with probabilities one half, three tenths and one fifth. Three equally likely columns each have probability one third. Multiplying the target probabilities by three gives column-sized masses 1.5, 0.9 and 0.6. Those numbers describe how many unit columns each category must fill in total.

A therefore needs more than one column, while B and C each need less than one. An alias table lets A occupy the unused portions of the other columns. Selecting a column uniformly is only the first part of the draw and should not be reported as a uniform draw of the final categories.

ThreecolumnsfillAall, B.9plusA.1, C.6plusA.4 reconstructtarget.5,.3,.2.
One valid conceptual alias table; not actual exposed library storage. Source: Zhilianhai editorial desk, original AI-assisted conceptual illustration.

Fill each column with at most two categories

One valid table puts A throughout column zero. Column one contains B over its lower 0.9 fraction and A over the remaining 0.1. Column two contains C over its lower 0.6 fraction and A over the remaining 0.4. Its thresholds are therefore one, 0.9 and 0.6, with A as the alias in the two partially filled columns.

This is a possible construction for explaining the method, not a claim that a particular library must expose exactly this internal ordering. Different small-and-large pairing orders can produce different valid tables. What matters is the total probability assigned to each category after both selection steps.

A receives one full column plus the portions 0.1 and 0.4 of the other columns. Dividing that total 1.5 by three gives one half. B receives 0.9 divided by three, or three tenths. C receives 0.6 divided by three, or one fifth. The areas reconstruct all three requested probabilities exactly in this ideal arithmetic model.

A single draw follows the selected column's threshold

Conceptually, select a uniform integer column and an independent uniform fraction between zero and one. If the fraction is below the chosen column's threshold, return its own category; otherwise return its alias. A continuous uniform draw can also encode both choices through its integer and fractional parts after scaling by the column count.

If column two is selected with fraction 0.4, the result is C because 0.4 is below 0.6. If its fraction is 0.8, the result is A. Column one behaves similarly around 0.9. A threshold of one in column zero always selects A under the usual fraction range excluding one.

Selectedcolumn2 returnsCforfraction.4below.6 andAfor.8above.6.
Ideal uniform-fraction example, not observed rental demand or sample quota. Source: Zhilianhai editorial desk, original AI-assisted conceptual illustration.

Table setup and random draws have different roles

The UNU.RAN manual, Section 5.8.2 describes the Alias-Urn method as using a table of at least the probability-vector length, with linear setup and a small fixed amount of sampling work afterward. Its table-size setting changes the tradeoff between setup effort and subsequent generation.

The SciPy interface exposes an urn factor and a random-state choice. Increasing the table factor does not mean the target categories should become more likely simply because they acquire extra internal positions. The table still represents the specified distribution. Changing the probability weights instead requires a table consistent with the changed distribution, rather than continuing to interpret an old threshold table as if it had updated itself.

A probability is not an exact short-run quota

The alias label also need not be a different category in every column. A completely filled column can use any harmless self-alias convention because the fraction never reaches its threshold of one. The example's useful work occurs in the partially filled columns, where both branches have positive area. When checking a saved table, compare thresholds with their associated column identities and alias entries; a correct list of thresholds attached to the wrong aliases no longer reconstructs the original distribution.

Repeated random draws need not yield exactly five A values in every ten observations. The table describes each draw's distribution, while realized counts fluctuate. Sorting the output or forcing each block to match a quota would define a different procedure. The geometric area check validates the constructed probabilities; it does not turn a small observed histogram into a universal randomness certificate.

The table contains invented categories and exact illustrative thresholds. It does not represent actual rental demand or an allocation decision. Keep the probability vector, category indexing and sampling method beside any simulated output. More data-method explanations appear in the reference collection and the technical article directory.

18028484626 CONTACT US

公司:智联海(惠州)科技有限公司

地址:惠州仲恺高新区陈江街道白云山工业大道 5 号六楼 601

Q Q:18028484626

Copyright © 2002-2026

粤xxx

咨询 在线留言 电话:18028484626
微信 微信扫码添加我