Skip to content

Promote integer starting coordinates before sampling - #578

Open
antonsoo wants to merge 1 commit into
dfm:mainfrom
antonsoo:fix/integer-initial-state
Open

antonsoo wants to merge 1 commit into
dfm:mainfrom
antonsoo:fix/integer-initial-state

Conversation

@antonsoo

Copy link
Copy Markdown

Integer starting coordinates silently truncate accepted continuous proposals while retaining their floating-point log probabilities. The stored positions and probabilities can then disagree:

import emcee
import numpy as np

sampler = emcee.EnsembleSampler(8, 1, lambda p: -0.5 * np.dot(p, p))
sampler.random_state = np.random.RandomState(117).get_state()
sampler.run_mcmc(np.arange(-4, 4)[:, None], 10)
np.testing.assert_allclose(
    sampler.get_log_prob(),
    -0.5 * np.sum(sampler.get_chain() ** 2, axis=-1),
)

The maximum discrepancy is about 2.52 on main and zero with this change. Promote integer or boolean starting coordinates to floating point before sampling. Existing floating-point types, including long double, keep their dtype. Regression cases compare signed/unsigned integer arrays and State inputs with equivalent float starts using stretch and Gaussian moves. This supports continuous sampling from integer-valued starting positions; it does not add integer-valued proposals.

Validation on Linux/Python 3.14.7: all 142 tests and repository-wide pre-commit hooks pass, including the existing long-double tests. For Bayesian regression on 107 NIST ultrasonic calibration measurements, all 108 signed/unsigned integer-start and State configurations now match their float-start chains exactly. The floating controls are unchanged; an independently derived Gaussian posterior checks every stored log probability. Other platforms were not run locally.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant