Relativistic SGHMC

class pysgmcmc.samplers.relativistic_sghmc.RelativisticSGHMCSampler(params, cost_fun, batch_generator=None, stepsize_schedule=<pysgmcmc.stepsize_schedules.ConstantStepsizeSchedule object>, mass=1.0, speed_of_light=1.0, D=1.0, Bhat=0.0, session=None, dtype=tf.float64, seed=None)[source]

Relativistic Stochastic Gradient Hamiltonian Monte-Carlo Sampler.

See [1] for more details on Relativistic SGHMC.

[1] X. Lu, V. Perrone, L. Hasenclever, Y. W. Teh, S. J. Vollmer

In Proceedings of the 20 th International Conference on Artificial Intelligence and Statistics (AISTATS) 2017

Relativistic Monte Carlo

__init__(params, cost_fun, batch_generator=None, stepsize_schedule=<pysgmcmc.stepsize_schedules.ConstantStepsizeSchedule object>, mass=1.0, speed_of_light=1.0, D=1.0, Bhat=0.0, session=None, dtype=tf.float64, seed=None)[source]
Initialize the sampler parameters and set up a tensorflow.Graph
for later queries.
Parameters:
  • params (list of tensorflow.Variable objects) – Target parameters for which we want to sample new values.
  • Cost (tensorflow.Tensor) – 1-d Cost tensor that depends on params. Frequently denoted as U(theta) in literature.
  • batch_generator (BatchGenerator, optional) – Iterable which returns dictionaries to feed into tensorflow.Session.run() calls to evaluate the cost function. Defaults to None which indicates that no batches shall be fed.
  • stepsize_schedule (pysgmcmc.stepsize_schedules.StepsizeSchedule) – Iterator class that produces a stream of stepsize values that we can use in our samplers. See also: pysgmcmc.stepsize_schedules
  • mass (float, optional) – mass constant. Defaults to 1.0.
  • speed_of_light (float, optional) – “Speed of light” constant. TODO EXTEND DOKU Defaults to 1.0.
  • D (float, optional) – Diffusion constant. Defaults to 1.0.
  • Bhat (float, optional) – TODO: Documentation
  • session (tensorflow.Session, optional) – Session object which knows about the external part of the graph (which defines Cost, and possibly batches). Used internally to evaluate (burn-in/sample) the sampler.
  • dtype (tensorflow.DType, optional) – Type of elements of tensorflow.Tensor objects used in this sampler. Defaults to tensorflow.float64.
  • seed (int, optional) – Random seed to use. Defaults to None.

See also

pysgmcmc.sampling.MCMCSampler()
Base class for RelativisticSGHMCSampler that specifies how actual sampling is performed (using iterator protocol, e.g. next(sampler)).
pysgmcmc.samplers.relativistic_sghmc._sample_relativistic_momentum(m, c, n_params, bounds=(-inf, inf), seed=None)[source]

Use adaptive rejection sampling (here: provided by external library ARSpy) to sample initial values for relativistic momentum p. The relativistic momentum variable in Relativistic MCMC has (marginal) distribution .. math:: propto e^{-K(p)} where \(K(p)\) is the relativistic kinetic energy. This distribution is a multivariate generalisation of the symmetric hyperbolic distribution, which cannot easily be sampled directly. Therefore we resort to adaptive rejection sampling to generate our samples and initialize our momentum terms properly.

See the paper “Relativistic Monte Carlo” for more information on Relativistic Hamiltonian Dynamics.

See Generalized hyperbolic distribution for more information on our target distribution.

Parameters:
  • m (float) – Mass constant used for sampling.
  • c (float) – Speed of light constant used for sampling.
  • n_params (int) – Number of target parameters of the target log pdf to sample from.
  • bounds (Tuple[float, float], optional) – Adaptive rejection sampling bounds to use during sampling. Defaults to (float(“-inf”), float(“inf”)), i.e. unbounded adaptive rejection sampling.
  • seed (int) – Random seed to use for adaptive rejection sampling.
Returns:

momentum_samples – Samples used to initialize our samplers momentum variables.

Return type:

list

Examples

Drawing 10 momentum values for 10 target parameters via (unbounded) adaptive rejection sampling:

>>> n_params = 10
>>> momentum_values = _sample_relativistic_momentum(m=1.0, c=1.0, n_params=n_params)
>>> len(momentum_values) == n_params
True

See also

ARSpy: Our external dependency that handles adaptive rejection sampling.
Available here.