import numpy as np
import imcmc
# Rerun this cell until the image looks good
np.random.seed(8)
image = imcmc.load_image('python.png', 'L')
trace = imcmc.sample_grayscale(image, samples=1000, tune=500, nchains=6, threshold=0.1)
imcmc.plot_multitrace(trace, image, marker='o', markersize=10, colors=['#0000FF','#0000FF', '#FFFF00'], alpha=1);
Multiprocess sampling (6 chains in 2 jobs) Metropolis: [image] 100%|█████████▉| 1494/1500 [00:00<00:00, 1865.37it/s] 100%|██████████| 1500/1500 [00:00<00:00, 1862.78it/s]The estimated number of effective samples is smaller than 200 for some parameters.
# Then run this step on the final image to get the samplers drawing it
imcmc.make_gif(trace, image, dpi=40, marker='o',
markersize=10, colors=['#0000FF','#0000FF', '#FFFF00'],
alpha=1, leading_point=False, filename='python.gif')
'python.gif'
# Rerun this cell until the image looks good
np.random.seed(2)
image = imcmc.load_image('pymc3-logo.png', 'L')
trace = imcmc.sample_grayscale(image, samples=5000, tune=500, nchains=7)
imcmc.plot_multitrace(trace, image, marker='o', alpha=0.5);
Multiprocess sampling (7 chains in 2 jobs) Metropolis: [image]
2
100%|██████████| 5500/5500 [00:00<00:00, 6760.44it/s] The gelman-rubin statistic is larger than 1.2 for some parameters. The estimated number of effective samples is smaller than 200 for some parameters.
# Then run this step on the final image to get the samplers drawing it
imcmc.make_gif(trace, image, dpi=40, marker='', linestyle='-', alpha=0.35, filename='pymc3.gif')
'pymc3.gif'
# Rerun this cell until the image looks good
seed += 1
np.random.seed(18)
print(seed)
image = imcmc.load_image('civic.png', 'L')
trace = imcmc.sample_grayscale(image, samples=1000, tune=500, nchains=98)
imcmc.plot_multitrace(trace, image, marker=',', alpha=1);
18
Multiprocess sampling (98 chains in 2 jobs) Metropolis: [image] 100%|██████████| 1500/1500 [00:00<00:00, 5639.67it/s] The gelman-rubin statistic is larger than 1.4 for some parameters. The sampler did not converge. The estimated number of effective samples is smaller than 200 for some parameters.
# Then run this step on the final image to get the samplers drawing it
imcmc.make_gif(trace, image, dpi=40, marker=',', leading_point=False, alpha=1, filename='civic.gif')
'civic.gif'
# Rerun this cell until the image looks good
seed += 1
np.random.seed(6)
print(seed)
image = imcmc.load_image('matplotlib.png', 'L')
trace = imcmc.sample_grayscale(image, samples=2000, tune=500, nchains=7)
imcmc.plot_multitrace(trace, image, marker='.', linestyle='-', alpha=0.5);
Multiprocess sampling (7 chains in 2 jobs) Metropolis: [image]
6
100%|██████████| 2500/2500 [00:00<00:00, 6298.96it/s] The gelman-rubin statistic is larger than 1.4 for some parameters. The sampler did not converge. The estimated number of effective samples is smaller than 200 for some parameters.
imcmc.make_gif(trace, image, dpi=40, marker='.', linestyle='-', alpha=0.3, filename='matplotlib.gif')
'matplotlib.gif'
seed = 0
# Rerun this cell until the image looks good
seed += 1
np.random.seed(10)
print(seed)
image = imcmc.load_image('scipy.png', 'L')
trace = imcmc.sample_grayscale(image, samples=1000, tune=500, nchains=5)
imcmc.plot_multitrace(trace, image, marker='o', linestyle='', alpha=0.5);
Multiprocess sampling (5 chains in 2 jobs) Metropolis: [image]
10
100%|██████████| 1500/1500 [00:00<00:00, 6106.53it/s] The gelman-rubin statistic is larger than 1.05 for some parameters. This indicates slight problems during sampling. The estimated number of effective samples is smaller than 200 for some parameters.
imcmc.make_gif(trace, image, dpi=40, marker='o', alpha=0.5, filename='scipy.gif')
'scipy.gif'
seed = 0
# Rerun this cell until the image looks good
seed += 1
np.random.seed(19)
print(seed)
image = imcmc.load_image('imcmc.png', 'L')
trace = imcmc.sample_grayscale(image, samples=1000, tune=500, nchains=7)
imcmc.plot_multitrace(trace, image, marker='.', linestyle='', alpha=0.7);
Multiprocess sampling (7 chains in 2 jobs) Metropolis: [image]
19
100%|██████████| 1500/1500 [00:00<00:00, 6114.56it/s] The gelman-rubin statistic is larger than 1.4 for some parameters. The sampler did not converge. The estimated number of effective samples is smaller than 200 for some parameters.
imcmc.make_gif(trace, image, dpi=20, marker='.', alpha=0.7, filename='imcmc.gif')
'imcmc.gif'