telescopic.engine¶
The engine: replicates of coupled chains, run in lockstep lanes with refill.
Classes
The outputs of a set of replicates, sorted by replicate index, and their run's settings. |
|
The settings of a run. |
|
The progress of a run, given to its monitor after every iteration. |
- telescopic.engine.check_settings(settings)¶
Check the settings of a run and return them with Python integers.
They need integers \(0 \le k \le m\), \(L \ge 1\) and
thin\(\ge 1\), and an integermax_iterabove \(\max(L, m)\) orNone, at most \(2^{31} - 1\) when the run stores the times of its atoms, andkeepNoneor an integer \(\ge 0\), only withstore. NumPy integers becomeint.
- telescopic.engine.merge(parts)¶
Join the outputs of disjoint sets of replicates of one run, sorted by replicate index.
The parts must share the root seed, the settings and the dimension; the requested and the abandoned indices are the unions of theirs. For a target evaluated point by point the result is bitwise that of one run of all the replicates; for a vectorized one it can differ from it as a run with other
lanesdoes (run()).- Parameters:
- partssequence of
Replicates The outputs to join, at least one.
- partssequence of
- Returns:
- telescopic.engine.run(
- target,
- kernel,
- initial,
- indices,
- *,
- k,
- m,
- lag,
- thin=1,
- max_iter=None,
- rng=None,
- lanes=256,
- store=True,
- keep=None,
- keep_paths=False,
- monitor=None,
Run the replicates
indicesof the estimator \(H_S\).Each replicate draws \(X_0\) and then \(Y_0\) from
initialwith its own stream, runs \(X\) alone forlagsteps, then the coupled kernel until \(X_t = Y_{t-L}\) under==, then \(X\) alone until \(t = m\). For a log-density evaluated point by point, a replicate’s output depends only on the root seed, its index and the arguments, bitwise, never on the other replicates or onlanes. For a vectorized one the kernels compute their products with BLAS, whose rounding can depend on the replicates beside it and on the number of BLAS threads: the output repeats bitwise with the same arguments,lanes, BLAS build and number of BLAS threads, and otherwise a replicate can differ by rounding, which can move its meeting time and its whole output, while the estimates agree within their error bars (Reproducibility, in Run in parallel). The engine emits no warning: it records what its caller needs to warn about.- Parameters:
- target
Target The target to sample.
- kernel
Kernel A tuned kernel.
- initial
An object with
rvs(random_state=generator), a callableinitial(rng)or an array of points of shape(n, d), as fortelescopic.initial.as_initial().- indicesarray_like of
int, shape (R,) Distinct replicate indices, at least one, started in this order.
- k, m
int First and last averaged times, \(0 \le k \le m\).
- lag
int The lag \(L \ge 1\).
- thin
int Average every
thin-th time fromk.- max_iter
int, optional Censor a pair still unmet when \(t\) reaches
max_iter, which must exceedmax(lag, m).Noneruns every pair until it meets.- rng
None,int,numpy.random.SeedSequenceornumpy.random.Generator The root seed, recorded in the output. Runs of other indices with the same
SeedSequenceor integer can be merged.- lanes
int Number of replicates advanced together, at most the number requested.
- storebool
Whether to store the signed measures and distances; meeting-time pilots do not.
- keep
int, optional With
store: store the signed measures, their times and the distances of the replicates of index belowkeeponly, and the moments of every replicate (centerandmomentsofReplicates), at a cost of \(O(p)\) per atom with \(p = d(d + 3)/2\) up to \(d = 100\) and \(2d\) above it.Nonestores the signed measures and distances of every replicate, and no moments.- keep_pathsbool
Whether to keep the paths of both chains, for inspection.
- monitor
callable(), optional Called with a
Statusafter every iteration. Once it returns true, no new replicate starts and the ones in progress finish, so the finished indices are those started.
- target
- Returns:
- Raises:
- Exception
An error raised while the replicates run, such as one of the log-density, is raised again as the same object once the replicates finished before it are recorded: its attribute
telescopic_replicatesholds them, aReplicateswhoseabandonedlists the replicates in progress, orNonewhen no record could be made, and one note says so. An exception object raised in several runs carries the attribute and the note of the last of them.
Notes
Memory:
stored_bytes()gives the size of the stored atoms and distances.
- telescopic.engine.stored_bytes(settings, ndim, coupled)¶
Bytes of the atoms, distances and moments that replicates store.
A replicate that met after \(c = \tau - L\) coupled steps stores the \(|S|\) atoms of the time average and two atoms for each of the \(\max(0, c - k)\) terms of the bias correction, each of \(8d + 20\) bytes (its coordinates in
atoms, its weight, its replicate inownerand itstime), and \(c\) distances of 24 bytes (distance_owner,distance_timeanddistance). This is exact whenthinis 1 and \(m - k + 1 \ge L\), and an upper bound otherwise, where some terms of the correction have no atoms. Withstore=Falsenothing is stored. Withkeep, only the firstkeepreplicates store atoms and distances, and every replicate stores its moments, \(8(p + d)\) bytes (centerandmomentsofReplicates), with \(p = d(d + 3)/2\) up to \(d = 100\) and \(2d\) above.- Parameters:
- settings
Settings The settings of the run.
- ndim
int The dimension \(d\).
- coupledarray_like of
int, shape (R,) \(\tau - L\) of each replicate, non-negative, in the order of their indices.
- settings
- Returns:
floatThe total over the replicates.