resample_posterior
params.resample_posterior(source, *, n, weight='weight', seed=None)Resample a weighted parameter table into an unweighted draw matrix.
Rows are drawn with replacement with probability proportional to the weight column, jointly (whole rows), so any correlation in the posterior survives. The weight column is dropped from the result, which carries a fresh RangeIndex named "iteration".
Resampling to an n larger than the input adds no information; it only smooths Monte Carlo noise in downstream expectations.
Parameters
| Name | Type | Description | Default |
|---|---|---|---|
| source | pd.DataFrame | str | Path |
A weighted parameter table DataFrame, or a path to a CSV file of one, with one column of weights and the rest parameters. | required |
| n | int |
Number of rows in the resampled draw matrix. | required |
| weight | str |
Name of the weight column. Weights must be non-negative and not all zero; they are normalised internally. | 'weight' |
| seed | int | np.random.Generator | None |
Integer seed or numpy Generator for the resampling. |
None |
Returns
| Name | Type | Description |
|---|---|---|
| pd.DataFrame | DataFrame with n rows, a RangeIndex named "iteration", and |
|
| pd.DataFrame | one column per parameter (the weight column removed). |
Raises
| Name | Type | Description |
|---|---|---|
ValueError |
If the table is empty, weight names a missing column, n is not positive, or the weights are negative or sum to zero. |
Example
import pandas as pd from heormodel.params import resample_posterior post = pd.DataFrame({“beta”: [0.1, 0.2, 0.3], “weight”: [1.0, 2.0, 1.0]}) resample_posterior(post, n=1000, seed=0).shape (1000, 1)