Skip to content

Bootstrap results are not reproducible #194

@mynameis5927

Description

@mynameis5927

The bootstrap results are not reproducible, even though I set the random seed np.random.seed(17) at the beginning of the program.

However, if I add np.random.seed(11) to this function, it works and is reproducible.

==================================================================
@njit
def bca_boot_conf(
x: NDArray[np.float64],
n: int,
n_boot: int,
fn: Callable[[NDArray[np.float64]], float],
) -> BootConfIntervals:
"""Computes confidence intervals for a user-defined parameter using the
bias corrected and accelerated (BCa) bootstrap method. <https://blogs.sas.com/content/iml/2017/07/12/bootstrap-bca-interval.html>_

Args:
    x: :class:`numpy.ndarray` containing the data for the randomized
        bootstrap sampling.
    n: Number of elements in each random bootstrap sample.
    n_boot: Number of random bootstrap samples to use.
    fn: :class:`Callable` for computing the parameter used for the
        confidence intervals.

Returns:
    :class:`.BootConfIntervals` containing the computed confidence
    intervals.
"""

np.random.seed(17)

if n <= 0:
    raise ValueError("Bootstrap sample size must be greater than 0.")
if n_boot <= 0:
    raise ValueError("Number of boostrap samples must be greater than 0.")
n_x = len(x)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions