from kameleon_mcmc.mcmc.MCMCParams import MCMCParams from kameleon_mcmc.mcmc.output.StatisticsOutput import StatisticsOutput from kameleon_mcmc.mcmc.samplers.AdaptiveMetropolis import AdaptiveMetropolis from kameleon_mcmc.mcmc.samplers.AdaptiveMetropolisLearnScale import \ AdaptiveMetropolisLearnScale from kameleon_mcmc.mcmc.samplers.KameleonWindowLearnScale import \ KameleonWindowLearnScale from kameleon_mcmc.mcmc.samplers.StandardMetropolis import StandardMetropolis if __name__ == '__main__': experiment_dir = str(os.path.abspath(sys.argv[0])).split( os.sep)[-1].split(".")[0] + os.sep distribution = Flower(amplitude=6, frequency=6, variance=1, radius=10, dimension=8) sigma = 5 kernel = GaussianKernel(sigma=sigma) burnin = 60000 num_iterations = 120000 #mcmc_sampler = KameleonWindowLearnScale(distribution, kernel, stop_adapt=burnin) mean_est = zeros(distribution.dimension, dtype="float64") cov_est = 1.0 * eye(distribution.dimension) #mcmc_sampler = AdaptiveMetropolisLearnScale(distribution, mean_est=mean_est, cov_est=cov_est) #mcmc_sampler = AdaptiveMetropolis(distribution, mean_est=mean_est, cov_est=cov_est) mcmc_sampler = StandardMetropolis(distribution)
def get_plotting_bounds(self): if self.dimension == 2: value = self.radius + self.amplitude + 3 * sqrt(self.variance) return [(-value, value) for _ in range(2)] else: return Flower.get_plotting_bounds(self)
from matplotlib.pyplot import axis, savefig from numpy import linspace from kameleon_mcmc.distribution.Banana import Banana from kameleon_mcmc.distribution.Flower import Flower from kameleon_mcmc.distribution.Ring import Ring from kameleon_mcmc.tools.Visualise import Visualise if __name__ == '__main__': distributions = [Ring(), Banana(), Flower()] for d in distributions: Xs, Ys = d.get_plotting_bounds() resolution = 250 Xs = linspace(Xs[0], Xs[1], resolution) Ys = linspace(Ys[0], Ys[1], resolution) Visualise.visualise_distribution(d, Xs=Xs, Ys=Ys) axis("Off") savefig("heatmap_" + d.__class__.__name__ + ".eps", bbox_inches='tight')
def __init__(self, variance=0.05, radius=3.5, dimension=2): Flower.__init__(self, 0, 1, variance, radius, dimension)