Gibbs¶
- class telescopic.kernels.Gibbs(conditional, blocks, *, coupling='maximal', eta=1.0, threshold=None)¶
A Gibbs sampler that draws blocks of coordinates from their full conditionals.
A step sweeps the blocks in order and draws each from its full conditional given the current values of the other coordinates. Coupled chains draw each block from a coupling of their two conditionals:
"maximal": the rejection maximal coupling, witheta;"crn": common random numbers, which contract the chains but make them equal only by rounding. For a block of one coordinate whose two conditionals haveppf, one uniform goes through eachppf. For a block of several coordinates, or of one withoutppf, each chain draws from its own conditional withrvs, from generators in the same state, so each keeps its conditional’s law whatever its type. The two draws are then close whenrvsreads a fixed count of numbers from the generator and maps them smoothly in the conditional’s parameters, as a normal block drawn asmean + cholesky(cov) @ random_state.standard_normal(k), or withrandom_state.multivariate_normal(mean, cov, method="cholesky"), does. NumPy’s default method, a singular value decomposition, which SciPy’smultivariate_normalcalls, can change signs and order between nearby covariances, and then the two draws are as far apart as independent ones;"two-scale": common random numbers for pairs farther apart thanthresholdat the start of the sweep, the maximal coupling for the others (Biswas, Bhattacharya, Jacob & Johndrow 2022).
Where the two chains agree on every coordinate outside a block, their conditionals are the same, and both chains get the same draw.
- Parameters:
- conditional
callable() conditional(x, b)returns the full conditional of blockbgiven the other coordinates ofx, a read-only point of shape(d,): a frozen distribution withrvs(random_state=...)and a normalizedlogpdforlogpmf, such asscipy.stats.norm(mean, sd). One value oflogpdfper coordinate, as with array parameters, is summed: the joint log-density of independent coordinates.- blockssequence of array_like of
int Index arrays that partition the coordinates
0, ..., d - 1.- coupling{“maximal”, “crn”, “two-scale”}
- eta
float Cap on the maximal coupling’s meeting probability, in (0, 1]; 1 with
"crn".- threshold
float, optional The distance at which
"two-scale"switches couplings; required by it, and refused by the others.
- conditional
Notes
Sweeps loop over rows in Python, and build a conditional per row and block. A frozen SciPy distribution takes 250 to 300 µs to build, which can dominate a step; a small class with the methods used is faster, as in
telescopic.examples. A step draws each block from the row’s generator. A coupled step does the same for the maximal coupling and for identical conditionals. For common random numbers it reads 1 uniform per row and block throughppf, or else draws from a new child of the row’s generator,child(), which leaves the row’s own stream where it was. A conditional that draws a point that is not finite, or not of its block’s size, raisesValueError. Withlog_prob=Nonethe target has no log-density, and states carry 0.Examples
The pump-failure model has full conditionals, so a Gibbs kernel samples it without a log-density, which is never evaluated:
>>> from telescopic import examples, kernels, sample >>> example = examples.pumps() >>> kernel = kernels.Gibbs(example.conditional, example.blocks) >>> result = sample( ... None, example.initial, kernel=kernel, n_replicates=50, rng=0 ... ) >>> result.n_log_prob, result.mean().value.shape (0, (11,))
- coupled_step(target, state_x, state_y, draws)¶
One coupled transition of each pair.
- property needs_log_prob¶
Whether the kernel evaluates the log-density; Gibbs kernels do not.
- Returns:
- step(target, state, draws)¶
One transition of each chain.
- Parameters:
- Returns: