blackjax.sgmcmc.sgnht#
Public API for the Stochastic gradient Nosé-Hoover Thermostat kernel.
Classes#
State of the SGNHT algorithm. |
Functions#
|
|
|
Stochastic gradient Nosé-Hoover Thermostat (SGNHT) algorithm. |
|
Implements the (basic) user interface for the SGNHT kernel. |
Module Contents#
- class SGNHTState[source]#
State of the SGNHT algorithm.
- Parameters:
position – Current position in the sample space.
momentum – Current momentum in the sample space.
xi – Scalar thermostat controlling kinetic energy.
- init(position: blackjax.types.ArrayLikeTree, rng_key: blackjax.types.PRNGKey, xi: float) SGNHTState [source]#
- build_kernel(alpha: float = 0.01, beta: float = 0) Callable [source]#
Stochastic gradient Nosé-Hoover Thermostat (SGNHT) algorithm.
- as_top_level_api(grad_estimator: Callable, alpha: float = 0.01, beta: float = 0.0) blackjax.base.SamplingAlgorithm [source]#
Implements the (basic) user interface for the SGNHT kernel.
The general sgnht kernel (
blackjax.sgmcmc.sgnht.build_kernel()
, alias blackjax.sgnht.build_kernel) can be cumbersome to manipulate. Since most users only need to specify the kernel parameters at initialization time, we provide a helper function that specializes the general kernel.Example
To initialize a SGNHT kernel one needs to specify a schedule function, which returns a step size at each sampling step, and a gradient estimator function. Here for a constant step size, and data_size data samples:
grad_estimator = blackjax.sgmcmc.gradients.grad_estimator(logprior_fn, loglikelihood_fn, data_size)
We can now initialize the sgnht kernel and the state.
sgnht = blackjax.sgnht(grad_estimator) state = sgnht.init(rng_key, position)
Assuming we have an iterator batches that yields batches of data we can perform one step:
step_size = 1e-3 minibatch = next(batches) new_state = sgnht.step(rng_key, state, minibatch, step_size)
Kernels are not jit-compiled by default so you will need to do it manually:
step = jax.jit(sgnht.step) new_state = step(rng_key, state, minibatch, step_size)
- Parameters:
grad_estimator – A function that takes a position, a batch of data and returns an estimation of the gradient of the log-density at this position.
- Return type:
A
SamplingAlgorithm
.