Skip to content

[Code scan] Make mhcustom honor burn-in state and nsamples #43

Description

@njzjz

This issue comes from a Codex global repository scan.

Problem

The vendored MCMC custom sampler computes a post-burn-in state, then discards it and collects the wrong number of samples:

x, dtype, device = _mhcustom_sample(logpfcn, x0, pparams, nburnout, custom_step, False)
xsamples = _mhcustom_sample(logpfcn, x0, pparams, nburnout, custom_step, True)

It calls _mhcustom_sample(..., x0, ..., nburnout, ..., True) instead of starting from x and collecting nsamples. Whenever nsamples != nburnout, the returned chain has the wrong length and starts from the unburned initial state.

Reproduction

Use custom_step=lambda x: x + 1, x0=0, nsamples=3, and nburnout=2; the current output has length 2 and starts at [0, 1].

Suggested fix

Collect from the burned-in state and use nsamples:

xsamples = _mhcustom_sample(logpfcn, x, pparams, nsamples, custom_step, True)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    Status
    Todo

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions