HadamardLangevin package
Submodules
HadamardLangevin.samplers module
- HadamardLangevin.samplers.generate_samples_stride(Iterate, init, n, stride=1, burn_in=1000)[source]
This function generates n samples using some sampling mechanisim given by Iterate.
- Parameters:
Iterate – function that takes input x_t of size (p,) and outputs x_{t+1} of size (p,)
init – int, initial vector of size (p,)
n – int, number of samples to return
stride – int, number of samples to skip before recording
burn_in – int, number of iterations to run before recording the samples
- Return samples:
numpy.ndarray of size (n,p)
- HadamardLangevin.samplers.generate_samples_x(Iterate, init, n, burn_in=1000)[source]
This function generates n samples using some sampling mechanisim given by Iterate.
- Parameters:
Iterate – function that takes input x_t of size (p,) and outputs x_{t+1} of size (p,)
init – int, initial vector of size (p,)
n – int, number of samples to return
burn_in – int, number of iterations to run before recording the samples
- Return samples:
numpy.ndarray of size (n,p)
- HadamardLangevin.samplers.gibbs_sampler(A, y, lam, init, n, burn_in=1000, beta=1)[source]
This function implements one step of Gibbs sampler for the Bayesian lasso. To sample from exp(-beta*(|A@x-y|^2/2+lam*|x|_1))
- Parameters:
A – numpy.ndarray of size (m,p), data matrix
y – numpy.ndarray of size (m,), data vector
lam – float, regularization parameter for l1 term
init – int, initial vector of size (p,)
n – int, number of samples to return
burn_in – int, number of iterations to run before recording the samples
beta – float, inverse temperature, beta=1 by default.
- Return samples:
numpy.ndarray of size (n,p), generated samples
- HadamardLangevin.samplers.one_step_MALA(x, p, fval, grad, tau, beta=1)[source]
- This function implements one step of metropolis hasting proximal langevin. To sample from exp(-beta*G(x))
where G is smooth and R is nonsmooth. Returns x’ = x - tau*(grad_G(x) + (x - prox_R(x,gamma))/gamma) + sqrt(2*tau/beta)*N(0,I_p)
- Parameters:
x – initial vector size (p,)
p – int, length of x
tau – float, stepsize
fval – G. This is a function mapping numpy.ndarray of size (p,) to float
grad – gradient of smooth term. This is a function mapping numpy.ndarray of size (p,) to numpy.ndarray of size (p,)
beta – float, inverse temperature, beta=1 by default.
- Return y:
numpy.ndarray of size (p,) next iteration of proximal langevin
- HadamardLangevin.samplers.one_step_MALA_hadamard(x, p, fval, grad, tau, lam, beta=1)[source]
- This function implements one step of Hadamard langevin. To sample from exp(-beta*(G(x)+lam*|x|_1))
where G is smooth.
- Parameters:
x – initial vector size (2*p,) representing (u,v)
p – int, .5 * length of x
tau – float, stepsize
fval – functional value of smooth part to negative log density
grad – gradient of smooth term in negative log density. This is a function mapping numpy.ndarray of size (p,) to numpy.ndarray of size (p,)
lam – float, regularization parameter for l1 term
beta – float, inverse temperature, beta=1 by default.
- Return y:
numpy.ndarray of size (2*p,) next iteration of hadamard langevin
- HadamardLangevin.samplers.one_step_hadamard(x, p, grad, tau, lam, beta=1)[source]
- This function implements one step of Hadamard langevin. To sample from exp(-beta*(G(x)+lam*|x|_1))
where G is smooth.
- Parameters:
x – initial vector size (2*p,) representing (u,v)
p – int, .5 * length of x
tau – float, stepsize
grad – gradient of smooth term. This is a function mapping numpy.ndarray of size (p,) to numpy.ndarray of size (p,)
lam – float, regularization parameter for l1 term
beta – float, inverse temperature, beta=1 by default.
- Return y:
numpy.ndarray of size (2*p,) next iteration of hadamard langevin
- HadamardLangevin.samplers.one_step_langevin(x, p, grad, tau, beta=1)[source]
- This function implements one step of proximal langevin. To sample from exp(-beta*(G(x)))
where G is smooth and R is nonsmooth. Returns x’ = x - tau*grad_G(x) + sqrt(2*tau/beta)*N(0,I_p)
- Parameters:
x – initial vector size (p,)
p – int, length of x
tau – float, stepsize
grad – gradient of G. This is a function mapping numpy.ndarray of size (p,) to numpy.ndarray of size (p,)
beta – float, inverse temperature, beta=1 by default.
- Return y:
numpy.ndarray of size (p,) next iteration of proximal langevin