resampling
systematic_resample(weights)
Systematic resampling with a single random offset.
Generates N equally spaced probe points in [0, 1] with a single random offset between 0 and 1/N. Indices are derived by mapping these points through the inverse CDF of the categorical distribution defined by the weights. Each index i is resampled exactly floor(N * w_i) or ceil(N * w_i) times.
Adapted from FilterPy (R. Labbe): https://filterpy.readthedocs.io/en/latest/monte_carlo/resampling.html
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
weights
|
array - like
|
Normalized probability weights summing to 1. |
required |
Returns:
| Type | Description |
|---|---|
ndarray
|
Integer array of ancestor indices. |
Source code in genlm/control/sampler/resampling.py
stratified_resample(weights)
Stratified resampling with one random draw per stratum.
Divides [0, 1] into N equal strata and draws one uniform point independently within each, so that consecutive points are between 0 and 2/N apart. Indices are derived by mapping these points through the inverse CDF of the categorical distribution defined by the weights.
Adapted from FilterPy (R. Labbe): https://filterpy.readthedocs.io/en/latest/monte_carlo/resampling.html
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
weights
|
array - like
|
Normalized probability weights summing to 1. |
required |
Returns:
| Type | Description |
|---|---|
ndarray
|
Integer array of ancestor indices. |
Source code in genlm/control/sampler/resampling.py
residual_resample(weights)
Residual resampling: deterministic floor copies + multinomial remainder.
Takes floor(N * w_i) copies of each particle deterministically, then resamples the remaining slots from the fractional residuals using multinomial resampling.
Adapted from FilterPy (R. Labbe): https://filterpy.readthedocs.io/en/latest/monte_carlo/resampling.html
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
weights
|
array - like
|
Normalized probability weights summing to 1. |
required |
Returns:
| Type | Description |
|---|---|
ndarray
|
Integer array of ancestor indices. |
Source code in genlm/control/sampler/resampling.py
multinomial_resample(weights)
Multinomial resampling: independent categorical draws.
Each of the N ancestor indices is drawn independently from the categorical distribution defined by the weights.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
weights
|
array - like
|
Normalized probability weights summing to 1. |
required |
Returns:
| Type | Description |
|---|---|
ndarray
|
Integer array of ancestor indices. |
Source code in genlm/control/sampler/resampling.py
get_resampling_fn(method)
Get a resampling function by name.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
method
|
str
|
One of 'systematic', 'stratified', 'residual', 'multinomial'. |
required |
Returns:
| Type | Description |
|---|---|
callable
|
Resampling function that takes weights and returns indices. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If method is not recognized. |