State

class telescopic.kernels.State(x, log_prob, grad=None, extra=<factory>)

The states of n chains, batch first: positions, log-densities, gradients, fields.

A kernel returns states with the fields of its input states, valid at the returned positions: a state that carries gradients gets them evaluated at every new position. extra maps names to arrays of one kernel, such as a momentum or a cached value, with the chains along their first axis. The kernel names in markov_fields those that are part of its Markov state, and the others are caches that it checks before use. A kernel carries unchanged the fields it does not know, and take() and put() do so for it. A state therefore carries its kernel’s caches: before handing a state to another kernel by hand, drop its extra.

Attributes:
xndarray, shape (n, d)
log_probndarray, shape (n,)
gradndarray, shape (n, d), or None
extradict of str to ndarray, each of shape (n, …)
put(rows, other)

Overwrite the chains in rows with other, in place.

A field of extra that other lacks keeps its values in rows, and a field that only other has is not added.

Parameters:
rowsarray_like of int or bool, or slice

An index array, a mask of shape (n,) or a slice.

otherState

One chain per selected row, with the fields of this state.

take(rows)

A copy of the chains in rows.

Parameters:
rowsarray_like of int or bool, or slice

An index array, a mask of shape (n,) or a slice.

Returns:
State

The selected chains, with arrays of their own, every field of extra included.