Constructor
new AliasTable(weights)
Parameters:
| Name | Type | Description |
|---|---|---|
weights |
Array.<number> | Non-negative weights (normalised automatically). |
- Source:
Example
const table = new AliasTable([0.1, 0.2, 0.7])
table.sample(1000) // indices 0, 1, 2
Methods
sample(sizeopt) → {number|Array}
Draws category indices.
Parameters:
| Name | Type | Attributes | Default | Description |
|---|---|---|---|---|
size |
number | Array | null |
<optional> |
null | Output shape. |
- Source:
Returns:
- Type
- number | Array