|
3 | 3 | import matplotlib.pyplot as plt |
4 | 4 | from fgivenx import plot_contours, plot_lines, plot_dkl |
5 | 5 | from fgivenx.drivers import compute_samples, compute_pmf, compute_dkl |
6 | | -from matplotlib.testing.decorators import image_comparison |
7 | 6 |
|
8 | 7 |
|
9 | 8 | def test_full(): |
@@ -63,7 +62,6 @@ def f(x, theta): |
63 | 62 | cache=cache, prior_cache=prior_cache) |
64 | 63 |
|
65 | 64 |
|
66 | | -@image_comparison(baseline_images=['fgivenx'], extensions=['pdf']) |
67 | 65 | def test_plotting(): |
68 | 66 | # Model definitions |
69 | 67 | # ================= |
@@ -91,47 +89,50 @@ def f(x, theta): |
91 | 89 | x = numpy.linspace(xmin, xmax, nx) |
92 | 90 |
|
93 | 91 | # Set the cache |
94 | | - cache = 'cache/test' |
95 | | - prior_cache = cache + '_prior' |
96 | | - |
97 | | - # Plotting |
98 | | - # ======== |
99 | | - fig, axes = plt.subplots(2, 2) |
100 | | - |
101 | | - # Sample plot |
102 | | - # ----------- |
103 | | - ax_samples = axes[0, 0] |
104 | | - ax_samples.set_ylabel(r'$c$') |
105 | | - ax_samples.set_xlabel(r'$m$') |
106 | | - ax_samples.plot(prior_samples.T[0], prior_samples.T[1], 'b.') |
107 | | - ax_samples.plot(samples.T[0], samples.T[1], 'r.') |
108 | | - |
109 | | - # Line plot |
110 | | - # --------- |
111 | | - ax_lines = axes[0, 1] |
112 | | - ax_lines.set_ylabel(r'$y = m x + c$') |
113 | | - ax_lines.set_xlabel(r'$x$') |
114 | | - plot_lines(f, x, prior_samples, ax_lines, color='b', cache=prior_cache) |
115 | | - plot_lines(f, x, samples, ax_lines, color='r', cache=cache) |
116 | | - |
117 | | - # Predictive posterior plot |
118 | | - # ------------------------- |
119 | | - ax_fgivenx = axes[1, 1] |
120 | | - ax_fgivenx.set_ylabel(r'$P(y|x)$') |
121 | | - ax_fgivenx.set_xlabel(r'$x$') |
122 | | - plot_contours(f, x, prior_samples, ax_fgivenx, |
123 | | - colors=plt.cm.Blues_r, lines=False, |
124 | | - cache=prior_cache) |
125 | | - plot_contours(f, x, samples, ax_fgivenx, cache=cache) |
126 | | - |
127 | | - # DKL plot |
128 | | - # -------- |
129 | | - ax_dkl = axes[1, 0] |
130 | | - ax_dkl.set_ylabel(r'$D_\mathrm{KL}$') |
131 | | - ax_dkl.set_xlabel(r'$x$') |
132 | | - ax_dkl.set_ylim(bottom=0) |
133 | | - plot_dkl(f, x, samples, prior_samples, ax_dkl, |
134 | | - cache=cache, prior_cache=prior_cache) |
135 | | - |
136 | | - ax_lines.get_shared_x_axes().join(ax_lines, ax_fgivenx, ax_samples) |
137 | | - fig.set_size_inches(6, 6) |
| 92 | + for cache in [None, 'cache/test']: |
| 93 | + if cache is not None: |
| 94 | + prior_cache = cache + '_prior' |
| 95 | + else: |
| 96 | + prior_cache = None |
| 97 | + |
| 98 | + # Plotting |
| 99 | + # ======== |
| 100 | + fig, axes = plt.subplots(2, 2) |
| 101 | + |
| 102 | + # Sample plot |
| 103 | + # ----------- |
| 104 | + ax_samples = axes[0, 0] |
| 105 | + ax_samples.set_ylabel(r'$c$') |
| 106 | + ax_samples.set_xlabel(r'$m$') |
| 107 | + ax_samples.plot(prior_samples.T[0], prior_samples.T[1], 'b.') |
| 108 | + ax_samples.plot(samples.T[0], samples.T[1], 'r.') |
| 109 | + |
| 110 | + # Line plot |
| 111 | + # --------- |
| 112 | + ax_lines = axes[0, 1] |
| 113 | + ax_lines.set_ylabel(r'$y = m x + c$') |
| 114 | + ax_lines.set_xlabel(r'$x$') |
| 115 | + plot_lines(f, x, prior_samples, ax_lines, color='b', cache=prior_cache) |
| 116 | + plot_lines(f, x, samples, ax_lines, color='r', cache=cache) |
| 117 | + |
| 118 | + # Predictive posterior plot |
| 119 | + # ------------------------- |
| 120 | + ax_fgivenx = axes[1, 1] |
| 121 | + ax_fgivenx.set_ylabel(r'$P(y|x)$') |
| 122 | + ax_fgivenx.set_xlabel(r'$x$') |
| 123 | + plot_contours(f, x, prior_samples, ax_fgivenx, |
| 124 | + colors=plt.cm.Blues_r, lines=False, |
| 125 | + cache=prior_cache) |
| 126 | + plot_contours(f, x, samples, ax_fgivenx, cache=cache) |
| 127 | + |
| 128 | + # DKL plot |
| 129 | + # -------- |
| 130 | + ax_dkl = axes[1, 0] |
| 131 | + ax_dkl.set_ylabel(r'$D_\mathrm{KL}$') |
| 132 | + ax_dkl.set_xlabel(r'$x$') |
| 133 | + ax_dkl.set_ylim(bottom=0) |
| 134 | + plot_dkl(f, x, samples, prior_samples, ax_dkl, |
| 135 | + cache=cache, prior_cache=prior_cache) |
| 136 | + |
| 137 | + ax_lines.get_shared_x_axes().join(ax_lines, ax_fgivenx, ax_samples) |
| 138 | + fig.set_size_inches(6, 6) |
0 commit comments