From c4082cf9c08ac13b4f366cc2d161ae13f845645c Mon Sep 17 00:00:00 2001 From: springcoil Date: Sat, 27 Oct 2018 10:36:06 +0200 Subject: [PATCH 1/9] Improvements in error messages and logging for bad initial energy. Co-authored-by: springcoil Co-authored-by: aseyboldt --- RELEASE-NOTES.md | 1 + pymc3/backends/report.py | 1 + pymc3/parallel_sampling.py | 37 +++++++++++++++++++++++------- pymc3/sampling.py | 35 ++++++++++++++++++---------- pymc3/step_methods/hmc/base_hmc.py | 23 ++++++++++++++----- pymc3/tests/test_hmc.py | 3 ++- pymc3/tests/test_step.py | 3 ++- 7 files changed, 75 insertions(+), 28 deletions(-) diff --git a/RELEASE-NOTES.md b/RELEASE-NOTES.md index ec340d9d516..31c5bcb1756 100644 --- a/RELEASE-NOTES.md +++ b/RELEASE-NOTES.md @@ -9,6 +9,7 @@ - Add Incomplete Beta function `incomplete_beta(a, b, value)` - Add log CDF functions to continuous distributions: `Beta`, `Cauchy`, `ExGaussian`, `Exponential`, `Flat`, `Gumbel`, `HalfCauchy`, `HalfFlat`, `HalfNormal`, `Laplace`, `Logistic`, `Lognormal`, `Normal`, `Pareto`, `StudentT`, `Triangular`, `Uniform`, `Wald`, `Weibull`. - Behavior of `sample_posterior_predictive` is now to produce posterior predictive samples, in order, from all values of the `trace`. Previously, by default it would produce 1 chain worth of samples, using a random selection from the `trace` (#3212) +- Show diagnostics for initial energy errors in HMC and NUTS. ### Maintenance diff --git a/pymc3/backends/report.py b/pymc3/backends/report.py index f2b81d87615..391ef5b978a 100644 --- a/pymc3/backends/report.py +++ b/pymc3/backends/report.py @@ -19,6 +19,7 @@ class WarningType(enum.Enum): # Indications that chains did not converge, eg Rhat CONVERGENCE = 6 BAD_ACCEPTANCE = 7 + BAD_ENERGY = 8 SamplerWarning = namedtuple( diff --git a/pymc3/parallel_sampling.py b/pymc3/parallel_sampling.py index 1c4952934ed..7cc75eb22ae 100644 --- a/pymc3/parallel_sampling.py +++ b/pymc3/parallel_sampling.py @@ -5,6 +5,7 @@ import logging from collections import namedtuple import traceback +from pymc3.exceptions import SamplingError import six import numpy as np @@ -14,6 +15,15 @@ logger = logging.getLogger('pymc3') +class ParallelSamplingError(Exception): + def __init__(self, message, chain, warnings=None): + super(ParallelSamplingError, self).__init__(message) + if warnings is None: + warnings = [] + self._chain = chain + self._warnings = warnings + + # Taken from https://hg.python.org/cpython/rev/c4f92b597074 class RemoteTraceback(Exception): def __init__(self, tb): @@ -40,8 +50,8 @@ def rebuild_exc(exc, tb): # Messages -# ('writing_done', is_last, sample_idx, tuning, stats) -# ('error', *exception_info) +# ('writing_done', is_last, sample_idx, tuning, stats, warns) +# ('error', warnings, *exception_info) # ('abort', reason) # ('write_next',) @@ -50,10 +60,10 @@ def rebuild_exc(exc, tb): class _Process(multiprocessing.Process): """Seperate process for each chain. - We communicate with the main process using a pipe, and send finished samples using shared memory. """ + def __init__(self, name, msg_pipe, step_method, shared_point, draws, tune, seed): super(_Process, self).__init__(daemon=True, name=name) @@ -75,7 +85,7 @@ def run(self): pass except BaseException as e: e = ExceptionWithTraceback(e, e.__traceback__) - self._msg_pipe.send(('error', e)) + self._msg_pipe.send(('error', None, e)) finally: self._msg_pipe.close() @@ -110,7 +120,12 @@ def _start_loop(self): while True: if draw < self._draws + self._tune: - point, stats = self._compute_point() + try: + point, stats = self._compute_point() + except SamplingError as e: + warns = self._collect_warnings() + e = ExceptionWithTraceback(e, e.__traceback__) + self._msg_pipe.send(('error', warns, e)) else: return @@ -151,6 +166,7 @@ def _collect_warnings(self): class ProcessAdapter(object): """Control a Chain process from the main thread.""" + def __init__(self, draws, tune, step_method, chain, seed, start): self.chain = chain process_name = "worker_chain_%s" % chain @@ -219,8 +235,13 @@ def recv_draw(processes, timeout=3600): msg = ready[0].recv() if msg[0] == 'error': - old = msg[1] - six.raise_from(RuntimeError('Chain %s failed.' % proc.chain), old) + warns, old_error = msg[1:] + if warns is not None: + error = ParallelSamplingError( + str(old_error), proc.chain, warns) + else: + error = RuntimeError('Chain %s failed.' % proc.chain) + six.raise_from(error, old_error) elif msg[0] == 'writing_done': proc._readable = True proc._num_samples += 1 @@ -333,4 +354,4 @@ def __enter__(self): def __exit__(self, *args): ProcessAdapter.terminate_all(self._samplers) if self._progress is not None: - self._progress.close() + self._progress.close() \ No newline at end of file diff --git a/pymc3/sampling.py b/pymc3/sampling.py index ac54def0056..af4e36a7f2f 100644 --- a/pymc3/sampling.py +++ b/pymc3/sampling.py @@ -986,17 +986,28 @@ def _mp_sample(draws, tune, step, chains, cores, chain, random_seed, draws, tune, chains, cores, random_seed, start, step, chain, progressbar) try: - with sampler: - for draw in sampler: - trace = traces[draw.chain - chain] - if trace.supports_sampler_stats and draw.stats is not None: - trace.record(draw.point, draw.stats) - else: - trace.record(draw.point) - if draw.is_last: - trace.close() - if draw.warnings is not None: - trace._add_warnings(draw.warnings) + try: + with sampler: + for draw in sampler: + trace = traces[draw.chain - chain] + if (trace.supports_sampler_stats + and draw.stats is not None): + trace.record(draw.point, draw.stats) + else: + trace.record(draw.point) + if draw.is_last: + trace.close() + if draw.warnings is not None: + trace._add_warnings(draw.warnings) + except ps.ParallelSamplingError as error: + trace = traces[error._chain - chain] + trace._add_warnings(error._warnings) + for trace in traces: + trace.close() + + multitrace = MultiTrace(traces) + multitrace._report._log_summary() + raise return MultiTrace(traces) except KeyboardInterrupt: traces, length = _choose_chains(traces, tune) @@ -1512,4 +1523,4 @@ def init_nuts(init='auto', chains=1, n_init=500000, model=None, step = pm.NUTS(potential=potential, model=model, **kwargs) - return start, step + return start, step \ No newline at end of file diff --git a/pymc3/step_methods/hmc/base_hmc.py b/pymc3/step_methods/hmc/base_hmc.py index 96ad1658884..a6a94159c1e 100644 --- a/pymc3/step_methods/hmc/base_hmc.py +++ b/pymc3/step_methods/hmc/base_hmc.py @@ -10,6 +10,8 @@ from .quadpotential import quad_potential, QuadPotentialDiagAdapt from pymc3.step_methods import step_sizes from pymc3.backends.report import SamplerWarning, WarningType +from pymc3.exceptions import SamplingError + logger = logging.getLogger('pymc3') HMCStepData = namedtuple( @@ -110,14 +112,23 @@ def astep(self, q0): """Perform a single HMC iteration.""" p0 = self.potential.random() start = self.integrator.compute_state(q0, p0) - model = self._model - + if not np.isfinite(start.energy): + model = self._model check_test_point = model.check_test_point() - error_logp = check_test_point.loc[(np.abs(check_test_point) >= 1e20) | np.isnan(check_test_point)] + error_logp = (check_test_point + .loc[(np.abs(check_test_point) >= 1e20) + | np.isnan(check_test_point)]) self.potential.raise_ok(self._logp_dlogp_func._ordering.vmap) - logger.error("Bad initial energy, check any log probabilities that are inf or -inf, nan or very small:\n{}".format(error_logp.to_string())) - raise ValueError('Bad initial energy') + message_energy = ( + "Bad initial energy, check any log probabilities that " + "are inf or -inf, nan or very small:\n{}" + .format(error_logp.to_string())) + warning = SamplerWarning( + WarningType.BAD_ENERGY, message_energy, 'critical', + self.iter_count, None, None) + self._warnings.append(warning) + raise SamplingError('Bad initial energy') adapt_step = self.tune and self.adapt_step_size step_size = self.step_adapt.current(adapt_step) @@ -190,4 +201,4 @@ def warnings(self): warnings.append(warning) warnings.extend(self.step_adapt.warnings()) - return warnings + return warnings \ No newline at end of file diff --git a/pymc3/tests/test_hmc.py b/pymc3/tests/test_hmc.py index ed50a0494e4..475b657d20c 100644 --- a/pymc3/tests/test_hmc.py +++ b/pymc3/tests/test_hmc.py @@ -3,6 +3,7 @@ from . import models from pymc3.step_methods.hmc.base_hmc import BaseHMC +from pymc3.exceptions import SamplingError import pymc3 import pytest import logging @@ -43,7 +44,7 @@ def test_nuts_tuning(): def test_nuts_error_reporting(caplog): model = pymc3.Model() - with caplog.at_level(logging.ERROR) and pytest.raises(ValueError): + with caplog.at_level(logging.CRITICAL) and pytest.raises(SamplingError): with model: pymc3.HalfNormal('a', sd=1, transform=None, testval=-1) pymc3.HalfNormal('b', sd=1, transform=None) diff --git a/pymc3/tests/test_step.py b/pymc3/tests/test_step.py index ca67369c5bd..206437a6b4f 100644 --- a/pymc3/tests/test_step.py +++ b/pymc3/tests/test_step.py @@ -5,6 +5,7 @@ from .models import (simple_categorical, mv_simple, mv_simple_discrete, mv_prior_simple, simple_2model_continuous) from pymc3.sampling import assign_step_methods, sample +from pymc3.parallel_sampling import ParallelSamplingError from pymc3.model import Model from pymc3.step_methods import (NUTS, BinaryGibbsMetropolis, CategoricalGibbsMetropolis, Metropolis, Slice, CompoundStep, NormalProposal, @@ -427,7 +428,7 @@ def test_multiple_samplers(self, caplog): def test_bad_init(self): with Model(): HalfNormal('a', sd=1, testval=-1, transform=None) - with pytest.raises(ValueError) as error: + with pytest.raises(ParallelSamplingError) as error: sample(init=None) error.match('Bad initial') From 0d5f7541ac4f0abfb4de47f43153c1bffeb31e74 Mon Sep 17 00:00:00 2001 From: springcoil Date: Sat, 27 Oct 2018 11:40:47 +0200 Subject: [PATCH 2/9] Adding another test one for parallel and non-parallel --- pymc3/tests/test_step.py | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/pymc3/tests/test_step.py b/pymc3/tests/test_step.py index 206437a6b4f..c7916e4d19a 100644 --- a/pymc3/tests/test_step.py +++ b/pymc3/tests/test_step.py @@ -6,6 +6,7 @@ mv_prior_simple, simple_2model_continuous) from pymc3.sampling import assign_step_methods, sample from pymc3.parallel_sampling import ParallelSamplingError +from pymc3.exceptions import SamplingError from pymc3.model import Model from pymc3.step_methods import (NUTS, BinaryGibbsMetropolis, CategoricalGibbsMetropolis, Metropolis, Slice, CompoundStep, NormalProposal, @@ -425,11 +426,19 @@ def test_multiple_samplers(self, caplog): messages = [msg.msg for msg in caplog.records] assert all('boolean index did not' not in msg for msg in messages) - def test_bad_init(self): + def test_bad_init_nonparallel(self): + with Model(): + HalfNormal('a', sd=1, testval=-1, transform=None) + with pytest.raises(SamplingError) as error: + sample(init=None, chains=1) + error.match('Bad initial') + + # TODO: This could probably be parameterized instead + def test_bad_init_parallel(self): with Model(): HalfNormal('a', sd=1, testval=-1, transform=None) with pytest.raises(ParallelSamplingError) as error: - sample(init=None) + sample(init=None, chains=4) error.match('Bad initial') def test_linalg(self, caplog): From cd2481f07bef65f4f7fe1dbec945672e0ed66d73 Mon Sep 17 00:00:00 2001 From: springcoil Date: Sat, 27 Oct 2018 13:48:34 +0200 Subject: [PATCH 3/9] Adding random seeds to tests --- .coverage | 1 + pymc3/tests/test_sampling.py | 4 ++-- pymc3/tests/test_step.py | 4 ++-- 3 files changed, 5 insertions(+), 4 deletions(-) create mode 100644 .coverage diff --git a/.coverage b/.coverage new file mode 100644 index 00000000000..2b0e4a67793 --- /dev/null +++ b/.coverage @@ -0,0 +1 @@ +!coverage.py: This is a private format, don't read it directly!{"lines":{"/Users/peadarcoyle/Code/pymc3/pymc3/__init__.py":[2,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,21,22,23,25,26,28,30,31,32,33,34,35],"/Users/peadarcoyle/Code/pymc3/pymc3/blocking.py":[256,5,6,7,8,10,12,13,141,19,22,150,152,25,26,27,156,29,30,24,31,33,35,38,39,40,41,42,44,48,176,51,53,54,55,58,60,63,65,196,73,74,75,76,78,86,88,89,91,220,93,223,225,230,122,233,109,243,247,120,250,252],"/Users/peadarcoyle/Code/pymc3/pymc3/distributions/__init__.py":[1,2,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,51,52,53,54,55,56,57,58,60,61,63,64,65,66,67,68,69,70,71,72,74,75,76,77,78,79,81,82,83,84,85,87,89,90,91,92,93,94,95,96,97,98,99,100,101,102,103,104,105,106,107,108,109,110,111,112,113,114,115,116,117,118,119,120,121,122,123,124,125,126,127,128,129,130,131,132,133,134,135,136,137,138,139,140,141,142,143,144,145,146,147,148,149,150,151,152,153,154,155,156,157,158],"/Users/peadarcoyle/Code/pymc3/pymc3/distributions/timeseries.py":[256,1,2,4,5,6,7,11,12,13,14,15,16,17,142,268,269,21,275,282,156,158,31,33,292,40,168,51,180,313,314,61,191,323,329,340,213,215,90,92,93,225,357,358,363,238,242,125],"/Users/peadarcoyle/Code/pymc3/pymc3/util.py":[1,2,3,130,5,134,135,8,136,137,138,145,148,154,155,157,158,32,161,162,163,164,166,167,168,48,51,65,68,82,85,88,109],"/Users/peadarcoyle/Code/pymc3/pymc3/distributions/continuous.py":[2049,2051,2564,5,6,3075,8,9,10,11,12,13,1546,15,2058,17,18,19,20,21,22,1556,3094,26,28,29,30,31,32,33,1053,1571,36,37,2085,39,3106,3616,3625,40,44,45,2606,47,2608,41,48,49,52,53,55,2105,571,3645,574,2623,2115,2121,75,77,79,81,83,84,598,3670,86,87,1114,2650,1116,3162,1630,3164,1632,3680,98,91,1118,1120,1121,1122,1124,1129,1125,1126,1131,1133,3179,2157,1132,2159,1648,2671,626,2160,1142,1652,2161,2162,2167,1144,2681,3705,2171,119,127,120,124,2163,130,3203,134,2062,135,137,1674,140,2165,653,1167,2704,2193,3228,1181,1182,1695,1184,1185,3747,676,2212,3749,1188,1190,1705,1194,3241,2220,1191,1192,3761,180,693,182,2229,1208,1722,191,1218,2759,3783,2761,2774,216,3291,3804,3293,1128,3302,3815,234,1258,1260,2285,2796,2287,754,243,756,757,758,1783,760,1785,1274,761,2300,3324,1278,763,256,769,3841,3843,260,2820,262,3614,1800,2313,266,263,264,764,766,2831,767,1301,3349,791,280,3862,1823,2336,3361,805,806,807,296,3880,808,811,300,1324,3883,809,819,3380,1335,312,313,1848,315,2359,829,3901,319,2370,1860,333,1870,2894,2896,1370,2907,1372,349,3420,3422,353,1383,3435,365,2416,2418,2935,1913,1915,1405,2433,3457,905,2441,907,1422,1934,2961,1938,3474,1430,2458,924,2973,3484,3491,1961,426,428,941,1454,429,430,2481,431,433,434,436,950,2998,437,441,439,3516,1981,3518,89,2501,1991,3527,974,464,2512,1494,2006,1496,3549,478,479,3040,1505,3042,480,482,485,121,483,1000,3052,495,499,1012,2548,2550,1527,3573,2555,122],"/Users/peadarcoyle/Code/pymc3/pymc3/theanof.py":[1,2,3,4,5,6,7,9,10,11,13,14,15,16,17,18,19,20,21,22,23,24,25,26,29,41,44,59,63,64,65,67,70,83,85,88,91,92,95,96,101,112,122,133,134,138,149,150,160,161,162,164,167,169,173,176,179,182,185,189,205,206,209,224,227,229,230,231,235,236,238,239,241,243,245,246,249,251,254,257,260,262,263,265,272,273,276,277,280,297,298,300,307,311,317,320,322,329,342,364,367,390,402,403,404,407,411,417,418,419,420,421,422,423,426,427,428,429,430,435,436,439,458],"/Users/peadarcoyle/Code/pymc3/pymc3/data.py":[1,2,3,4,5,6,7,8,9,263,266,12,13,14,15,19,289,34,35,39,42,45,51,55,57,62,74,82,84,87,90,94,224,226,228,356,230,361,364,371,251],"/Users/peadarcoyle/Code/pymc3/pymc3/vartypes.py":[1,3,5,6,8,10,11,12,13,14,15,16,17,18,19,20,21,22,23,25,26,31,33,36],"/Users/peadarcoyle/Code/pymc3/pymc3/distributions/transforms.py":[1,2,4,5,6,7,8,9,10,12,13,14,17,23,24,26,43,61,78,93,95,97,101,103,104,105,108,109,111,119,120,121,123,124,125,126,128,129,130,132,137,138,139,140,142,144,145,147,150,151,153,156,159,162,165,168,169,171,174,181,184,187,190,191,193,194,196,197,199,202,205,206,208,210,214,219,223,231,235,238,239,241,243,246,251,255,263,266,269,270,272,274,277,282,286,294,297,300,301,303,309,315,321,324,327,331,332,334,338,341,344,348,351,360,362,364,365,367,379,391,403,413,415,418,420,421,423,426,429,432,435,438,439,441,444,447,450,454,458,459,463,469,475,481],"/Users/peadarcoyle/Code/pymc3/pymc3/model.py":[1,2,3,4,5,7,8,9,10,11,12,14,15,16,17,18,19,20,21,24,25,28,31,35,37,38,39,41,46,69,70,74,75,78,80,82,113,149,152,153,155,156,158,159,160,162,163,165,166,168,172,173,174,176,179,180,185,189,190,191,194,197,198,199,201,204,206,210,214,218,222,226,230,235,239,243,247,251,255,258,261,262,263,264,266,278,279,280,281,282,283,284,287,289,290,291,293,297,298,301,305,306,307,308,309,310,313,314,315,317,327,332,339,343,344,345,346,347,348,351,352,354,356,359,363,366,397,399,400,403,404,406,409,412,413,414,415,416,417,418,419,420,421,422,423,427,432,433,434,435,436,437,439,440,442,443,445,447,448,450,451,452,453,455,462,463,466,469,473,474,476,478,479,480,482,483,485,490,492,493,494,495,497,499,502,505,506,507,508,510,512,514,515,516,517,519,520,521,523,524,525,526,527,529,530,533,620,621,623,624,626,629,630,631,632,633,634,636,637,638,646,647,648,649,650,651,653,655,657,659,661,668,672,673,675,677,678,680,682,684,686,688,690,694,699,700,703,704,707,708,709,711,714,715,716,717,720,721,723,735,743,750,755,757,762,764,767,769,772,773,775,780,783,785,803,804,805,806,807,808,809,811,812,813,814,815,816,818,819,820,821,822,823,845,846,848,850,853,854,855,857,859,861,864,870,872,875,876,882,891,904,905,909,911,924,926,939,940,942,971,1009,1024,1025,1027,1028,1030,1043,1046,1063,1080,1089,1090,1091,1092,1096,1097,1100,1101,1103,1104,1106,1107,1110,1112,1114,1115,1116,1118,1119,1120,1122,1125,1141,1142,1179,1182,1183,1186,1198,1199,1200,1202,1203,1204,1205,1206,1207,1208,1211,1212,1213,1214,1215,1217,1218,1219,1221,1230,1232,1238,1257,1284,1287,1290,1334,1343,1345,1351,1354,1356,1385,1400,1405,1426,1445,1457,1461,1462,1463,1464,1466,1468,1469,1470,1471,1472,1474,1476,1477,1479,1481,1482,1483,1484,1485,1486,1487,1489,1498,1500,1506,1513,1516,1517,1518,1520],"/Users/peadarcoyle/Code/pymc3/pymc3/math.py":[256,1,2,3,131,5,6,135,263,132,128,11,12,13,14,15,16,17,18,19,20,21,143,275,280,26,284,157,161,37,170,171,298,299,301,176,49,307,187,319,192,195,198,328,202,206,80,81,82,337,84,342,88,99,126,104,105,108,114,121,250,253,254],"/Users/peadarcoyle/Code/pymc3/pymc3/memoize.py":[1,2,3,4,5,8,9,14,15,16,18,20,25,26,27,29,30,31,33,34,37,49,50,53,58,62,66,67,68,69],"/Users/peadarcoyle/Code/pymc3/pymc3/distributions/distribution.py":[1,2,4,5,6,7,8,9,13,15,16,19,20,23,24,25,26,28,29,36,37,38,40,41,42,46,49,51,52,53,55,56,57,58,60,61,62,63,64,66,67,69,70,71,72,73,75,83,84,85,87,88,90,91,93,95,99,111,113,119,121,124,125,126,127,130,132,133,139,147,151,152,154,156,157,160,161,164,168,169,172,173,175,177,178,179,180,183,199,201,209,217,330,331,355,421,427,436],"/Users/peadarcoyle/Code/pymc3/pymc3/distributions/special.py":[1,2,3,4,6,38,8,9,39,12,26],"/Users/peadarcoyle/Code/pymc3/pymc3/distributions/dist_math.py":[5,6,262,8,9,10,11,12,13,14,15,266,17,18,274,21,22,277,280,278,25,284,287,421,170,44,46,47,51,54,55,56,57,314,58,61,65,321,70,73,74,460,77,78,81,82,85,92,102,236,111,239,241,243,118,246,250,125],"/Users/peadarcoyle/Code/pymc3/pymc3/distributions/multivariate.py":[4,5,6,7,8,10,12,13,14,1550,16,17,18,19,20,21,22,23,24,531,1042,27,28,29,30,33,34,1074,569,576,1095,590,1102,80,600,1119,608,612,615,106,619,1040,626,122,636,125,639,643,646,649,140,154,684,686,1206,1209,703,709,1222,727,219,221,736,227,1283,272,278,1310,288,817,1331,1339,836,327,330,340,357,367,380,1426,402,1428,404,1435,420,943,944,441,449,1475,970,460,1487,468,1000,1517,499,1523,501],"/Users/peadarcoyle/Code/pymc3/pymc3/distributions/discrete.py":[1,2,3,4,5,7,8,9,10,519,13,14,15,16,530,19,1043,1045,1053,1062,565,567,59,572,61,1083,62,63,64,578,67,65,583,73,74,75,1100,77,78,79,592,80,82,92,629,631,638,644,651,1163,1165,145,657,147,154,1179,668,173,180,189,701,703,200,713,722,739,748,238,240,756,758,764,255,261,774,778,272,785,788,281,318,319,836,838,327,845,336,852,346,351,867,358,878,369,411,413,927,929,418,424,937,944,433,442,960,977,490,492,498,506],"/Users/peadarcoyle/Code/pymc3/pymc3/distributions/mixture.py":[1,2,4,5,6,7,8,133,11,142,21,149,186,69,71,217,219,229,105,117,125],"/Users/peadarcoyle/Code/pymc3/pymc3/distributions/bound.py":[1,129,3,4,5,7,9,10,12,15,16,158,36,48,194,68,196,209,88,90,227,110,126],"/Users/peadarcoyle/Code/pymc3/pymc3/glm/__init__.py":[1,2],"/Users/peadarcoyle/Code/pymc3/pymc3/glm/linear.py":[1,2,3,4,5,6,10,11,140,15,143,152,34,35,36,39,85,87,96,117,120],"/Users/peadarcoyle/Code/pymc3/pymc3/glm/families.py":[1,2,3,5,6,7,9,17,19,22,23,24,25,28,30,31,32,34,43,62,79,86,87,88,89,90,91,94,95,96,97,98,101,102,103,104,105,108,109,110,111,112,115,116,117,118,119,120],"/Users/peadarcoyle/Code/pymc3/pymc3/glm/utils.py":[1,2,3,4,7],"/Users/peadarcoyle/Code/pymc3/pymc3/gp/__init__.py":[1,2,3,4],"/Users/peadarcoyle/Code/pymc3/pymc3/gp/cov.py":[1,2,3,4,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,533,24,547,36,38,551,39,40,41,45,568,569,63,66,522,579,69,585,75,78,81,595,84,87,104,105,626,116,628,644,139,140,653,144,145,659,149,163,165,171,180,187,194,196,197,198,200,203,210,217,219,223,226,233,242,244,255,268,272,275,279,285,287,290,301,309,311,316,323,325,329,335,344,346,353,361,363,369,376,378,383,389,391,396,402,404,408,413,421,426,432,434,439,443,448,463,466,476,483,488,504,507],"/Users/peadarcoyle/Code/pymc3/pymc3/gp/mean.py":[1,3,6,9,11,21,24,28,32,34,37,45,47,51,55,65,67,72,76,77,82,86,87,92],"/Users/peadarcoyle/Code/pymc3/pymc3/gp/util.py":[1,2,3,5,6,7,8,11,20,25,44,46,47,48,57,59,60,62,64,65,66,67,68,69,72],"/Users/peadarcoyle/Code/pymc3/pymc3/gp/gp.py":[1152,1,2,385,4,5,262,7,8,9,10,643,12,13,14,1036,17,20,917,150,23,536,25,1175,29,288,672,801,802,37,165,40,771,43,429,46,302,176,560,50,51,561,900,1028,1075,953,954,447,329,330,722,211,212,853,470,855,1114,247,863,866,631,104,106,875,250,109,621,239,623,241,625,1009,756,373,1011,375,120,378,1019,508,1022],"/Users/peadarcoyle/Code/pymc3/pymc3/model_graph.py":[1,3,37,5,6,9,41,76,141,174,115,20,21,88,28,61,95],"/Users/peadarcoyle/Code/pymc3/pymc3/stats.py":[1,2,3,4,5,387,7,8,9,10,11,12,14,15,16,17,19,661,22,1046,25,26,29,802,35,643,803,679,173,1071,437,61,62,319,64,701,702,67,68,839,465,853,854,855,985,98,99,998,240,1009,754,760,761,124],"/Users/peadarcoyle/Code/pymc3/pymc3/sampling.py":[512,1,2,3,4,5,517,7,8,9,10,11,522,13,14,15,16,17,1037,20,21,22,23,24,25,412,27,28,540,30,31,32,541,34,35,542,544,38,545,546,41,1066,547,548,549,550,551,1069,1070,1074,563,564,565,518,560,569,419,65,66,68,69,70,72,73,74,75,77,78,81,82,84,87,88,426,610,611,612,613,614,615,1445,504,618,428,621,623,626,628,629,118,119,630,121,631,633,635,636,939,640,641,642,643,644,645,1158,135,136,137,646,139,140,141,1166,142,647,648,654,655,148,149,150,151,661,153,665,666,156,157,667,671,672,161,162,163,164,668,166,167,168,171,178,179,181,182,183,184,187,189,195,415,729,733,416,744,662,663,1297,787,1304,507,818,321,323,1350,333,334,335,340,345,347,349,351,352,353,354,355,356,357,360,366,371,885,374,375,376,1398,378,1400,380,1401,1403,1407,385,1410,1411,388,389,1413,391,392,393,394,395,396,397,398,1414,1416,1418,1419,1420,1423,1424,1425,1426,408,409,406,1429,1436,1437,410,411,1440,1441,1435,1443,1444,413,1438,1439,417,418,1442,420,422,425,421,423,424,427,940,942,944,945,430,432,433,435,436,437,438,439,440,441,445,961,452,453,964,965,968,458,459,460,970,462,463,971,465,466,467,972,975,978,471,979,473,980,983,476,985,986,987,988,989,990,991,992,993,994,995,998,1001,999,1002,1003,1004,1005,1006,1000,1008,1009,1010,1011,1012,1524,503,1016,505,506,502,1526,1017],"/Users/peadarcoyle/Code/pymc3/pymc3/backends/__init__.py":[128,129,130,119,120,121,122,123,125,126,127],"/Users/peadarcoyle/Code/pymc3/pymc3/backends/ndarray.py":[4,5,6,7,8,10,11,14,57,81,82,83,85,91,109,129,143,155,157,159,160,161,162,163,164,168,181,183,184,196,197,198,199,201,204,205,206,207,208,209,210,221,229,230,232,234,236,237,238,239,240,242,243,245,246,247,250,251,252,254,255,259,260,261,262,264,279,285,287,288,289,290,291,292,294,296,297,298,299,300,301,303,305,309,310,311,314],"/Users/peadarcoyle/Code/pymc3/pymc3/backends/base.py":[513,515,5,6,7,9,10,11,13,14,16,530,19,20,23,37,39,41,42,556,44,45,46,47,48,49,50,559,560,54,55,561,566,60,61,62,63,64,65,66,67,68,70,71,75,76,79,82,86,87,88,89,93,95,109,110,112,124,133,142,145,160,178,181,184,185,186,189,190,191,192,196,200,204,210,221,259,261,262,263,264,266,268,269,270,271,273,278,282,284,286,288,290,291,292,294,295,296,297,299,307,308,310,311,317,318,321,322,324,327,330,331,337,338,342,343,344,346,348,349,351,353,355,356,358,359,360,362,363,364,366,408,428,462,480,483,484,485,486,490,491,492,494,496,497,498,499,500,502,511],"/Users/peadarcoyle/Code/pymc3/pymc3/backends/report.py":[1,2,3,4,132,133,7,136,137,10,11,139,13,14,15,16,141,18,145,20,21,22,151,152,25,26,27,154,155,156,31,32,33,34,35,163,165,134,39,40,41,42,43,44,166,46,174,167,168,169,51,171,162,48,49,54,57,58,59,60,61,55,63,159,160,142,158,143,161,146,147,148,157],"/Users/peadarcoyle/Code/pymc3/pymc3/backends/text.py":[101,41,43,108,141,17,146,18,19,20,116,22,23,57,122,27,188,87,24,159],"/Users/peadarcoyle/Code/pymc3/pymc3/backends/tracetab.py":[2,4,5,7,9,12,44,62],"/Users/peadarcoyle/Code/pymc3/pymc3/backends/sqlite.py":[131,142,273,18,19,20,275,22,23,281,26,158,30,288,33,35,39,167,41,297,43,48,176,53,183,57,58,61,193,75,203,77,331,341,347,94,355,118,249,254],"/Users/peadarcoyle/Code/pymc3/pymc3/backends/hdf5.py":[1,2,3,132,5,18,159,32,34,36,167,42,46,50,184,57,188,64,69,198,74,206,79,84,212,89,94,101,114],"/Users/peadarcoyle/Code/pymc3/pymc3/step_methods/__init__.py":[1,3,5,6,7,8,9,10,11,12,13,14,16,17,19,21,23],"/Users/peadarcoyle/Code/pymc3/pymc3/step_methods/compound.py":[5,6,9,11,13,14,15,16,17,18,19,20,22,23,24,25,26,27,28,33,34,35,38,44,45,46,47,48,49,51,52,53,55],"/Users/peadarcoyle/Code/pymc3/pymc3/step_methods/hmc/__init__.py":[1,2],"/Users/peadarcoyle/Code/pymc3/pymc3/step_methods/hmc/hmc.py":[1,3,4,5,6,133,136,9,138,137,12,16,20,22,23,24,26,27,28,29,30,31,32,33,34,35,36,37,42,91],"/Users/peadarcoyle/Code/pymc3/pymc3/step_methods/arraystep.py":[1,2,3,4,5,6,7,10,13,14,21,22,23,24,25,28,30,32,33,34,36,37,39,40,43,46,47,49,52,54,57,72,74,75,78,81,85,87,88,89,90,91,92,93,94,95,97,99,100,101,102,103,104,106,107,108,111,122,124,131,146,152,154,162,163,164,165,166,168,169,170,172,174,175,176,182,187,189,202,220,222,223,224,225,227,228,231,232,233,234,240,242,243,244,246,247,248,249,256,274,275,277],"/Users/peadarcoyle/Code/pymc3/pymc3/step_methods/hmc/integration.py":[1,3,4,7,10,11,14,15,17,18,19,20,25,27,29,30,31,32,33,35,53,54,55,58,60,61,62,63,67,68,69,71,72,73,74,75,76,82,86,88,91,93,96,98,99,101,105],"/Users/peadarcoyle/Code/pymc3/pymc3/step_methods/hmc/base_hmc.py":[1,3,4,5,6,7,8,9,10,11,12,13,15,17,18,19,22,23,24,27,28,30,36,58,60,61,62,64,65,67,68,69,70,72,73,74,75,77,79,80,81,82,84,88,91,92,96,97,99,100,101,102,104,111,113,114,116,117,118,119,120,121,122,124,126,127,128,129,130,131,133,134,135,137,140,142,143,144,145,146,147,148,150,151,153,154,157,158,159,161,163,164,165,168,169,172,173,175,177,181,183,186,187,188,191,192,194,195,196,198,199,200,201,203,204],"/Users/peadarcoyle/Code/pymc3/pymc3/tuning/__init__.py":[1,2],"/Users/peadarcoyle/Code/pymc3/pymc3/tuning/starting.py":[5,6,7,8,9,10,11,12,13,14,15,16,18,19,21,153,25,157,161,167,168,183,212],"/Users/peadarcoyle/Code/pymc3/pymc3/tuning/scaling.py":[131,6,7,8,9,10,11,74,13,106,135,16,139,50,115,90,124],"/Users/peadarcoyle/Code/pymc3/pymc3/step_methods/hmc/quadpotential.py":[1,2,3,4,5,7,10,11,14,51,64,65,70,75,76,80,83,86,89,97,115,119,124,125,128,130,132,134,137,141,142,144,148,149,150,151,152,153,154,155,156,157,158,160,162,164,166,167,170,172,173,175,177,178,180,181,182,183,184,186,188,189,191,193,194,195,197,201,203,219,233,248,252,254,261,267,289,290,293,294,295,296,297,298,300,301,302,304,306,308,310,313,314,315,316,317,318,319,320,321,323,324,326,327,331,335,336,338,356,363,367,373,379,380,382,395,402,407,413,419,420,422,436,440,445,451,456,459,460,462,463,465],"/Users/peadarcoyle/Code/pymc3/pymc3/step_methods/step_sizes.py":[1,2,4,7,8,9,10,11,12,13,14,15,16,17,18,20,21,22,24,26,27,28,29,31,32,33,35,36,37,38,40,42,43,46,47,48,49,52,53,54,55,56,59,60,61,62,63,65],"/Users/peadarcoyle/Code/pymc3/pymc3/exceptions.py":[1,4,5],"/Users/peadarcoyle/Code/pymc3/pymc3/step_methods/hmc/nuts.py":[1,3,5,6,8,9,10,11,12,13,15,18,19,21,24,73,75,77,78,80,81,82,83,84,85,86,87,88,89,90,93,154,156,157,158,160,161,162,164,166,168,169,170,172,173,178,179,180,182,185,186,187,189,190,191,192,194,200,204,207,208,209,212,213,228,229,230,231,232,233,235,236,237,238,239,240,241,242,243,245,257,258,259,260,262,263,264,266,267,268,270,271,273,274,275,277,278,280,281,282,284,286,288,289,290,291,292,294,295,298,299,300,301,302,303,304,305,306,307,309,310,311,312,313,314,316,317,318,320,321,322,323,325,326,328,330,331,332,334,335,336,338,340,341,342,344,345,347,348,349,351,353,354,355,356,357,358,359],"/Users/peadarcoyle/Code/pymc3/pymc3/step_methods/metropolis.py":[1,2,3,4,5,7,8,9,10,12,13,14,528,529,19,20,531,532,534,24,25,535,539,21,29,30,26,34,35,39,40,45,46,50,51,58,572,67,90,91,604,93,94,96,97,611,101,103,105,618,107,109,110,623,112,624,114,115,626,627,629,631,632,121,633,122,123,124,125,128,129,130,131,133,135,136,137,139,140,148,150,151,152,153,154,162,163,164,166,169,170,173,175,177,180,219,235,236,238,240,241,242,245,261,284,290,291,292,294,296,299,315,316,318,342,362,368,369,370,372,374,377,384,385,387,429,445,458,478,484,485,486,490,492,495],"/Users/peadarcoyle/Code/pymc3/pymc3/step_methods/sgmcmc.py":[1,2,4,5,6,7,8,9,10,12,14,18,24,409,33,42,172,177,180,310,184,317,63,204,339,340,342,222,223,352,225,100,360,110,239,249],"/Users/peadarcoyle/Code/pymc3/pymc3/step_methods/gibbs.py":[5,6,7,8,9,10,42,12,13,14,15,46,18,53,23,59,28],"/Users/peadarcoyle/Code/pymc3/pymc3/step_methods/slicer.py":[32,33,97,3,4,35,6,7,8,9,36,11,99,13,102,103,16,49,100,31],"/Users/peadarcoyle/Code/pymc3/pymc3/step_methods/elliptical_slice.py":[1,2,3,68,5,6,7,8,37,10,70,72,13,112,84],"/Users/peadarcoyle/Code/pymc3/pymc3/step_methods/smc.py":[3,4,5,6,7,8,10,11,12,13,14,15,273,18,20,23,294,176,60,63,194,73,244,254],"/Users/peadarcoyle/Code/pymc3/pymc3/plots/__init__.py":[1,2,3,4,5,6,7,8,9],"/Users/peadarcoyle/Code/pymc3/pymc3/plots/autocorrplot.py":[1,2,4,5,9,13],"/Users/peadarcoyle/Code/pymc3/pymc3/plots/utils.py":[1,2,36,5,7,10,15],"/Users/peadarcoyle/Code/pymc3/pymc3/plots/compareplot.py":[1,2,3,9],"/Users/peadarcoyle/Code/pymc3/pymc3/plots/forestplot.py":[1,2,3,68,69,6,7,8,9,70,11,71,25],"/Users/peadarcoyle/Code/pymc3/pymc3/diagnostics.py":[1,3,4,5,6,100,8,11,12,179],"/Users/peadarcoyle/Code/pymc3/pymc3/plots/kdeplot.py":[1,2,3,5,6,11,52],"/Users/peadarcoyle/Code/pymc3/pymc3/plots/posteriorplot.py":[1,2,5,7,9,12,13,14,123],"/Users/peadarcoyle/Code/pymc3/pymc3/plots/artists.py":[161,2,3,1,5,6,9,16,53,150,26],"/Users/peadarcoyle/Code/pymc3/pymc3/plots/traceplot.py":[1,2,5,7,8,11,12,13,14],"/Users/peadarcoyle/Code/pymc3/pymc3/plots/energyplot.py":[1,3,4,5,8,12],"/Users/peadarcoyle/Code/pymc3/pymc3/plots/densityplot.py":[1,2,3,130,6,7,8,13],"/Users/peadarcoyle/Code/pymc3/pymc3/plots/pairplot.py":[1,3,4,5,8,9,15],"/Users/peadarcoyle/Code/pymc3/pymc3/variational/__init__.py":[32,33,2,3,40,41,47,48,49,50,19,20,51],"/Users/peadarcoyle/Code/pymc3/pymc3/variational/updates.py":[389,1031,776,273,536,669,163,170,950,455,584,334,224,97,98,99,100,865,102,103,104,108,109,110,111,112,113,114,115,116,117,118,119,120,124],"/Users/peadarcoyle/Code/pymc3/pymc3/variational/inference.py":[640,1,258,3,4,5,645,7,8,10,11,12,15,16,272,18,146,21,22,23,24,25,26,27,28,29,32,35,295,296,552,554,555,300,48,50,694,55,184,57,442,569,444,696,701,448,70,88,477,479,483,612,614,493,494,503,635],"/Users/peadarcoyle/Code/pymc3/pymc3/variational/test_functions.py":[1,2,3,6,10,18,50,21,22],"/Users/peadarcoyle/Code/pymc3/pymc3/variational/opvi.py":[1537,1556,1557,1046,1558,32,34,35,36,1060,38,39,40,1572,42,43,44,45,1068,1069,48,49,50,51,54,55,56,57,58,62,63,66,67,1602,1093,70,71,1606,74,75,1098,1610,78,79,1614,82,83,1618,86,87,1622,1113,90,1626,1633,1125,1637,103,1641,106,1647,112,115,1148,1156,137,139,140,1164,143,147,1176,156,1181,158,162,163,164,1186,166,167,168,1197,1201,1205,1210,1211,1214,704,706,707,708,709,712,713,716,717,720,721,722,723,724,726,728,729,1242,730,1244,731,732,733,734,225,226,227,737,735,747,242,243,244,757,1272,1276,261,262,263,264,265,266,267,777,1288,1289,1291,1296,1300,1313,803,1318,810,1323,1328,1335,1340,1345,324,325,1350,1355,845,1360,1365,1372,861,350,1378,1384,361,877,1390,1395,372,374,375,376,377,378,379,1400,381,1405,1412,390,391,392,393,394,395,396,397,398,399,401,1437,1438,928,421,933,934,936,944,439,952,1465,444,1470,1483,975,468,469,470,1495,471,473,985,477,989,480,993,1506,483,1509,492],"/Users/peadarcoyle/Code/pymc3/pymc3/variational/approximations.py":[1,2,3,5,6,7,8,9,10,11,12,527,16,17,18,19,20,528,529,531,24,25,539,30,31,32,33,542,35,548,39,551,552,43,555,558,559,562,51,565,566,55,568,574,64,577,578,580,84,91,100,101,106,107,108,109,111,120,143,158,162,170,177,182,186,199,213,214,217,218,219,220,221,223,236,261,268,286,303,307,311,315,320,324,332,379,380,382,425,454,468,480,484,490,494,501,506],"/Users/peadarcoyle/Code/pymc3/pymc3/variational/flows.py":[512,1,2,3,513,5,6,7,8,9,514,516,12,13,14,15,16,17,521,523,529,21,534,535,536,537,539,540,546,548,39,41,554,559,560,561,562,564,565,57,67,579,70,73,75,588,82,90,103,104,105,106,107,108,110,112,113,114,115,116,118,126,134,155,180,184,193,194,203,207,211,222,224,231,240,244,248,255,258,262,263,266,267,271,275,279,283,284,286,287,296,297,298,300,303,330,357,358,359,361,367,368,369,371,374,400,401,403,404,422,423,424,426,429,453,481,482,487,492,498,499,500,502,505,511],"/Users/peadarcoyle/Code/pymc3/pymc3/variational/operators.py":[1,2,3,4,5,6,9,10,14,36,38,42,48,57,59,64,81,107,108,109,110,111,113,117],"/Users/peadarcoyle/Code/pymc3/pymc3/variational/stein.py":[64,1,2,3,4,5,33,68,8,72,26,12,13,44,82,19,52,83,58],"/Users/peadarcoyle/Code/pymc3/pymc3/variational/callbacks.py":[1,3,6,7,8,137,12,13,140,143,17,21,25,26,27,31,55,57,58,59,60,61,62,63,65,79,84,117,118,122],"/Users/peadarcoyle/Code/pymc3/pymc3/tests/__init__.py":[1,3],"/Users/peadarcoyle/Code/pymc3/pymc3/tests/conftest.py":[1,2,3,4,33,7,9,10,11,14,16,17,18,19,22],"/Users/peadarcoyle/Code/pymc3/pymc3/tests/test_step.py":[1,2,4,5,7,8,9,10,11,15,16,19,20,21,22,23,24,25,28,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,57,58,59,60,61,62,63,64,65,66,67,68,69,70,71,72,73,74,75,76,77,78,79,80,81,82,83,84,85,86,87,88,89,90,91,92,93,94,95,96,97,98,99,100,101,102,103,104,105,106,107,108,109,110,111,112,113,114,115,116,117,118,119,120,121,122,123,124,125,126,127,128,129,130,131,132,133,134,135,136,137,138,139,140,141,142,143,144,145,146,147,148,149,150,151,152,153,154,155,156,157,158,159,162,165,168,173,213,218,242,258,272,288,289,302,311,312,314,315,323,324,334,335,342,349,360,367,387,389,391,402,417,418,419,420,421,422,423,424,425,426,427,429,430,431,432,433,434,437,438,439,440,441,442,444,445,446,447,448,449,450,451,452,453,454,464,465,466,468,470,471,472,473,477,478,479,481,482,483,487,488,489,491],"/Users/peadarcoyle/Code/pymc3/pymc3/tests/checks.py":[1,10,4],"/Users/peadarcoyle/Code/pymc3/pymc3/tests/models.py":[1,2,3,4,5,6,7,8,11,142,20,148,155,31,162,40,55,61,72,82,97,115],"/Users/peadarcoyle/Code/pymc3/pymc3/parallel_sampling.py":[1,2,3,4,5,6,7,8,10,11,13,15,18,19,20,21,23,24,28,29,30,32,36,37,38,39,40,41,43,44,47,48,49,61,65,67,69,70,71,72,73,74,75,76,78,79,82,83,84,86,87,88,90,92,93,94,95,96,97,98,99,101,102,103,105,106,108,109,110,112,113,115,116,118,121,122,123,124,125,126,127,128,130,132,133,134,136,137,139,140,141,142,143,145,146,147,148,152,153,154,158,160,161,162,167,168,170,171,172,173,175,176,177,178,179,180,181,182,185,186,187,188,189,191,192,194,195,196,198,200,205,207,209,210,212,213,214,216,217,219,220,222,225,226,227,229,230,231,233,234,235,237,238,239,240,241,244,245,246,247,248,252,253,254,255,256,260,261,262,263,264,266,276,277,278,282,284,285,286,287,289,294,296,299,300,301,302,304,305,307,308,309,310,311,313,314,315,316,317,318,320,321,323,325,326,327,328,329,331,332,333,334,335,341,342,345,346,348,350,351,352,354,355,356,357],"/Users/peadarcoyle/Code/pymc3/pymc3/tests/helpers.py":[1,2,3,4,5,6,9,10,12,16,21,25,26,35,38,41,52,54,56,73,86,92],"/Users/peadarcoyle/Code/pymc3/pymc3/tests/test_shared.py":[],"/Users/peadarcoyle/Code/pymc3/pymc3/tests/test_model.py":[],"/Users/peadarcoyle/Code/pymc3/pymc3/tests/test_diagnostics.py":[],"/Users/peadarcoyle/Code/pymc3/pymc3/tests/test_text_backend.py":[],"/Users/peadarcoyle/Code/pymc3/pymc3/tests/test_models_utils.py":[],"/Users/peadarcoyle/Code/pymc3/pymc3/tests/test_sgfs.py":[],"/Users/peadarcoyle/Code/pymc3/pymc3/tests/test_posteriors.py":[],"/Users/peadarcoyle/Code/pymc3/pymc3/tests/test_plots.py":[],"/Users/peadarcoyle/Code/pymc3/pymc3/tests/test_stats.py":[],"/Users/peadarcoyle/Code/pymc3/pymc3/tests/test_distributions_timeseries.py":[],"/Users/peadarcoyle/Code/pymc3/pymc3/tests/test_tracetab.py":[],"/Users/peadarcoyle/Code/pymc3/pymc3/tests/test_missing.py":[],"/Users/peadarcoyle/Code/pymc3/pymc3/tests/test_tuning.py":[],"/Users/peadarcoyle/Code/pymc3/pymc3/tests/test_smc.py":[],"/Users/peadarcoyle/Code/pymc3/pymc3/tests/test_mixture.py":[],"/Users/peadarcoyle/Code/pymc3/pymc3/tests/test_variational_inference.py":[],"/Users/peadarcoyle/Code/pymc3/pymc3/tests/test_model_func.py":[],"/Users/peadarcoyle/Code/pymc3/pymc3/tests/test_special_functions.py":[],"/Users/peadarcoyle/Code/pymc3/pymc3/tests/test_quadpotential.py":[],"/Users/peadarcoyle/Code/pymc3/pymc3/tests/test_model_helpers.py":[],"/Users/peadarcoyle/Code/pymc3/pymc3/tests/backend_fixtures.py":[],"/Users/peadarcoyle/Code/pymc3/pymc3/tests/test_glm.py":[],"/Users/peadarcoyle/Code/pymc3/pymc3/tests/sampler_fixtures.py":[],"/Users/peadarcoyle/Code/pymc3/pymc3/tests/test_starting.py":[],"/Users/peadarcoyle/Code/pymc3/pymc3/tests/test_ndarray_backend.py":[],"/Users/peadarcoyle/Code/pymc3/pymc3/tests/test_gp.py":[],"/Users/peadarcoyle/Code/pymc3/pymc3/tests/test_parallel_sampling.py":[],"/Users/peadarcoyle/Code/pymc3/pymc3/tests/test_updates.py":[],"/Users/peadarcoyle/Code/pymc3/pymc3/tests/test_hdf5_backend.py":[],"/Users/peadarcoyle/Code/pymc3/pymc3/tests/test_profile.py":[],"/Users/peadarcoyle/Code/pymc3/pymc3/tests/test_memo.py":[],"/Users/peadarcoyle/Code/pymc3/pymc3/tests/test_util.py":[],"/Users/peadarcoyle/Code/pymc3/pymc3/tests/test_sqlite_backend.py":[],"/Users/peadarcoyle/Code/pymc3/pymc3/tests/test_model_graph.py":[],"/Users/peadarcoyle/Code/pymc3/pymc3/tests/test_models_linear.py":[],"/Users/peadarcoyle/Code/pymc3/pymc3/tests/test_distributions_random.py":[],"/Users/peadarcoyle/Code/pymc3/pymc3/tests/test_modelcontext.py":[],"/Users/peadarcoyle/Code/pymc3/pymc3/tests/test_pickling.py":[],"/Users/peadarcoyle/Code/pymc3/pymc3/tests/test_theanof.py":[],"/Users/peadarcoyle/Code/pymc3/pymc3/tests/test_distributions.py":[],"/Users/peadarcoyle/Code/pymc3/pymc3/tests/test_transforms.py":[],"/Users/peadarcoyle/Code/pymc3/pymc3/tests/test_distribution_defaults.py":[],"/Users/peadarcoyle/Code/pymc3/pymc3/tests/test_sampling.py":[],"/Users/peadarcoyle/Code/pymc3/pymc3/tests/test_dist_math.py":[],"/Users/peadarcoyle/Code/pymc3/pymc3/tests/test_minibatches.py":[],"/Users/peadarcoyle/Code/pymc3/pymc3/tests/test_hmc.py":[],"/Users/peadarcoyle/Code/pymc3/pymc3/tests/test_math.py":[],"/Users/peadarcoyle/Code/pymc3/pymc3/tests/test_posdef_sym.py":[],"/Users/peadarcoyle/Code/pymc3/pymc3/tests/test_types.py":[],"/Users/peadarcoyle/Code/pymc3/pymc3/tests/test_random.py":[],"/Users/peadarcoyle/Code/pymc3/pymc3/step_methods/hmc/trajectory.py":[]}} \ No newline at end of file diff --git a/pymc3/tests/test_sampling.py b/pymc3/tests/test_sampling.py index 4adb5ed4874..09584cbf9d7 100644 --- a/pymc3/tests/test_sampling.py +++ b/pymc3/tests/test_sampling.py @@ -16,8 +16,8 @@ from scipy import stats import pytest - - + + @pytest.mark.xfail(condition=(theano.config.floatX == "float32"), reason="Fails on float32") class TestSample(SeededTest): def setup_method(self): diff --git a/pymc3/tests/test_step.py b/pymc3/tests/test_step.py index c7916e4d19a..22ed41b072f 100644 --- a/pymc3/tests/test_step.py +++ b/pymc3/tests/test_step.py @@ -430,7 +430,7 @@ def test_bad_init_nonparallel(self): with Model(): HalfNormal('a', sd=1, testval=-1, transform=None) with pytest.raises(SamplingError) as error: - sample(init=None, chains=1) + sample(init=None, chains=1, random_seed=1) error.match('Bad initial') # TODO: This could probably be parameterized instead @@ -438,7 +438,7 @@ def test_bad_init_parallel(self): with Model(): HalfNormal('a', sd=1, testval=-1, transform=None) with pytest.raises(ParallelSamplingError) as error: - sample(init=None, chains=4) + sample(init=None, chains=4, random_seed=1) error.match('Bad initial') def test_linalg(self, caplog): From b1563ee267b2a08b717ff97648bd61091812c234 Mon Sep 17 00:00:00 2001 From: springcoil Date: Sat, 27 Oct 2018 16:43:54 +0200 Subject: [PATCH 4/9] Removed unnecessary files and formatting in test_sampling --- .coverage | 1 - pymc3/tests/test_sampling.py | 5 ++--- 2 files changed, 2 insertions(+), 4 deletions(-) delete mode 100644 .coverage diff --git a/.coverage b/.coverage deleted file mode 100644 index 2b0e4a67793..00000000000 --- a/.coverage +++ /dev/null @@ -1 +0,0 @@ -!coverage.py: This is a private format, don't read it directly!{"lines":{"/Users/peadarcoyle/Code/pymc3/pymc3/__init__.py":[2,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,21,22,23,25,26,28,30,31,32,33,34,35],"/Users/peadarcoyle/Code/pymc3/pymc3/blocking.py":[256,5,6,7,8,10,12,13,141,19,22,150,152,25,26,27,156,29,30,24,31,33,35,38,39,40,41,42,44,48,176,51,53,54,55,58,60,63,65,196,73,74,75,76,78,86,88,89,91,220,93,223,225,230,122,233,109,243,247,120,250,252],"/Users/peadarcoyle/Code/pymc3/pymc3/distributions/__init__.py":[1,2,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,51,52,53,54,55,56,57,58,60,61,63,64,65,66,67,68,69,70,71,72,74,75,76,77,78,79,81,82,83,84,85,87,89,90,91,92,93,94,95,96,97,98,99,100,101,102,103,104,105,106,107,108,109,110,111,112,113,114,115,116,117,118,119,120,121,122,123,124,125,126,127,128,129,130,131,132,133,134,135,136,137,138,139,140,141,142,143,144,145,146,147,148,149,150,151,152,153,154,155,156,157,158],"/Users/peadarcoyle/Code/pymc3/pymc3/distributions/timeseries.py":[256,1,2,4,5,6,7,11,12,13,14,15,16,17,142,268,269,21,275,282,156,158,31,33,292,40,168,51,180,313,314,61,191,323,329,340,213,215,90,92,93,225,357,358,363,238,242,125],"/Users/peadarcoyle/Code/pymc3/pymc3/util.py":[1,2,3,130,5,134,135,8,136,137,138,145,148,154,155,157,158,32,161,162,163,164,166,167,168,48,51,65,68,82,85,88,109],"/Users/peadarcoyle/Code/pymc3/pymc3/distributions/continuous.py":[2049,2051,2564,5,6,3075,8,9,10,11,12,13,1546,15,2058,17,18,19,20,21,22,1556,3094,26,28,29,30,31,32,33,1053,1571,36,37,2085,39,3106,3616,3625,40,44,45,2606,47,2608,41,48,49,52,53,55,2105,571,3645,574,2623,2115,2121,75,77,79,81,83,84,598,3670,86,87,1114,2650,1116,3162,1630,3164,1632,3680,98,91,1118,1120,1121,1122,1124,1129,1125,1126,1131,1133,3179,2157,1132,2159,1648,2671,626,2160,1142,1652,2161,2162,2167,1144,2681,3705,2171,119,127,120,124,2163,130,3203,134,2062,135,137,1674,140,2165,653,1167,2704,2193,3228,1181,1182,1695,1184,1185,3747,676,2212,3749,1188,1190,1705,1194,3241,2220,1191,1192,3761,180,693,182,2229,1208,1722,191,1218,2759,3783,2761,2774,216,3291,3804,3293,1128,3302,3815,234,1258,1260,2285,2796,2287,754,243,756,757,758,1783,760,1785,1274,761,2300,3324,1278,763,256,769,3841,3843,260,2820,262,3614,1800,2313,266,263,264,764,766,2831,767,1301,3349,791,280,3862,1823,2336,3361,805,806,807,296,3880,808,811,300,1324,3883,809,819,3380,1335,312,313,1848,315,2359,829,3901,319,2370,1860,333,1870,2894,2896,1370,2907,1372,349,3420,3422,353,1383,3435,365,2416,2418,2935,1913,1915,1405,2433,3457,905,2441,907,1422,1934,2961,1938,3474,1430,2458,924,2973,3484,3491,1961,426,428,941,1454,429,430,2481,431,433,434,436,950,2998,437,441,439,3516,1981,3518,89,2501,1991,3527,974,464,2512,1494,2006,1496,3549,478,479,3040,1505,3042,480,482,485,121,483,1000,3052,495,499,1012,2548,2550,1527,3573,2555,122],"/Users/peadarcoyle/Code/pymc3/pymc3/theanof.py":[1,2,3,4,5,6,7,9,10,11,13,14,15,16,17,18,19,20,21,22,23,24,25,26,29,41,44,59,63,64,65,67,70,83,85,88,91,92,95,96,101,112,122,133,134,138,149,150,160,161,162,164,167,169,173,176,179,182,185,189,205,206,209,224,227,229,230,231,235,236,238,239,241,243,245,246,249,251,254,257,260,262,263,265,272,273,276,277,280,297,298,300,307,311,317,320,322,329,342,364,367,390,402,403,404,407,411,417,418,419,420,421,422,423,426,427,428,429,430,435,436,439,458],"/Users/peadarcoyle/Code/pymc3/pymc3/data.py":[1,2,3,4,5,6,7,8,9,263,266,12,13,14,15,19,289,34,35,39,42,45,51,55,57,62,74,82,84,87,90,94,224,226,228,356,230,361,364,371,251],"/Users/peadarcoyle/Code/pymc3/pymc3/vartypes.py":[1,3,5,6,8,10,11,12,13,14,15,16,17,18,19,20,21,22,23,25,26,31,33,36],"/Users/peadarcoyle/Code/pymc3/pymc3/distributions/transforms.py":[1,2,4,5,6,7,8,9,10,12,13,14,17,23,24,26,43,61,78,93,95,97,101,103,104,105,108,109,111,119,120,121,123,124,125,126,128,129,130,132,137,138,139,140,142,144,145,147,150,151,153,156,159,162,165,168,169,171,174,181,184,187,190,191,193,194,196,197,199,202,205,206,208,210,214,219,223,231,235,238,239,241,243,246,251,255,263,266,269,270,272,274,277,282,286,294,297,300,301,303,309,315,321,324,327,331,332,334,338,341,344,348,351,360,362,364,365,367,379,391,403,413,415,418,420,421,423,426,429,432,435,438,439,441,444,447,450,454,458,459,463,469,475,481],"/Users/peadarcoyle/Code/pymc3/pymc3/model.py":[1,2,3,4,5,7,8,9,10,11,12,14,15,16,17,18,19,20,21,24,25,28,31,35,37,38,39,41,46,69,70,74,75,78,80,82,113,149,152,153,155,156,158,159,160,162,163,165,166,168,172,173,174,176,179,180,185,189,190,191,194,197,198,199,201,204,206,210,214,218,222,226,230,235,239,243,247,251,255,258,261,262,263,264,266,278,279,280,281,282,283,284,287,289,290,291,293,297,298,301,305,306,307,308,309,310,313,314,315,317,327,332,339,343,344,345,346,347,348,351,352,354,356,359,363,366,397,399,400,403,404,406,409,412,413,414,415,416,417,418,419,420,421,422,423,427,432,433,434,435,436,437,439,440,442,443,445,447,448,450,451,452,453,455,462,463,466,469,473,474,476,478,479,480,482,483,485,490,492,493,494,495,497,499,502,505,506,507,508,510,512,514,515,516,517,519,520,521,523,524,525,526,527,529,530,533,620,621,623,624,626,629,630,631,632,633,634,636,637,638,646,647,648,649,650,651,653,655,657,659,661,668,672,673,675,677,678,680,682,684,686,688,690,694,699,700,703,704,707,708,709,711,714,715,716,717,720,721,723,735,743,750,755,757,762,764,767,769,772,773,775,780,783,785,803,804,805,806,807,808,809,811,812,813,814,815,816,818,819,820,821,822,823,845,846,848,850,853,854,855,857,859,861,864,870,872,875,876,882,891,904,905,909,911,924,926,939,940,942,971,1009,1024,1025,1027,1028,1030,1043,1046,1063,1080,1089,1090,1091,1092,1096,1097,1100,1101,1103,1104,1106,1107,1110,1112,1114,1115,1116,1118,1119,1120,1122,1125,1141,1142,1179,1182,1183,1186,1198,1199,1200,1202,1203,1204,1205,1206,1207,1208,1211,1212,1213,1214,1215,1217,1218,1219,1221,1230,1232,1238,1257,1284,1287,1290,1334,1343,1345,1351,1354,1356,1385,1400,1405,1426,1445,1457,1461,1462,1463,1464,1466,1468,1469,1470,1471,1472,1474,1476,1477,1479,1481,1482,1483,1484,1485,1486,1487,1489,1498,1500,1506,1513,1516,1517,1518,1520],"/Users/peadarcoyle/Code/pymc3/pymc3/math.py":[256,1,2,3,131,5,6,135,263,132,128,11,12,13,14,15,16,17,18,19,20,21,143,275,280,26,284,157,161,37,170,171,298,299,301,176,49,307,187,319,192,195,198,328,202,206,80,81,82,337,84,342,88,99,126,104,105,108,114,121,250,253,254],"/Users/peadarcoyle/Code/pymc3/pymc3/memoize.py":[1,2,3,4,5,8,9,14,15,16,18,20,25,26,27,29,30,31,33,34,37,49,50,53,58,62,66,67,68,69],"/Users/peadarcoyle/Code/pymc3/pymc3/distributions/distribution.py":[1,2,4,5,6,7,8,9,13,15,16,19,20,23,24,25,26,28,29,36,37,38,40,41,42,46,49,51,52,53,55,56,57,58,60,61,62,63,64,66,67,69,70,71,72,73,75,83,84,85,87,88,90,91,93,95,99,111,113,119,121,124,125,126,127,130,132,133,139,147,151,152,154,156,157,160,161,164,168,169,172,173,175,177,178,179,180,183,199,201,209,217,330,331,355,421,427,436],"/Users/peadarcoyle/Code/pymc3/pymc3/distributions/special.py":[1,2,3,4,6,38,8,9,39,12,26],"/Users/peadarcoyle/Code/pymc3/pymc3/distributions/dist_math.py":[5,6,262,8,9,10,11,12,13,14,15,266,17,18,274,21,22,277,280,278,25,284,287,421,170,44,46,47,51,54,55,56,57,314,58,61,65,321,70,73,74,460,77,78,81,82,85,92,102,236,111,239,241,243,118,246,250,125],"/Users/peadarcoyle/Code/pymc3/pymc3/distributions/multivariate.py":[4,5,6,7,8,10,12,13,14,1550,16,17,18,19,20,21,22,23,24,531,1042,27,28,29,30,33,34,1074,569,576,1095,590,1102,80,600,1119,608,612,615,106,619,1040,626,122,636,125,639,643,646,649,140,154,684,686,1206,1209,703,709,1222,727,219,221,736,227,1283,272,278,1310,288,817,1331,1339,836,327,330,340,357,367,380,1426,402,1428,404,1435,420,943,944,441,449,1475,970,460,1487,468,1000,1517,499,1523,501],"/Users/peadarcoyle/Code/pymc3/pymc3/distributions/discrete.py":[1,2,3,4,5,7,8,9,10,519,13,14,15,16,530,19,1043,1045,1053,1062,565,567,59,572,61,1083,62,63,64,578,67,65,583,73,74,75,1100,77,78,79,592,80,82,92,629,631,638,644,651,1163,1165,145,657,147,154,1179,668,173,180,189,701,703,200,713,722,739,748,238,240,756,758,764,255,261,774,778,272,785,788,281,318,319,836,838,327,845,336,852,346,351,867,358,878,369,411,413,927,929,418,424,937,944,433,442,960,977,490,492,498,506],"/Users/peadarcoyle/Code/pymc3/pymc3/distributions/mixture.py":[1,2,4,5,6,7,8,133,11,142,21,149,186,69,71,217,219,229,105,117,125],"/Users/peadarcoyle/Code/pymc3/pymc3/distributions/bound.py":[1,129,3,4,5,7,9,10,12,15,16,158,36,48,194,68,196,209,88,90,227,110,126],"/Users/peadarcoyle/Code/pymc3/pymc3/glm/__init__.py":[1,2],"/Users/peadarcoyle/Code/pymc3/pymc3/glm/linear.py":[1,2,3,4,5,6,10,11,140,15,143,152,34,35,36,39,85,87,96,117,120],"/Users/peadarcoyle/Code/pymc3/pymc3/glm/families.py":[1,2,3,5,6,7,9,17,19,22,23,24,25,28,30,31,32,34,43,62,79,86,87,88,89,90,91,94,95,96,97,98,101,102,103,104,105,108,109,110,111,112,115,116,117,118,119,120],"/Users/peadarcoyle/Code/pymc3/pymc3/glm/utils.py":[1,2,3,4,7],"/Users/peadarcoyle/Code/pymc3/pymc3/gp/__init__.py":[1,2,3,4],"/Users/peadarcoyle/Code/pymc3/pymc3/gp/cov.py":[1,2,3,4,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,533,24,547,36,38,551,39,40,41,45,568,569,63,66,522,579,69,585,75,78,81,595,84,87,104,105,626,116,628,644,139,140,653,144,145,659,149,163,165,171,180,187,194,196,197,198,200,203,210,217,219,223,226,233,242,244,255,268,272,275,279,285,287,290,301,309,311,316,323,325,329,335,344,346,353,361,363,369,376,378,383,389,391,396,402,404,408,413,421,426,432,434,439,443,448,463,466,476,483,488,504,507],"/Users/peadarcoyle/Code/pymc3/pymc3/gp/mean.py":[1,3,6,9,11,21,24,28,32,34,37,45,47,51,55,65,67,72,76,77,82,86,87,92],"/Users/peadarcoyle/Code/pymc3/pymc3/gp/util.py":[1,2,3,5,6,7,8,11,20,25,44,46,47,48,57,59,60,62,64,65,66,67,68,69,72],"/Users/peadarcoyle/Code/pymc3/pymc3/gp/gp.py":[1152,1,2,385,4,5,262,7,8,9,10,643,12,13,14,1036,17,20,917,150,23,536,25,1175,29,288,672,801,802,37,165,40,771,43,429,46,302,176,560,50,51,561,900,1028,1075,953,954,447,329,330,722,211,212,853,470,855,1114,247,863,866,631,104,106,875,250,109,621,239,623,241,625,1009,756,373,1011,375,120,378,1019,508,1022],"/Users/peadarcoyle/Code/pymc3/pymc3/model_graph.py":[1,3,37,5,6,9,41,76,141,174,115,20,21,88,28,61,95],"/Users/peadarcoyle/Code/pymc3/pymc3/stats.py":[1,2,3,4,5,387,7,8,9,10,11,12,14,15,16,17,19,661,22,1046,25,26,29,802,35,643,803,679,173,1071,437,61,62,319,64,701,702,67,68,839,465,853,854,855,985,98,99,998,240,1009,754,760,761,124],"/Users/peadarcoyle/Code/pymc3/pymc3/sampling.py":[512,1,2,3,4,5,517,7,8,9,10,11,522,13,14,15,16,17,1037,20,21,22,23,24,25,412,27,28,540,30,31,32,541,34,35,542,544,38,545,546,41,1066,547,548,549,550,551,1069,1070,1074,563,564,565,518,560,569,419,65,66,68,69,70,72,73,74,75,77,78,81,82,84,87,88,426,610,611,612,613,614,615,1445,504,618,428,621,623,626,628,629,118,119,630,121,631,633,635,636,939,640,641,642,643,644,645,1158,135,136,137,646,139,140,141,1166,142,647,648,654,655,148,149,150,151,661,153,665,666,156,157,667,671,672,161,162,163,164,668,166,167,168,171,178,179,181,182,183,184,187,189,195,415,729,733,416,744,662,663,1297,787,1304,507,818,321,323,1350,333,334,335,340,345,347,349,351,352,353,354,355,356,357,360,366,371,885,374,375,376,1398,378,1400,380,1401,1403,1407,385,1410,1411,388,389,1413,391,392,393,394,395,396,397,398,1414,1416,1418,1419,1420,1423,1424,1425,1426,408,409,406,1429,1436,1437,410,411,1440,1441,1435,1443,1444,413,1438,1439,417,418,1442,420,422,425,421,423,424,427,940,942,944,945,430,432,433,435,436,437,438,439,440,441,445,961,452,453,964,965,968,458,459,460,970,462,463,971,465,466,467,972,975,978,471,979,473,980,983,476,985,986,987,988,989,990,991,992,993,994,995,998,1001,999,1002,1003,1004,1005,1006,1000,1008,1009,1010,1011,1012,1524,503,1016,505,506,502,1526,1017],"/Users/peadarcoyle/Code/pymc3/pymc3/backends/__init__.py":[128,129,130,119,120,121,122,123,125,126,127],"/Users/peadarcoyle/Code/pymc3/pymc3/backends/ndarray.py":[4,5,6,7,8,10,11,14,57,81,82,83,85,91,109,129,143,155,157,159,160,161,162,163,164,168,181,183,184,196,197,198,199,201,204,205,206,207,208,209,210,221,229,230,232,234,236,237,238,239,240,242,243,245,246,247,250,251,252,254,255,259,260,261,262,264,279,285,287,288,289,290,291,292,294,296,297,298,299,300,301,303,305,309,310,311,314],"/Users/peadarcoyle/Code/pymc3/pymc3/backends/base.py":[513,515,5,6,7,9,10,11,13,14,16,530,19,20,23,37,39,41,42,556,44,45,46,47,48,49,50,559,560,54,55,561,566,60,61,62,63,64,65,66,67,68,70,71,75,76,79,82,86,87,88,89,93,95,109,110,112,124,133,142,145,160,178,181,184,185,186,189,190,191,192,196,200,204,210,221,259,261,262,263,264,266,268,269,270,271,273,278,282,284,286,288,290,291,292,294,295,296,297,299,307,308,310,311,317,318,321,322,324,327,330,331,337,338,342,343,344,346,348,349,351,353,355,356,358,359,360,362,363,364,366,408,428,462,480,483,484,485,486,490,491,492,494,496,497,498,499,500,502,511],"/Users/peadarcoyle/Code/pymc3/pymc3/backends/report.py":[1,2,3,4,132,133,7,136,137,10,11,139,13,14,15,16,141,18,145,20,21,22,151,152,25,26,27,154,155,156,31,32,33,34,35,163,165,134,39,40,41,42,43,44,166,46,174,167,168,169,51,171,162,48,49,54,57,58,59,60,61,55,63,159,160,142,158,143,161,146,147,148,157],"/Users/peadarcoyle/Code/pymc3/pymc3/backends/text.py":[101,41,43,108,141,17,146,18,19,20,116,22,23,57,122,27,188,87,24,159],"/Users/peadarcoyle/Code/pymc3/pymc3/backends/tracetab.py":[2,4,5,7,9,12,44,62],"/Users/peadarcoyle/Code/pymc3/pymc3/backends/sqlite.py":[131,142,273,18,19,20,275,22,23,281,26,158,30,288,33,35,39,167,41,297,43,48,176,53,183,57,58,61,193,75,203,77,331,341,347,94,355,118,249,254],"/Users/peadarcoyle/Code/pymc3/pymc3/backends/hdf5.py":[1,2,3,132,5,18,159,32,34,36,167,42,46,50,184,57,188,64,69,198,74,206,79,84,212,89,94,101,114],"/Users/peadarcoyle/Code/pymc3/pymc3/step_methods/__init__.py":[1,3,5,6,7,8,9,10,11,12,13,14,16,17,19,21,23],"/Users/peadarcoyle/Code/pymc3/pymc3/step_methods/compound.py":[5,6,9,11,13,14,15,16,17,18,19,20,22,23,24,25,26,27,28,33,34,35,38,44,45,46,47,48,49,51,52,53,55],"/Users/peadarcoyle/Code/pymc3/pymc3/step_methods/hmc/__init__.py":[1,2],"/Users/peadarcoyle/Code/pymc3/pymc3/step_methods/hmc/hmc.py":[1,3,4,5,6,133,136,9,138,137,12,16,20,22,23,24,26,27,28,29,30,31,32,33,34,35,36,37,42,91],"/Users/peadarcoyle/Code/pymc3/pymc3/step_methods/arraystep.py":[1,2,3,4,5,6,7,10,13,14,21,22,23,24,25,28,30,32,33,34,36,37,39,40,43,46,47,49,52,54,57,72,74,75,78,81,85,87,88,89,90,91,92,93,94,95,97,99,100,101,102,103,104,106,107,108,111,122,124,131,146,152,154,162,163,164,165,166,168,169,170,172,174,175,176,182,187,189,202,220,222,223,224,225,227,228,231,232,233,234,240,242,243,244,246,247,248,249,256,274,275,277],"/Users/peadarcoyle/Code/pymc3/pymc3/step_methods/hmc/integration.py":[1,3,4,7,10,11,14,15,17,18,19,20,25,27,29,30,31,32,33,35,53,54,55,58,60,61,62,63,67,68,69,71,72,73,74,75,76,82,86,88,91,93,96,98,99,101,105],"/Users/peadarcoyle/Code/pymc3/pymc3/step_methods/hmc/base_hmc.py":[1,3,4,5,6,7,8,9,10,11,12,13,15,17,18,19,22,23,24,27,28,30,36,58,60,61,62,64,65,67,68,69,70,72,73,74,75,77,79,80,81,82,84,88,91,92,96,97,99,100,101,102,104,111,113,114,116,117,118,119,120,121,122,124,126,127,128,129,130,131,133,134,135,137,140,142,143,144,145,146,147,148,150,151,153,154,157,158,159,161,163,164,165,168,169,172,173,175,177,181,183,186,187,188,191,192,194,195,196,198,199,200,201,203,204],"/Users/peadarcoyle/Code/pymc3/pymc3/tuning/__init__.py":[1,2],"/Users/peadarcoyle/Code/pymc3/pymc3/tuning/starting.py":[5,6,7,8,9,10,11,12,13,14,15,16,18,19,21,153,25,157,161,167,168,183,212],"/Users/peadarcoyle/Code/pymc3/pymc3/tuning/scaling.py":[131,6,7,8,9,10,11,74,13,106,135,16,139,50,115,90,124],"/Users/peadarcoyle/Code/pymc3/pymc3/step_methods/hmc/quadpotential.py":[1,2,3,4,5,7,10,11,14,51,64,65,70,75,76,80,83,86,89,97,115,119,124,125,128,130,132,134,137,141,142,144,148,149,150,151,152,153,154,155,156,157,158,160,162,164,166,167,170,172,173,175,177,178,180,181,182,183,184,186,188,189,191,193,194,195,197,201,203,219,233,248,252,254,261,267,289,290,293,294,295,296,297,298,300,301,302,304,306,308,310,313,314,315,316,317,318,319,320,321,323,324,326,327,331,335,336,338,356,363,367,373,379,380,382,395,402,407,413,419,420,422,436,440,445,451,456,459,460,462,463,465],"/Users/peadarcoyle/Code/pymc3/pymc3/step_methods/step_sizes.py":[1,2,4,7,8,9,10,11,12,13,14,15,16,17,18,20,21,22,24,26,27,28,29,31,32,33,35,36,37,38,40,42,43,46,47,48,49,52,53,54,55,56,59,60,61,62,63,65],"/Users/peadarcoyle/Code/pymc3/pymc3/exceptions.py":[1,4,5],"/Users/peadarcoyle/Code/pymc3/pymc3/step_methods/hmc/nuts.py":[1,3,5,6,8,9,10,11,12,13,15,18,19,21,24,73,75,77,78,80,81,82,83,84,85,86,87,88,89,90,93,154,156,157,158,160,161,162,164,166,168,169,170,172,173,178,179,180,182,185,186,187,189,190,191,192,194,200,204,207,208,209,212,213,228,229,230,231,232,233,235,236,237,238,239,240,241,242,243,245,257,258,259,260,262,263,264,266,267,268,270,271,273,274,275,277,278,280,281,282,284,286,288,289,290,291,292,294,295,298,299,300,301,302,303,304,305,306,307,309,310,311,312,313,314,316,317,318,320,321,322,323,325,326,328,330,331,332,334,335,336,338,340,341,342,344,345,347,348,349,351,353,354,355,356,357,358,359],"/Users/peadarcoyle/Code/pymc3/pymc3/step_methods/metropolis.py":[1,2,3,4,5,7,8,9,10,12,13,14,528,529,19,20,531,532,534,24,25,535,539,21,29,30,26,34,35,39,40,45,46,50,51,58,572,67,90,91,604,93,94,96,97,611,101,103,105,618,107,109,110,623,112,624,114,115,626,627,629,631,632,121,633,122,123,124,125,128,129,130,131,133,135,136,137,139,140,148,150,151,152,153,154,162,163,164,166,169,170,173,175,177,180,219,235,236,238,240,241,242,245,261,284,290,291,292,294,296,299,315,316,318,342,362,368,369,370,372,374,377,384,385,387,429,445,458,478,484,485,486,490,492,495],"/Users/peadarcoyle/Code/pymc3/pymc3/step_methods/sgmcmc.py":[1,2,4,5,6,7,8,9,10,12,14,18,24,409,33,42,172,177,180,310,184,317,63,204,339,340,342,222,223,352,225,100,360,110,239,249],"/Users/peadarcoyle/Code/pymc3/pymc3/step_methods/gibbs.py":[5,6,7,8,9,10,42,12,13,14,15,46,18,53,23,59,28],"/Users/peadarcoyle/Code/pymc3/pymc3/step_methods/slicer.py":[32,33,97,3,4,35,6,7,8,9,36,11,99,13,102,103,16,49,100,31],"/Users/peadarcoyle/Code/pymc3/pymc3/step_methods/elliptical_slice.py":[1,2,3,68,5,6,7,8,37,10,70,72,13,112,84],"/Users/peadarcoyle/Code/pymc3/pymc3/step_methods/smc.py":[3,4,5,6,7,8,10,11,12,13,14,15,273,18,20,23,294,176,60,63,194,73,244,254],"/Users/peadarcoyle/Code/pymc3/pymc3/plots/__init__.py":[1,2,3,4,5,6,7,8,9],"/Users/peadarcoyle/Code/pymc3/pymc3/plots/autocorrplot.py":[1,2,4,5,9,13],"/Users/peadarcoyle/Code/pymc3/pymc3/plots/utils.py":[1,2,36,5,7,10,15],"/Users/peadarcoyle/Code/pymc3/pymc3/plots/compareplot.py":[1,2,3,9],"/Users/peadarcoyle/Code/pymc3/pymc3/plots/forestplot.py":[1,2,3,68,69,6,7,8,9,70,11,71,25],"/Users/peadarcoyle/Code/pymc3/pymc3/diagnostics.py":[1,3,4,5,6,100,8,11,12,179],"/Users/peadarcoyle/Code/pymc3/pymc3/plots/kdeplot.py":[1,2,3,5,6,11,52],"/Users/peadarcoyle/Code/pymc3/pymc3/plots/posteriorplot.py":[1,2,5,7,9,12,13,14,123],"/Users/peadarcoyle/Code/pymc3/pymc3/plots/artists.py":[161,2,3,1,5,6,9,16,53,150,26],"/Users/peadarcoyle/Code/pymc3/pymc3/plots/traceplot.py":[1,2,5,7,8,11,12,13,14],"/Users/peadarcoyle/Code/pymc3/pymc3/plots/energyplot.py":[1,3,4,5,8,12],"/Users/peadarcoyle/Code/pymc3/pymc3/plots/densityplot.py":[1,2,3,130,6,7,8,13],"/Users/peadarcoyle/Code/pymc3/pymc3/plots/pairplot.py":[1,3,4,5,8,9,15],"/Users/peadarcoyle/Code/pymc3/pymc3/variational/__init__.py":[32,33,2,3,40,41,47,48,49,50,19,20,51],"/Users/peadarcoyle/Code/pymc3/pymc3/variational/updates.py":[389,1031,776,273,536,669,163,170,950,455,584,334,224,97,98,99,100,865,102,103,104,108,109,110,111,112,113,114,115,116,117,118,119,120,124],"/Users/peadarcoyle/Code/pymc3/pymc3/variational/inference.py":[640,1,258,3,4,5,645,7,8,10,11,12,15,16,272,18,146,21,22,23,24,25,26,27,28,29,32,35,295,296,552,554,555,300,48,50,694,55,184,57,442,569,444,696,701,448,70,88,477,479,483,612,614,493,494,503,635],"/Users/peadarcoyle/Code/pymc3/pymc3/variational/test_functions.py":[1,2,3,6,10,18,50,21,22],"/Users/peadarcoyle/Code/pymc3/pymc3/variational/opvi.py":[1537,1556,1557,1046,1558,32,34,35,36,1060,38,39,40,1572,42,43,44,45,1068,1069,48,49,50,51,54,55,56,57,58,62,63,66,67,1602,1093,70,71,1606,74,75,1098,1610,78,79,1614,82,83,1618,86,87,1622,1113,90,1626,1633,1125,1637,103,1641,106,1647,112,115,1148,1156,137,139,140,1164,143,147,1176,156,1181,158,162,163,164,1186,166,167,168,1197,1201,1205,1210,1211,1214,704,706,707,708,709,712,713,716,717,720,721,722,723,724,726,728,729,1242,730,1244,731,732,733,734,225,226,227,737,735,747,242,243,244,757,1272,1276,261,262,263,264,265,266,267,777,1288,1289,1291,1296,1300,1313,803,1318,810,1323,1328,1335,1340,1345,324,325,1350,1355,845,1360,1365,1372,861,350,1378,1384,361,877,1390,1395,372,374,375,376,377,378,379,1400,381,1405,1412,390,391,392,393,394,395,396,397,398,399,401,1437,1438,928,421,933,934,936,944,439,952,1465,444,1470,1483,975,468,469,470,1495,471,473,985,477,989,480,993,1506,483,1509,492],"/Users/peadarcoyle/Code/pymc3/pymc3/variational/approximations.py":[1,2,3,5,6,7,8,9,10,11,12,527,16,17,18,19,20,528,529,531,24,25,539,30,31,32,33,542,35,548,39,551,552,43,555,558,559,562,51,565,566,55,568,574,64,577,578,580,84,91,100,101,106,107,108,109,111,120,143,158,162,170,177,182,186,199,213,214,217,218,219,220,221,223,236,261,268,286,303,307,311,315,320,324,332,379,380,382,425,454,468,480,484,490,494,501,506],"/Users/peadarcoyle/Code/pymc3/pymc3/variational/flows.py":[512,1,2,3,513,5,6,7,8,9,514,516,12,13,14,15,16,17,521,523,529,21,534,535,536,537,539,540,546,548,39,41,554,559,560,561,562,564,565,57,67,579,70,73,75,588,82,90,103,104,105,106,107,108,110,112,113,114,115,116,118,126,134,155,180,184,193,194,203,207,211,222,224,231,240,244,248,255,258,262,263,266,267,271,275,279,283,284,286,287,296,297,298,300,303,330,357,358,359,361,367,368,369,371,374,400,401,403,404,422,423,424,426,429,453,481,482,487,492,498,499,500,502,505,511],"/Users/peadarcoyle/Code/pymc3/pymc3/variational/operators.py":[1,2,3,4,5,6,9,10,14,36,38,42,48,57,59,64,81,107,108,109,110,111,113,117],"/Users/peadarcoyle/Code/pymc3/pymc3/variational/stein.py":[64,1,2,3,4,5,33,68,8,72,26,12,13,44,82,19,52,83,58],"/Users/peadarcoyle/Code/pymc3/pymc3/variational/callbacks.py":[1,3,6,7,8,137,12,13,140,143,17,21,25,26,27,31,55,57,58,59,60,61,62,63,65,79,84,117,118,122],"/Users/peadarcoyle/Code/pymc3/pymc3/tests/__init__.py":[1,3],"/Users/peadarcoyle/Code/pymc3/pymc3/tests/conftest.py":[1,2,3,4,33,7,9,10,11,14,16,17,18,19,22],"/Users/peadarcoyle/Code/pymc3/pymc3/tests/test_step.py":[1,2,4,5,7,8,9,10,11,15,16,19,20,21,22,23,24,25,28,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,57,58,59,60,61,62,63,64,65,66,67,68,69,70,71,72,73,74,75,76,77,78,79,80,81,82,83,84,85,86,87,88,89,90,91,92,93,94,95,96,97,98,99,100,101,102,103,104,105,106,107,108,109,110,111,112,113,114,115,116,117,118,119,120,121,122,123,124,125,126,127,128,129,130,131,132,133,134,135,136,137,138,139,140,141,142,143,144,145,146,147,148,149,150,151,152,153,154,155,156,157,158,159,162,165,168,173,213,218,242,258,272,288,289,302,311,312,314,315,323,324,334,335,342,349,360,367,387,389,391,402,417,418,419,420,421,422,423,424,425,426,427,429,430,431,432,433,434,437,438,439,440,441,442,444,445,446,447,448,449,450,451,452,453,454,464,465,466,468,470,471,472,473,477,478,479,481,482,483,487,488,489,491],"/Users/peadarcoyle/Code/pymc3/pymc3/tests/checks.py":[1,10,4],"/Users/peadarcoyle/Code/pymc3/pymc3/tests/models.py":[1,2,3,4,5,6,7,8,11,142,20,148,155,31,162,40,55,61,72,82,97,115],"/Users/peadarcoyle/Code/pymc3/pymc3/parallel_sampling.py":[1,2,3,4,5,6,7,8,10,11,13,15,18,19,20,21,23,24,28,29,30,32,36,37,38,39,40,41,43,44,47,48,49,61,65,67,69,70,71,72,73,74,75,76,78,79,82,83,84,86,87,88,90,92,93,94,95,96,97,98,99,101,102,103,105,106,108,109,110,112,113,115,116,118,121,122,123,124,125,126,127,128,130,132,133,134,136,137,139,140,141,142,143,145,146,147,148,152,153,154,158,160,161,162,167,168,170,171,172,173,175,176,177,178,179,180,181,182,185,186,187,188,189,191,192,194,195,196,198,200,205,207,209,210,212,213,214,216,217,219,220,222,225,226,227,229,230,231,233,234,235,237,238,239,240,241,244,245,246,247,248,252,253,254,255,256,260,261,262,263,264,266,276,277,278,282,284,285,286,287,289,294,296,299,300,301,302,304,305,307,308,309,310,311,313,314,315,316,317,318,320,321,323,325,326,327,328,329,331,332,333,334,335,341,342,345,346,348,350,351,352,354,355,356,357],"/Users/peadarcoyle/Code/pymc3/pymc3/tests/helpers.py":[1,2,3,4,5,6,9,10,12,16,21,25,26,35,38,41,52,54,56,73,86,92],"/Users/peadarcoyle/Code/pymc3/pymc3/tests/test_shared.py":[],"/Users/peadarcoyle/Code/pymc3/pymc3/tests/test_model.py":[],"/Users/peadarcoyle/Code/pymc3/pymc3/tests/test_diagnostics.py":[],"/Users/peadarcoyle/Code/pymc3/pymc3/tests/test_text_backend.py":[],"/Users/peadarcoyle/Code/pymc3/pymc3/tests/test_models_utils.py":[],"/Users/peadarcoyle/Code/pymc3/pymc3/tests/test_sgfs.py":[],"/Users/peadarcoyle/Code/pymc3/pymc3/tests/test_posteriors.py":[],"/Users/peadarcoyle/Code/pymc3/pymc3/tests/test_plots.py":[],"/Users/peadarcoyle/Code/pymc3/pymc3/tests/test_stats.py":[],"/Users/peadarcoyle/Code/pymc3/pymc3/tests/test_distributions_timeseries.py":[],"/Users/peadarcoyle/Code/pymc3/pymc3/tests/test_tracetab.py":[],"/Users/peadarcoyle/Code/pymc3/pymc3/tests/test_missing.py":[],"/Users/peadarcoyle/Code/pymc3/pymc3/tests/test_tuning.py":[],"/Users/peadarcoyle/Code/pymc3/pymc3/tests/test_smc.py":[],"/Users/peadarcoyle/Code/pymc3/pymc3/tests/test_mixture.py":[],"/Users/peadarcoyle/Code/pymc3/pymc3/tests/test_variational_inference.py":[],"/Users/peadarcoyle/Code/pymc3/pymc3/tests/test_model_func.py":[],"/Users/peadarcoyle/Code/pymc3/pymc3/tests/test_special_functions.py":[],"/Users/peadarcoyle/Code/pymc3/pymc3/tests/test_quadpotential.py":[],"/Users/peadarcoyle/Code/pymc3/pymc3/tests/test_model_helpers.py":[],"/Users/peadarcoyle/Code/pymc3/pymc3/tests/backend_fixtures.py":[],"/Users/peadarcoyle/Code/pymc3/pymc3/tests/test_glm.py":[],"/Users/peadarcoyle/Code/pymc3/pymc3/tests/sampler_fixtures.py":[],"/Users/peadarcoyle/Code/pymc3/pymc3/tests/test_starting.py":[],"/Users/peadarcoyle/Code/pymc3/pymc3/tests/test_ndarray_backend.py":[],"/Users/peadarcoyle/Code/pymc3/pymc3/tests/test_gp.py":[],"/Users/peadarcoyle/Code/pymc3/pymc3/tests/test_parallel_sampling.py":[],"/Users/peadarcoyle/Code/pymc3/pymc3/tests/test_updates.py":[],"/Users/peadarcoyle/Code/pymc3/pymc3/tests/test_hdf5_backend.py":[],"/Users/peadarcoyle/Code/pymc3/pymc3/tests/test_profile.py":[],"/Users/peadarcoyle/Code/pymc3/pymc3/tests/test_memo.py":[],"/Users/peadarcoyle/Code/pymc3/pymc3/tests/test_util.py":[],"/Users/peadarcoyle/Code/pymc3/pymc3/tests/test_sqlite_backend.py":[],"/Users/peadarcoyle/Code/pymc3/pymc3/tests/test_model_graph.py":[],"/Users/peadarcoyle/Code/pymc3/pymc3/tests/test_models_linear.py":[],"/Users/peadarcoyle/Code/pymc3/pymc3/tests/test_distributions_random.py":[],"/Users/peadarcoyle/Code/pymc3/pymc3/tests/test_modelcontext.py":[],"/Users/peadarcoyle/Code/pymc3/pymc3/tests/test_pickling.py":[],"/Users/peadarcoyle/Code/pymc3/pymc3/tests/test_theanof.py":[],"/Users/peadarcoyle/Code/pymc3/pymc3/tests/test_distributions.py":[],"/Users/peadarcoyle/Code/pymc3/pymc3/tests/test_transforms.py":[],"/Users/peadarcoyle/Code/pymc3/pymc3/tests/test_distribution_defaults.py":[],"/Users/peadarcoyle/Code/pymc3/pymc3/tests/test_sampling.py":[],"/Users/peadarcoyle/Code/pymc3/pymc3/tests/test_dist_math.py":[],"/Users/peadarcoyle/Code/pymc3/pymc3/tests/test_minibatches.py":[],"/Users/peadarcoyle/Code/pymc3/pymc3/tests/test_hmc.py":[],"/Users/peadarcoyle/Code/pymc3/pymc3/tests/test_math.py":[],"/Users/peadarcoyle/Code/pymc3/pymc3/tests/test_posdef_sym.py":[],"/Users/peadarcoyle/Code/pymc3/pymc3/tests/test_types.py":[],"/Users/peadarcoyle/Code/pymc3/pymc3/tests/test_random.py":[],"/Users/peadarcoyle/Code/pymc3/pymc3/step_methods/hmc/trajectory.py":[]}} \ No newline at end of file diff --git a/pymc3/tests/test_sampling.py b/pymc3/tests/test_sampling.py index 09584cbf9d7..13df2917c78 100644 --- a/pymc3/tests/test_sampling.py +++ b/pymc3/tests/test_sampling.py @@ -14,10 +14,9 @@ from .models import simple_init from .helpers import SeededTest from scipy import stats - import pytest - - + + @pytest.mark.xfail(condition=(theano.config.floatX == "float32"), reason="Fails on float32") class TestSample(SeededTest): def setup_method(self): From 78ac4ce0469587d9ad1b8d710d867f2533d4e164 Mon Sep 17 00:00:00 2001 From: springcoil Date: Sat, 27 Oct 2018 16:54:36 +0200 Subject: [PATCH 5/9] Changed chains to cores in one test --- pymc3/tests/test_step.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pymc3/tests/test_step.py b/pymc3/tests/test_step.py index 22ed41b072f..82e6eef668c 100644 --- a/pymc3/tests/test_step.py +++ b/pymc3/tests/test_step.py @@ -438,7 +438,7 @@ def test_bad_init_parallel(self): with Model(): HalfNormal('a', sd=1, testval=-1, transform=None) with pytest.raises(ParallelSamplingError) as error: - sample(init=None, chains=4, random_seed=1) + sample(init=None, cores=4, random_seed=1) error.match('Bad initial') def test_linalg(self, caplog): From 2d6977180e990f39d884123f926bb5094a29bb69 Mon Sep 17 00:00:00 2001 From: springcoil Date: Sat, 27 Oct 2018 16:58:05 +0200 Subject: [PATCH 6/9] Applying black formatting --- pymc3/parallel_sampling.py | 108 +-- pymc3/step_methods/hmc/base_hmc.py | 102 +-- pymc3/tests/test_step.py | 1031 +++++++++++++++++++++------- 3 files changed, 919 insertions(+), 322 deletions(-) diff --git a/pymc3/parallel_sampling.py b/pymc3/parallel_sampling.py index 7cc75eb22ae..ca4c7c928b4 100644 --- a/pymc3/parallel_sampling.py +++ b/pymc3/parallel_sampling.py @@ -12,7 +12,7 @@ from . import theanof -logger = logging.getLogger('pymc3') +logger = logging.getLogger("pymc3") class ParallelSamplingError(Exception): @@ -36,7 +36,7 @@ def __str__(self): class ExceptionWithTraceback: def __init__(self, exc, tb): tb = traceback.format_exception(type(exc), exc, tb) - tb = ''.join(tb) + tb = "".join(tb) self.exc = exc self.tb = '\n"""\n%s"""' % tb @@ -64,8 +64,7 @@ class _Process(multiprocessing.Process): and send finished samples using shared memory. """ - def __init__(self, name, msg_pipe, step_method, shared_point, - draws, tune, seed): + def __init__(self, name, msg_pipe, step_method, shared_point, draws, tune, seed): super(_Process, self).__init__(daemon=True, name=name) self._msg_pipe = msg_pipe self._step_method = step_method @@ -85,7 +84,7 @@ def run(self): pass except BaseException as e: e = ExceptionWithTraceback(e, e.__traceback__) - self._msg_pipe.send(('error', None, e)) + self._msg_pipe.send(("error", None, e)) finally: self._msg_pipe.close() @@ -113,10 +112,10 @@ def _start_loop(self): tuning = True msg = self._recv_msg() - if msg[0] == 'abort': + if msg[0] == "abort": raise KeyboardInterrupt() - if msg[0] != 'start': - raise ValueError('Unexpected msg ' + msg[0]) + if msg[0] != "start": + raise ValueError("Unexpected msg " + msg[0]) while True: if draw < self._draws + self._tune: @@ -125,7 +124,7 @@ def _start_loop(self): except SamplingError as e: warns = self._collect_warnings() e = ExceptionWithTraceback(e, e.__traceback__) - self._msg_pipe.send(('error', warns, e)) + self._msg_pipe.send(("error", warns, e)) else: return @@ -134,9 +133,9 @@ def _start_loop(self): tuning = False msg = self._recv_msg() - if msg[0] == 'abort': + if msg[0] == "abort": raise KeyboardInterrupt() - elif msg[0] == 'write_next': + elif msg[0] == "write_next": self._write_point(point) is_last = draw + 1 == self._draws + self._tune if is_last: @@ -144,10 +143,11 @@ def _start_loop(self): else: warns = None self._msg_pipe.send( - ('writing_done', is_last, draw, tuning, stats, warns)) + ("writing_done", is_last, draw, tuning, stats, warns) + ) draw += 1 else: - raise ValueError('Unknown message ' + msg[0]) + raise ValueError("Unknown message " + msg[0]) def _compute_point(self): if self._step_method.generates_stats: @@ -158,7 +158,7 @@ def _compute_point(self): return point, stats def _collect_warnings(self): - if hasattr(self._step_method, 'warnings'): + if hasattr(self._step_method, "warnings"): return self._step_method.warnings() else: return [] @@ -180,9 +180,9 @@ def __init__(self, draws, tune, step_method, chain, seed, start): size *= int(dim) size *= dtype.itemsize if size != ctypes.c_size_t(size).value: - raise ValueError('Variable %s is too large' % name) + raise ValueError("Variable %s is too large" % name) - array = multiprocessing.sharedctypes.RawArray('c', size) + array = multiprocessing.sharedctypes.RawArray("c", size) self._shared_point[name] = array array_np = np.frombuffer(array, dtype).reshape(shape) array_np[...] = start[name] @@ -192,8 +192,14 @@ def __init__(self, draws, tune, step_method, chain, seed, start): self._num_samples = 0 self._process = _Process( - process_name, remote_conn, step_method, self._shared_point, - draws, tune, seed) + process_name, + remote_conn, + step_method, + self._shared_point, + draws, + tune, + seed, + ) # We fork right away, so that the main process can start tqdm threads self._process.start() @@ -207,14 +213,14 @@ def shared_point_view(self): return self._point def start(self): - self._msg_pipe.send(('start',)) + self._msg_pipe.send(("start",)) def write_next(self): self._readable = False - self._msg_pipe.send(('write_next',)) + self._msg_pipe.send(("write_next",)) def abort(self): - self._msg_pipe.send(('abort',)) + self._msg_pipe.send(("abort",)) def join(self, timeout=None): self._process.join(timeout) @@ -225,29 +231,28 @@ def terminate(self): @staticmethod def recv_draw(processes, timeout=3600): if not processes: - raise ValueError('No processes.') + raise ValueError("No processes.") pipes = [proc._msg_pipe for proc in processes] ready = multiprocessing.connection.wait(pipes) if not ready: - raise multiprocessing.TimeoutError('No message from samplers.') + raise multiprocessing.TimeoutError("No message from samplers.") idxs = {id(proc._msg_pipe): proc for proc in processes} proc = idxs[id(ready[0])] msg = ready[0].recv() - if msg[0] == 'error': + if msg[0] == "error": warns, old_error = msg[1:] if warns is not None: - error = ParallelSamplingError( - str(old_error), proc.chain, warns) + error = ParallelSamplingError(str(old_error), proc.chain, warns) else: - error = RuntimeError('Chain %s failed.' % proc.chain) + error = RuntimeError("Chain %s failed." % proc.chain) six.raise_from(error, old_error) - elif msg[0] == 'writing_done': + elif msg[0] == "writing_done": proc._readable = True proc._num_samples += 1 return (proc,) + msg[1:] else: - raise ValueError('Sampler sent bad message.') + raise ValueError("Sampler sent bad message.") @staticmethod def terminate_all(processes, patience=2): @@ -265,8 +270,10 @@ def terminate_all(processes, patience=2): raise multiprocessing.TimeoutError() process.join(timeout) except multiprocessing.TimeoutError: - logger.warn('Chain processes did not terminate as expected. ' - 'Terminating forcefully...') + logger.warn( + "Chain processes did not terminate as expected. " + "Terminating forcefully..." + ) for process in processes: process.terminate() for process in processes: @@ -274,25 +281,35 @@ def terminate_all(processes, patience=2): Draw = namedtuple( - 'Draw', - ['chain', 'is_last', 'draw_idx', 'tuning', 'stats', 'point', 'warnings'] + "Draw", ["chain", "is_last", "draw_idx", "tuning", "stats", "point", "warnings"] ) class ParallelSampler(object): - def __init__(self, draws, tune, chains, cores, seeds, start_points, - step_method, start_chain_num=0, progressbar=True): + def __init__( + self, + draws, + tune, + chains, + cores, + seeds, + start_points, + step_method, + start_chain_num=0, + progressbar=True, + ): if progressbar: import tqdm + tqdm_ = tqdm.tqdm if any(len(arg) != chains for arg in [seeds, start_points]): - raise ValueError( - 'Number of seeds and start_points must be %s.' % chains) + raise ValueError("Number of seeds and start_points must be %s." % chains) self._samplers = [ - ProcessAdapter(draws, tune, step_method, - chain + start_chain_num, seed, start) + ProcessAdapter( + draws, tune, step_method, chain + start_chain_num, seed, start + ) for chain, seed, start in zip(range(chains), seeds, start_points) ] @@ -307,8 +324,10 @@ def __init__(self, draws, tune, chains, cores, seeds, start_points, self._progress = None if progressbar: self._progress = tqdm_( - total=chains * (draws + tune), unit='draws', - desc='Sampling %s chains' % chains) + total=chains * (draws + tune), + unit="draws", + desc="Sampling %s chains" % chains, + ) def _make_active(self): while self._inactive and len(self._active) < self._max_active: @@ -319,7 +338,7 @@ def _make_active(self): def __iter__(self): if not self._in_context: - raise ValueError('Use ParallelSampler as context manager.') + raise ValueError("Use ParallelSampler as context manager.") self._make_active() while self._active: @@ -338,8 +357,7 @@ def __iter__(self): # and only call proc.write_next() after the yield returns. # This seems to be faster overally though, as the worker # loses less time waiting. - point = {name: val.copy() - for name, val in proc.shared_point_view.items()} + point = {name: val.copy() for name, val in proc.shared_point_view.items()} # Already called for new proc in _make_active if not is_last: @@ -354,4 +372,4 @@ def __enter__(self): def __exit__(self, *args): ProcessAdapter.terminate_all(self._samplers) if self._progress is not None: - self._progress.close() \ No newline at end of file + self._progress.close() diff --git a/pymc3/step_methods/hmc/base_hmc.py b/pymc3/step_methods/hmc/base_hmc.py index a6a94159c1e..fb626ff5276 100644 --- a/pymc3/step_methods/hmc/base_hmc.py +++ b/pymc3/step_methods/hmc/base_hmc.py @@ -12,16 +12,12 @@ from pymc3.backends.report import SamplerWarning, WarningType from pymc3.exceptions import SamplingError -logger = logging.getLogger('pymc3') +logger = logging.getLogger("pymc3") -HMCStepData = namedtuple( - "HMCStepData", - "end, accept_stat, divergence_info, stats") +HMCStepData = namedtuple("HMCStepData", "end, accept_stat, divergence_info, stats") -DivergenceInfo = namedtuple( - 'DivergenceInfo', - 'message, exec_info, state') +DivergenceInfo = namedtuple("DivergenceInfo", "message, exec_info, state") class BaseHMC(arraystep.GradientSharedStep): @@ -29,12 +25,26 @@ class BaseHMC(arraystep.GradientSharedStep): default_blocked = True - def __init__(self, vars=None, scaling=None, step_scale=0.25, is_cov=False, - model=None, blocked=True, potential=None, - integrator="leapfrog", dtype=None, Emax=1000, - target_accept=0.8, gamma=0.05, k=0.75, t0=10, - adapt_step_size=True, step_rand=None, - **theano_kwargs): + def __init__( + self, + vars=None, + scaling=None, + step_scale=0.25, + is_cov=False, + model=None, + blocked=True, + potential=None, + integrator="leapfrog", + dtype=None, + Emax=1000, + target_accept=0.8, + gamma=0.05, + k=0.75, + t0=10, + adapt_step_size=True, + step_rand=None, + **theano_kwargs + ): """Set up Hamiltonian samplers with common structures. Parameters @@ -61,8 +71,9 @@ def __init__(self, vars=None, scaling=None, step_scale=0.25, is_cov=False, vars = self._model.cont_vars vars = inputvars(vars) - super(BaseHMC, self).__init__(vars, blocked=blocked, model=model, - dtype=dtype, **theano_kwargs) + super(BaseHMC, self).__init__( + vars, blocked=blocked, model=model, dtype=dtype, **theano_kwargs + ) self.adapt_step_size = adapt_step_size self.Emax = Emax @@ -72,7 +83,8 @@ def __init__(self, vars=None, scaling=None, step_scale=0.25, is_cov=False, self.step_size = step_scale / (size ** 0.25) self.target_accept = target_accept self.step_adapt = step_sizes.DualAverageAdaptation( - self.step_size, target_accept, gamma, k, t0) + self.step_size, target_accept, gamma, k, t0 + ) self.tune = True @@ -94,7 +106,8 @@ def __init__(self, vars=None, scaling=None, step_scale=0.25, is_cov=False, self.potential = quad_potential(scaling, is_cov) self.integrator = integration.CpuLeapfrogIntegrator( - self.potential, self._logp_dlogp_func) + self.potential, self._logp_dlogp_func + ) self._step_rand = step_rand self._warnings = [] @@ -116,19 +129,24 @@ def astep(self, q0): if not np.isfinite(start.energy): model = self._model check_test_point = model.check_test_point() - error_logp = (check_test_point - .loc[(np.abs(check_test_point) >= 1e20) - | np.isnan(check_test_point)]) + error_logp = check_test_point.loc[ + (np.abs(check_test_point) >= 1e20) | np.isnan(check_test_point) + ] self.potential.raise_ok(self._logp_dlogp_func._ordering.vmap) message_energy = ( "Bad initial energy, check any log probabilities that " - "are inf or -inf, nan or very small:\n{}" - .format(error_logp.to_string())) + "are inf or -inf, nan or very small:\n{}".format(error_logp.to_string()) + ) warning = SamplerWarning( - WarningType.BAD_ENERGY, message_energy, 'critical', - self.iter_count, None, None) + WarningType.BAD_ENERGY, + message_energy, + "critical", + self.iter_count, + None, + None, + ) self._warnings.append(warning) - raise SamplingError('Bad initial energy') + raise SamplingError("Bad initial energy") adapt_step = self.tune and self.adapt_step_size step_size = self.step_adapt.current(adapt_step) @@ -155,8 +173,8 @@ def astep(self, q0): else: point = None warning = SamplerWarning( - kind, info.message, 'debug', self.iter_count, - info.exec_info, point) + kind, info.message, "debug", self.iter_count, info.exec_info, point + ) self._warnings.append(warning) @@ -164,10 +182,7 @@ def astep(self, q0): if not self.tune: self._samples_after_tune += 1 - stats = { - 'tune': self.tune, - 'diverging': bool(hmc_step.divergence_info), - } + stats = {"tune": self.tune, "diverging": bool(hmc_step.divergence_info)} stats.update(hmc_step.stats) stats.update(self.step_adapt.stats()) @@ -183,22 +198,29 @@ def warnings(self): warnings = self._warnings[:] # Generate a global warning for divergences - message = '' + message = "" n_divs = self._num_divs_sample if n_divs and self._samples_after_tune == n_divs: - message = ('The chain contains only diverging samples. The model ' - 'is probably misspecified.') + message = ( + "The chain contains only diverging samples. The model " + "is probably misspecified." + ) elif n_divs == 1: - message = ('There was 1 divergence after tuning. Increase ' - '`target_accept` or reparameterize.') + message = ( + "There was 1 divergence after tuning. Increase " + "`target_accept` or reparameterize." + ) elif n_divs > 1: - message = ('There were %s divergences after tuning. Increase ' - '`target_accept` or reparameterize.' % n_divs) + message = ( + "There were %s divergences after tuning. Increase " + "`target_accept` or reparameterize." % n_divs + ) if message: warning = SamplerWarning( - WarningType.DIVERGENCES, message, 'error', None, None, None) + WarningType.DIVERGENCES, message, "error", None, None, None + ) warnings.append(warning) warnings.extend(self.step_adapt.warnings()) - return warnings \ No newline at end of file + return warnings diff --git a/pymc3/tests/test_step.py b/pymc3/tests/test_step.py index 82e6eef668c..8c87fd87b69 100644 --- a/pymc3/tests/test_step.py +++ b/pymc3/tests/test_step.py @@ -2,19 +2,40 @@ import tempfile from .checks import close_to -from .models import (simple_categorical, mv_simple, mv_simple_discrete, - mv_prior_simple, simple_2model_continuous) +from .models import ( + simple_categorical, + mv_simple, + mv_simple_discrete, + mv_prior_simple, + simple_2model_continuous, +) from pymc3.sampling import assign_step_methods, sample from pymc3.parallel_sampling import ParallelSamplingError from pymc3.exceptions import SamplingError from pymc3.model import Model -from pymc3.step_methods import (NUTS, BinaryGibbsMetropolis, CategoricalGibbsMetropolis, - Metropolis, Slice, CompoundStep, NormalProposal, - MultivariateNormalProposal, HamiltonianMC, - EllipticalSlice, SMC, DEMetropolis) +from pymc3.step_methods import ( + NUTS, + BinaryGibbsMetropolis, + CategoricalGibbsMetropolis, + Metropolis, + Slice, + CompoundStep, + NormalProposal, + MultivariateNormalProposal, + HamiltonianMC, + EllipticalSlice, + SMC, + DEMetropolis, +) from pymc3.theanof import floatX from pymc3.distributions import ( - Binomial, Normal, Bernoulli, Categorical, Beta, HalfNormal) + Binomial, + Normal, + Bernoulli, + Categorical, + Beta, + HalfNormal, +) from numpy.testing import assert_array_almost_equal import numpy as np @@ -27,136 +48,626 @@ class TestStepMethods(object): # yield test doesn't work subclassing object master_samples = { - Slice: np.array([ 0.10233528, 0.40458486, 0.17329217, 0.46281232, 0.22556278, - 1.52632836, -0.27823807, 0.02539625, 1.02711735, 0.03686346, - -0.62841281, -0.27125083, 0.31989505, 0.84031155, -0.18949138, - 1.60550262, 1.01375291, -0.29742941, 0.35312738, 0.43363622, - 1.18898078, 0.80063888, 0.38445644, 0.90184395, 1.69150017, - 2.05452171, -0.13334755, 1.61265408, 1.36579345, 1.3216292 , - -0.59487037, -0.34648927, 1.05107285, 0.42870305, 0.61552257, - 0.55239884, 0.13929271, 0.26213809, -0.2316028 , 0.19711046, - 1.42832629, 1.93641434, -0.81142379, -0.31059485, -0.3189694 , - 1.43542534, 0.40311093, 1.63103768, 0.24034874, 0.33924866, - 0.94951616, 0.71700185, 0.79273056, -0.44569146, 1.91974783, - 0.84673795, 1.12411833, -0.83123811, -0.54310095, -0.00721347, - 0.9925055 , 1.04015058, -0.34958074, -0.14926302, -0.47990225, - -0.75629446, -0.95942067, 1.68179204, 1.20598073, 1.39675733, - 1.22755935, 0.06728757, 1.05184231, 1.01126791, -0.67327093, - 0.21429651, 1.33730461, -1.56174184, -0.64348764, 0.98050636, - 0.25923049, 0.58622631, 0.46589069, 1.44367347, -0.43141573, - 1.08293374, -0.5563204 , 1.46287904, 1.26019815, 0.52972104, - 1.08792687, 1.10064358, 1.84881549, 0.91179647, 0.69316592, - -0.47657064, 2.22747063, 0.83388935, 0.84680716, -0.10556406]), - HamiltonianMC: np.array([ 0.43733634, 0.43733634, 0.15955614, -0.44355329, 0.21465731, - 0.30148244, 0.45527282, 0.45527282, 0.41753005, -0.03480236, - 1.16599611, 0.565306 , 0.565306 , 0.0077143 , -0.18291321, - -0.14577946, -0.00703353, -0.00703353, 0.14345194, -0.12345058, - 0.76875516, 0.76875516, 0.84289506, 0.24596225, 0.95287087, - 1.3799335 , 1.1493899 , 1.1493899 , 2.0255982 , -0.77850273, - 0.11604115, 0.11604115, 0.39296557, 0.34826491, 0.5951183 , - 0.63097341, 0.57938784, 0.57938784, 0.76570029, 0.63516046, - 0.23667784, 2.0151377 , 1.92064966, 1.09125654, -0.43716787, - 0.61939595, 0.30566853, 0.30566853, 0.3690641 , 0.3690641 , - 0.3690641 , 1.26497542, 0.90890334, 0.01482818, 0.01482818, - -0.15542473, 0.26475651, 0.32687263, 1.21902207, 0.6708017 , - -0.18867695, -0.18867695, -0.07141329, -0.04631175, -0.16855462, - -0.16855462, 1.05455573, 0.47371825, 0.47371825, 0.86307077, - 0.86307077, 0.51484125, 1.0022533 , 1.0022533 , 1.02370316, - 0.71331829, 0.71331829, 0.71331829, 0.40758664, 0.81307434, - -0.46269741, -0.60284666, 0.06710527, 0.06710527, -0.35055053, - 0.36727629, 0.36727629, 0.69350367, 0.11268647, 0.37681301, - 1.10168386, 0.49559472, 0.49559472, 0.06193658, -0.07947103, - 0.01969434, 1.28470893, -0.13536813, -0.13536813, 0.6575966 ]), - Metropolis: np.array([ 1.62434536, 1.01258895, 0.4844172 , 0.4844172 , 0.4844172 , - 0.4844172 , 0.4844172 , 0.4844172 , 0.4844172 , 0.4844172 , - 0.31198899, 0.31198899, 0.31198899, 0.31198899, 1.21284494, - 0.52911708, 0.261229 , 0.79158447, 0.10441177, -0.74079387, - -0.74079387, -0.50637818, -0.50637818, -0.50637818, -0.45557042, - -0.45557042, -0.33541147, 0.28179164, 0.58196196, 0.22971211, - 0.02081788, 0.60744107, 0.8930284 , 0.8930284 , 1.40595822, - 1.10786538, 1.10786538, 1.10786538, 1.10786538, -0.28863095, - -0.12859388, 0.74757504, 0.74757504, 0.74757504, 0.97766977, - 0.97766977, 0.75534163, 0.55458356, 0.75288328, 0.87189193, - 0.9937132 , 0.9937132 , 0.61842825, 0.61842825, 0.27457457, - 0.31817143, 0.31817143, 0.31817143, -0.77674042, -0.60735798, - 0.13319847, -0.82050213, -0.82050213, -0.50534274, -0.15479676, - -0.15479676, -0.19349227, -0.19349227, -0.21810923, -0.21810923, - -0.21810923, 1.0180548 , -0.18121323, 0.68213209, 0.68213209, - 1.23266958, 1.23266958, 0.60913885, 1.41099989, 1.45756718, - 1.45756718, 1.45756718, 1.45756718, 1.59526839, 1.82776295, - 1.82776295, 1.82776295, 1.82776295, 2.2691274 , 2.16897216, - 2.18638157, 1.06436284, 0.54726838, 0.54726838, 1.04247971, - 0.86777655, 0.86777655, 0.86777655, 0.86777655, 0.61914177]), - NUTS: np.array([ 0.550575 , 0.550575 , 0.80046332, 0.91590059, 1.34621916, - 1.34621916, -0.63917773, -0.65770809, -0.65770809, -0.64512868, - -1.05448153, -0.5225666 , 0.14335153, -0.0034499 , -0.0034499 , - 0.05309212, -0.53186371, 0.29325825, 0.43210854, 0.56284837, - 0.56284837, 0.38041767, 0.47322034, 0.49937368, 0.49937368, - 0.44424258, 0.44424258, -0.02790848, -0.40470145, -0.35725567, - -0.43744228, 0.41955432, 0.31099421, 0.31099421, 0.65811717, - 0.66649398, 0.38493786, 0.54114658, 0.54114658, 0.68222408, - 0.66404942, 1.44143108, 1.15638799, -0.06775775, -0.06775775, - 0.30418561, 0.23543403, 0.57934404, -0.5435111 , -0.47938915, - -0.23816662, 0.36793792, 0.36793792, 0.64980016, 0.52150456, - 0.64643321, 0.26130179, 1.10569077, 1.10569077, 1.23662797, - -0.36928735, -0.14303069, 0.85298904, 0.85298904, 0.31422085, - 0.32113762, 0.32113762, 1.0692238 , 1.0692238 , 1.60127576, - 1.49249738, 1.09065107, 0.84264371, 0.84264371, -0.08832343, - 0.04868027, -0.02679449, -0.02679449, 0.91989101, 0.65754478, - -0.39220625, 0.08379492, 1.03055634, 1.03055634, 1.71071332, - 1.58740483, 1.67905741, 0.77744868, 0.15050587, 0.15050587, - 0.73979127, 0.15445515, 0.13134717, 0.85068974, 0.85068974, - 0.6974799 , 0.16170472, 0.86405959, 0.86405959, -0.22032854]), - SMC: np.array([ 5.10950205e-02, 1.09811720e+00, 1.78330202e-01, 6.85938766e-01, - 1.42354476e-01, -1.59630758e+00, 1.57176810e+00, -4.01398917e-01, - 1.14567871e+00, 1.14954938e+00, 4.94399840e-01, 1.16253017e+00, - 1.17432244e+00, 7.79195162e-01, 1.29017945e+00, 2.53722905e-01, - 5.38589898e-01, 3.52121216e-01, 1.35795966e+00, 1.02086933e-01, - 1.58845251e+00, 6.76852927e-01, -1.04716592e-02, -1.01613324e-01, - 1.37680965e+00, 7.40036542e-01, 2.89069320e-01, 1.48153741e+00, - 9.58156958e-01, 5.73623782e-02, 7.68850721e-01, 3.68643390e-01, - 1.47645964e+00, 2.32596780e-01, -1.85008158e-01, 3.71335958e-01, - 2.68600102e+00, -4.89504443e-01, 6.54265561e-02, 3.80455349e-01, - 1.17875338e+00, 2.30233324e-01, 6.90960231e-01, 8.81668685e-01, - -2.19754340e-01, 1.27686862e-01, 3.28444250e-01, 1.34820635e-01, - 5.29725257e-01, 1.43783915e+00, -1.64754264e-01, 7.41446719e-01, - -1.17733186e+00, 6.01215658e-02, 1.82638158e-01, -2.23232214e-02, - -1.79877583e-02, 8.37949150e-01, 4.41964955e-01, -8.66524743e-01, - 4.90738093e-01, 2.42056488e-01, 4.67699626e-01, 2.91075351e-01, - 1.49541153e+00, 8.30730845e-01, 1.03956404e+00, -5.16162910e-01, - 2.84338859e-01, 1.72305888e+00, 9.52445566e-01, 1.48831718e+00, - 8.03455325e-01, 1.48840970e+00, 6.98122664e-01, 3.30187139e-01, - 7.88029712e-01, 9.31510828e-01, 1.01326878e+00, 2.26637755e-01, - 1.70703646e-01, -8.54429841e-01, 2.97254590e-01, -2.77843274e-01, - -2.25544207e-01, 1.98862826e-02, 5.05953885e-01, 4.98203941e-01, - 1.20897382e+00, -6.32958669e-05, -7.22425896e-01, 1.60930869e+00, - -5.02773645e-01, 2.46405678e+00, 9.16039706e-01, 1.14146060e+00, - -1.95781984e-01, -2.44653942e-01, 2.67851290e-01, 2.37462012e-01, - 6.71471950e-01, 1.18319765e+00, 1.29146530e+00, -3.14177753e-01, - -1.31041215e-02, 1.05029405e+00, 1.31202399e+00, 7.40532839e-02, - 9.15510041e-01, 7.71054604e-01, 9.83483263e-01, 9.03032142e-01, - 9.14191160e-01, 9.32285366e-01, 1.13937607e+00, -4.29155928e-01, - 3.44609229e-02, -5.46423555e-02, 1.34625982e+00, -1.28287047e-01, - -1.55214879e-02, 3.25294234e-01, 1.06120585e+00, -5.09891282e-01, - 1.25789335e+00, 1.01808348e+00, -9.92590713e-01, 1.72832932e+00, - 1.12232980e+00, 8.54801892e-01, 1.41534752e+00, 3.50798405e-01, - 3.69381623e-01, 1.48608411e+00, -1.15506310e-02, 1.57066360e+00, - 2.00747378e-01, 4.47219763e-01, 5.57720524e-01, -7.74295353e-02, - 1.79192501e+00, 7.66510475e-01, 1.38852488e+00, -4.06055122e-01, - 2.73203156e-01, 3.61014687e-01, 1.23574043e+00, 1.64565746e-01, - -9.89896480e-02, 9.26130265e-02, 1.06440134e+00, -1.55890408e-01, - 4.47131846e-01, -7.59186008e-01, -1.50881256e+00, -2.13928005e-01, - -4.19160151e-01, 1.75815544e+00, 7.45423008e-01, 6.94781506e-01, - 1.58596346e+00, 1.75508724e+00, 4.56070434e-01, 2.94128709e-02, - 1.17703970e+00, -9.90230827e-02, 8.42796845e-01, 1.79154944e+00, - 5.92779197e-01, 2.73562285e-01, 1.61597907e+00, 1.23514403e+00, - 4.86261080e-01, -3.10434934e-01, 5.57873722e-01, 6.50365217e-01, - -3.41009850e-01, 9.26851109e-01, 8.28936486e-01, 9.16180689e-02, - 1.30226405e+00, 3.73945789e-01, 6.04560122e-02, 6.00698708e-01, - 9.68764731e-02, 1.41904148e+00, 6.94182961e-03, 3.17504138e-01, - 5.90956041e-01, -5.78113887e-01, 5.26615565e-01, -4.19715252e-01, - 8.92891364e-01, 1.30207363e-01, 4.19899637e-01, 7.10275704e-01, - 9.27418179e-02, 1.85758044e+00, 4.76988907e-01, -1.36341398e-01]), + Slice: np.array( + [ + 0.10233528, + 0.40458486, + 0.17329217, + 0.46281232, + 0.22556278, + 1.52632836, + -0.27823807, + 0.02539625, + 1.02711735, + 0.03686346, + -0.62841281, + -0.27125083, + 0.31989505, + 0.84031155, + -0.18949138, + 1.60550262, + 1.01375291, + -0.29742941, + 0.35312738, + 0.43363622, + 1.18898078, + 0.80063888, + 0.38445644, + 0.90184395, + 1.69150017, + 2.05452171, + -0.13334755, + 1.61265408, + 1.36579345, + 1.3216292, + -0.59487037, + -0.34648927, + 1.05107285, + 0.42870305, + 0.61552257, + 0.55239884, + 0.13929271, + 0.26213809, + -0.2316028, + 0.19711046, + 1.42832629, + 1.93641434, + -0.81142379, + -0.31059485, + -0.3189694, + 1.43542534, + 0.40311093, + 1.63103768, + 0.24034874, + 0.33924866, + 0.94951616, + 0.71700185, + 0.79273056, + -0.44569146, + 1.91974783, + 0.84673795, + 1.12411833, + -0.83123811, + -0.54310095, + -0.00721347, + 0.9925055, + 1.04015058, + -0.34958074, + -0.14926302, + -0.47990225, + -0.75629446, + -0.95942067, + 1.68179204, + 1.20598073, + 1.39675733, + 1.22755935, + 0.06728757, + 1.05184231, + 1.01126791, + -0.67327093, + 0.21429651, + 1.33730461, + -1.56174184, + -0.64348764, + 0.98050636, + 0.25923049, + 0.58622631, + 0.46589069, + 1.44367347, + -0.43141573, + 1.08293374, + -0.5563204, + 1.46287904, + 1.26019815, + 0.52972104, + 1.08792687, + 1.10064358, + 1.84881549, + 0.91179647, + 0.69316592, + -0.47657064, + 2.22747063, + 0.83388935, + 0.84680716, + -0.10556406, + ] + ), + HamiltonianMC: np.array( + [ + 0.43733634, + 0.43733634, + 0.15955614, + -0.44355329, + 0.21465731, + 0.30148244, + 0.45527282, + 0.45527282, + 0.41753005, + -0.03480236, + 1.16599611, + 0.565306, + 0.565306, + 0.0077143, + -0.18291321, + -0.14577946, + -0.00703353, + -0.00703353, + 0.14345194, + -0.12345058, + 0.76875516, + 0.76875516, + 0.84289506, + 0.24596225, + 0.95287087, + 1.3799335, + 1.1493899, + 1.1493899, + 2.0255982, + -0.77850273, + 0.11604115, + 0.11604115, + 0.39296557, + 0.34826491, + 0.5951183, + 0.63097341, + 0.57938784, + 0.57938784, + 0.76570029, + 0.63516046, + 0.23667784, + 2.0151377, + 1.92064966, + 1.09125654, + -0.43716787, + 0.61939595, + 0.30566853, + 0.30566853, + 0.3690641, + 0.3690641, + 0.3690641, + 1.26497542, + 0.90890334, + 0.01482818, + 0.01482818, + -0.15542473, + 0.26475651, + 0.32687263, + 1.21902207, + 0.6708017, + -0.18867695, + -0.18867695, + -0.07141329, + -0.04631175, + -0.16855462, + -0.16855462, + 1.05455573, + 0.47371825, + 0.47371825, + 0.86307077, + 0.86307077, + 0.51484125, + 1.0022533, + 1.0022533, + 1.02370316, + 0.71331829, + 0.71331829, + 0.71331829, + 0.40758664, + 0.81307434, + -0.46269741, + -0.60284666, + 0.06710527, + 0.06710527, + -0.35055053, + 0.36727629, + 0.36727629, + 0.69350367, + 0.11268647, + 0.37681301, + 1.10168386, + 0.49559472, + 0.49559472, + 0.06193658, + -0.07947103, + 0.01969434, + 1.28470893, + -0.13536813, + -0.13536813, + 0.6575966, + ] + ), + Metropolis: np.array( + [ + 1.62434536, + 1.01258895, + 0.4844172, + 0.4844172, + 0.4844172, + 0.4844172, + 0.4844172, + 0.4844172, + 0.4844172, + 0.4844172, + 0.31198899, + 0.31198899, + 0.31198899, + 0.31198899, + 1.21284494, + 0.52911708, + 0.261229, + 0.79158447, + 0.10441177, + -0.74079387, + -0.74079387, + -0.50637818, + -0.50637818, + -0.50637818, + -0.45557042, + -0.45557042, + -0.33541147, + 0.28179164, + 0.58196196, + 0.22971211, + 0.02081788, + 0.60744107, + 0.8930284, + 0.8930284, + 1.40595822, + 1.10786538, + 1.10786538, + 1.10786538, + 1.10786538, + -0.28863095, + -0.12859388, + 0.74757504, + 0.74757504, + 0.74757504, + 0.97766977, + 0.97766977, + 0.75534163, + 0.55458356, + 0.75288328, + 0.87189193, + 0.9937132, + 0.9937132, + 0.61842825, + 0.61842825, + 0.27457457, + 0.31817143, + 0.31817143, + 0.31817143, + -0.77674042, + -0.60735798, + 0.13319847, + -0.82050213, + -0.82050213, + -0.50534274, + -0.15479676, + -0.15479676, + -0.19349227, + -0.19349227, + -0.21810923, + -0.21810923, + -0.21810923, + 1.0180548, + -0.18121323, + 0.68213209, + 0.68213209, + 1.23266958, + 1.23266958, + 0.60913885, + 1.41099989, + 1.45756718, + 1.45756718, + 1.45756718, + 1.45756718, + 1.59526839, + 1.82776295, + 1.82776295, + 1.82776295, + 1.82776295, + 2.2691274, + 2.16897216, + 2.18638157, + 1.06436284, + 0.54726838, + 0.54726838, + 1.04247971, + 0.86777655, + 0.86777655, + 0.86777655, + 0.86777655, + 0.61914177, + ] + ), + NUTS: np.array( + [ + 0.550575, + 0.550575, + 0.80046332, + 0.91590059, + 1.34621916, + 1.34621916, + -0.63917773, + -0.65770809, + -0.65770809, + -0.64512868, + -1.05448153, + -0.5225666, + 0.14335153, + -0.0034499, + -0.0034499, + 0.05309212, + -0.53186371, + 0.29325825, + 0.43210854, + 0.56284837, + 0.56284837, + 0.38041767, + 0.47322034, + 0.49937368, + 0.49937368, + 0.44424258, + 0.44424258, + -0.02790848, + -0.40470145, + -0.35725567, + -0.43744228, + 0.41955432, + 0.31099421, + 0.31099421, + 0.65811717, + 0.66649398, + 0.38493786, + 0.54114658, + 0.54114658, + 0.68222408, + 0.66404942, + 1.44143108, + 1.15638799, + -0.06775775, + -0.06775775, + 0.30418561, + 0.23543403, + 0.57934404, + -0.5435111, + -0.47938915, + -0.23816662, + 0.36793792, + 0.36793792, + 0.64980016, + 0.52150456, + 0.64643321, + 0.26130179, + 1.10569077, + 1.10569077, + 1.23662797, + -0.36928735, + -0.14303069, + 0.85298904, + 0.85298904, + 0.31422085, + 0.32113762, + 0.32113762, + 1.0692238, + 1.0692238, + 1.60127576, + 1.49249738, + 1.09065107, + 0.84264371, + 0.84264371, + -0.08832343, + 0.04868027, + -0.02679449, + -0.02679449, + 0.91989101, + 0.65754478, + -0.39220625, + 0.08379492, + 1.03055634, + 1.03055634, + 1.71071332, + 1.58740483, + 1.67905741, + 0.77744868, + 0.15050587, + 0.15050587, + 0.73979127, + 0.15445515, + 0.13134717, + 0.85068974, + 0.85068974, + 0.6974799, + 0.16170472, + 0.86405959, + 0.86405959, + -0.22032854, + ] + ), + SMC: np.array( + [ + 5.10950205e-02, + 1.09811720e00, + 1.78330202e-01, + 6.85938766e-01, + 1.42354476e-01, + -1.59630758e00, + 1.57176810e00, + -4.01398917e-01, + 1.14567871e00, + 1.14954938e00, + 4.94399840e-01, + 1.16253017e00, + 1.17432244e00, + 7.79195162e-01, + 1.29017945e00, + 2.53722905e-01, + 5.38589898e-01, + 3.52121216e-01, + 1.35795966e00, + 1.02086933e-01, + 1.58845251e00, + 6.76852927e-01, + -1.04716592e-02, + -1.01613324e-01, + 1.37680965e00, + 7.40036542e-01, + 2.89069320e-01, + 1.48153741e00, + 9.58156958e-01, + 5.73623782e-02, + 7.68850721e-01, + 3.68643390e-01, + 1.47645964e00, + 2.32596780e-01, + -1.85008158e-01, + 3.71335958e-01, + 2.68600102e00, + -4.89504443e-01, + 6.54265561e-02, + 3.80455349e-01, + 1.17875338e00, + 2.30233324e-01, + 6.90960231e-01, + 8.81668685e-01, + -2.19754340e-01, + 1.27686862e-01, + 3.28444250e-01, + 1.34820635e-01, + 5.29725257e-01, + 1.43783915e00, + -1.64754264e-01, + 7.41446719e-01, + -1.17733186e00, + 6.01215658e-02, + 1.82638158e-01, + -2.23232214e-02, + -1.79877583e-02, + 8.37949150e-01, + 4.41964955e-01, + -8.66524743e-01, + 4.90738093e-01, + 2.42056488e-01, + 4.67699626e-01, + 2.91075351e-01, + 1.49541153e00, + 8.30730845e-01, + 1.03956404e00, + -5.16162910e-01, + 2.84338859e-01, + 1.72305888e00, + 9.52445566e-01, + 1.48831718e00, + 8.03455325e-01, + 1.48840970e00, + 6.98122664e-01, + 3.30187139e-01, + 7.88029712e-01, + 9.31510828e-01, + 1.01326878e00, + 2.26637755e-01, + 1.70703646e-01, + -8.54429841e-01, + 2.97254590e-01, + -2.77843274e-01, + -2.25544207e-01, + 1.98862826e-02, + 5.05953885e-01, + 4.98203941e-01, + 1.20897382e00, + -6.32958669e-05, + -7.22425896e-01, + 1.60930869e00, + -5.02773645e-01, + 2.46405678e00, + 9.16039706e-01, + 1.14146060e00, + -1.95781984e-01, + -2.44653942e-01, + 2.67851290e-01, + 2.37462012e-01, + 6.71471950e-01, + 1.18319765e00, + 1.29146530e00, + -3.14177753e-01, + -1.31041215e-02, + 1.05029405e00, + 1.31202399e00, + 7.40532839e-02, + 9.15510041e-01, + 7.71054604e-01, + 9.83483263e-01, + 9.03032142e-01, + 9.14191160e-01, + 9.32285366e-01, + 1.13937607e00, + -4.29155928e-01, + 3.44609229e-02, + -5.46423555e-02, + 1.34625982e00, + -1.28287047e-01, + -1.55214879e-02, + 3.25294234e-01, + 1.06120585e00, + -5.09891282e-01, + 1.25789335e00, + 1.01808348e00, + -9.92590713e-01, + 1.72832932e00, + 1.12232980e00, + 8.54801892e-01, + 1.41534752e00, + 3.50798405e-01, + 3.69381623e-01, + 1.48608411e00, + -1.15506310e-02, + 1.57066360e00, + 2.00747378e-01, + 4.47219763e-01, + 5.57720524e-01, + -7.74295353e-02, + 1.79192501e00, + 7.66510475e-01, + 1.38852488e00, + -4.06055122e-01, + 2.73203156e-01, + 3.61014687e-01, + 1.23574043e00, + 1.64565746e-01, + -9.89896480e-02, + 9.26130265e-02, + 1.06440134e00, + -1.55890408e-01, + 4.47131846e-01, + -7.59186008e-01, + -1.50881256e00, + -2.13928005e-01, + -4.19160151e-01, + 1.75815544e00, + 7.45423008e-01, + 6.94781506e-01, + 1.58596346e00, + 1.75508724e00, + 4.56070434e-01, + 2.94128709e-02, + 1.17703970e00, + -9.90230827e-02, + 8.42796845e-01, + 1.79154944e00, + 5.92779197e-01, + 2.73562285e-01, + 1.61597907e00, + 1.23514403e00, + 4.86261080e-01, + -3.10434934e-01, + 5.57873722e-01, + 6.50365217e-01, + -3.41009850e-01, + 9.26851109e-01, + 8.28936486e-01, + 9.16180689e-02, + 1.30226405e00, + 3.73945789e-01, + 6.04560122e-02, + 6.00698708e-01, + 9.68764731e-02, + 1.41904148e00, + 6.94182961e-03, + 3.17504138e-01, + 5.90956041e-01, + -5.78113887e-01, + 5.26615565e-01, + -4.19715252e-01, + 8.92891364e-01, + 1.30207363e-01, + 4.19899637e-01, + 7.10275704e-01, + 9.27418179e-02, + 1.85758044e00, + 4.76988907e-01, + -1.36341398e-01, + ] + ), } def setup_class(self): @@ -165,7 +676,9 @@ def setup_class(self): def teardown_class(self): shutil.rmtree(self.temp_dir) - @pytest.mark.xfail(condition=(theano.config.floatX == "float32"), reason="Fails on float32") + @pytest.mark.xfail( + condition=(theano.config.floatX == "float32"), reason="Fails on float32" + ) def test_sample_exact(self): for step_method in self.master_samples: self.check_trace(step_method) @@ -188,27 +701,37 @@ def check_trace(self, step_method): """ n_steps = 100 with Model() as model: - x = Normal('x', mu=0, sd=1) - y = Normal('y', mu=x, sd=1, observed=1) - if step_method.__name__ == 'SMC': - trace = sample(draws=200, - random_seed=1, - progressbar=False, - step=step_method()) - elif step_method.__name__ == 'NUTS': + x = Normal("x", mu=0, sd=1) + y = Normal("y", mu=x, sd=1, observed=1) + if step_method.__name__ == "SMC": + trace = sample( + draws=200, random_seed=1, progressbar=False, step=step_method() + ) + elif step_method.__name__ == "NUTS": step = step_method(scaling=model.test_point) - trace = sample(0, tune=n_steps, - discard_tuned_samples=False, - step=step, random_seed=1, chains=1) + trace = sample( + 0, + tune=n_steps, + discard_tuned_samples=False, + step=step, + random_seed=1, + chains=1, + ) else: - trace = sample(0, tune=n_steps, - discard_tuned_samples=False, - step=step_method(), random_seed=1, chains=1) + trace = sample( + 0, + tune=n_steps, + discard_tuned_samples=False, + step=step_method(), + random_seed=1, + chains=1, + ) assert_array_almost_equal( - trace['x'], + trace["x"], self.master_samples[step_method], - decimal=select_by_precision(float64=6, float32=4)) + decimal=select_by_precision(float64=6, float32=4), + ) def check_stat(self, check, trace, name): for (var, stat, value, bound) in check: @@ -217,9 +740,8 @@ def check_stat(self, check, trace, name): def test_step_continuous(self): start, model, (mu, C) = mv_simple() - unc = np.diag(C) ** .5 - check = (('x', np.mean, mu, unc / 10.), - ('x', np.std, unc, unc / 10.)) + unc = np.diag(C) ** 0.5 + check = (("x", np.mean, mu, unc / 10.0), ("x", np.std, unc, unc / 10.0)) with model: steps = ( Slice(), @@ -229,59 +751,77 @@ def test_step_continuous(self): Slice(blocked=True), HamiltonianMC(scaling=C, is_cov=True), NUTS(scaling=C, is_cov=True), - CompoundStep([ - HamiltonianMC(scaling=C, is_cov=True), - HamiltonianMC(scaling=C, is_cov=True, blocked=False)]), + CompoundStep( + [ + HamiltonianMC(scaling=C, is_cov=True), + HamiltonianMC(scaling=C, is_cov=True, blocked=False), + ] + ), ) for step in steps: - trace = sample(0, tune=8000, chains=1, - discard_tuned_samples=False, step=step, - start=start, model=model, random_seed=1) + trace = sample( + 0, + tune=8000, + chains=1, + discard_tuned_samples=False, + step=step, + start=start, + model=model, + random_seed=1, + ) self.check_stat(check, trace, step.__class__.__name__) def test_step_discrete(self): if theano.config.floatX == "float32": return # Cannot use @skip because it only skips one iteration of the yield start, model, (mu, C) = mv_simple_discrete() - unc = np.diag(C) ** .5 - check = (('x', np.mean, mu, unc / 10.), - ('x', np.std, unc, unc / 10.)) + unc = np.diag(C) ** 0.5 + check = (("x", np.mean, mu, unc / 10.0), ("x", np.std, unc, unc / 10.0)) with model: - steps = ( - Metropolis(S=C, proposal_dist=MultivariateNormalProposal), - ) + steps = (Metropolis(S=C, proposal_dist=MultivariateNormalProposal),) for step in steps: - trace = sample(20000, tune=0, step=step, start=start, model=model, - random_seed=1, chains=1) + trace = sample( + 20000, + tune=0, + step=step, + start=start, + model=model, + random_seed=1, + chains=1, + ) self.check_stat(check, trace, step.__class__.__name__) def test_step_categorical(self): start, model, (mu, C) = simple_categorical() - unc = C ** .5 - check = (('x', np.mean, mu, unc / 10.), - ('x', np.std, unc, unc / 10.)) + unc = C ** 0.5 + check = (("x", np.mean, mu, unc / 10.0), ("x", np.std, unc, unc / 10.0)) with model: steps = ( - CategoricalGibbsMetropolis(model.x, proposal='uniform'), - CategoricalGibbsMetropolis(model.x, proposal='proportional'), + CategoricalGibbsMetropolis(model.x, proposal="uniform"), + CategoricalGibbsMetropolis(model.x, proposal="proportional"), ) for step in steps: - trace = sample(8000, tune=0, step=step, start=start, model=model, random_seed=1) + trace = sample( + 8000, tune=0, step=step, start=start, model=model, random_seed=1 + ) self.check_stat(check, trace, step.__class__.__name__) def test_step_elliptical_slice(self): start, model, (K, L, mu, std, noise) = mv_prior_simple() unc = noise ** 0.5 - check = (('x', np.mean, mu, unc / 10.), - ('x', np.std, std, unc / 10.)) + check = (("x", np.mean, mu, unc / 10.0), ("x", np.std, std, unc / 10.0)) with model: - steps = ( - EllipticalSlice(prior_cov=K), - EllipticalSlice(prior_chol=L), - ) + steps = (EllipticalSlice(prior_cov=K), EllipticalSlice(prior_chol=L)) for step in steps: - trace = sample(5000, tune=0, step=step, start=start, model=model, - random_seed=1, chains=1) + trace = sample( + 5000, + tune=0, + step=step, + start=start, + model=model, + random_seed=1, + chains=1, + ) self.check_stat(check, trace, step.__class__.__name__) @@ -311,8 +851,10 @@ def test_mv_proposal(self): class TestCompoundStep(object): samplers = (Metropolis, Slice, HamiltonianMC, NUTS, DEMetropolis) - @pytest.mark.skipif(theano.config.floatX == "float32", - reason="Test fails on 32 bit due to linalg issues") + @pytest.mark.skipif( + theano.config.floatX == "float32", + reason="Test fails on 32 bit due to linalg issues", + ) def test_non_blocked(self): """Test that samplers correctly create non-blocked compound steps.""" _, model = simple_2model_continuous() @@ -320,8 +862,10 @@ def test_non_blocked(self): for sampler in self.samplers: assert isinstance(sampler(blocked=False), CompoundStep) - @pytest.mark.skipif(theano.config.floatX == "float32", - reason="Test fails on 32 bit due to linalg issues") + @pytest.mark.skipif( + theano.config.floatX == "float32", + reason="Test fails on 32 bit due to linalg issues", + ) def test_blocked(self): _, model = simple_2model_continuous() with model: @@ -335,50 +879,53 @@ class TestAssignStepMethods(object): def test_bernoulli(self): """Test bernoulli distribution is assigned binary gibbs metropolis method""" with Model() as model: - Bernoulli('x', 0.5) + Bernoulli("x", 0.5) steps = assign_step_methods(model, []) assert isinstance(steps, BinaryGibbsMetropolis) def test_normal(self): """Test normal distribution is assigned NUTS method""" with Model() as model: - Normal('x', 0, 1) + Normal("x", 0, 1) steps = assign_step_methods(model, []) assert isinstance(steps, NUTS) def test_categorical(self): """Test categorical distribution is assigned categorical gibbs metropolis method""" with Model() as model: - Categorical('x', np.array([0.25, 0.75])) + Categorical("x", np.array([0.25, 0.75])) steps = assign_step_methods(model, []) assert isinstance(steps, BinaryGibbsMetropolis) with Model() as model: - Categorical('y', np.array([0.25, 0.70, 0.05])) + Categorical("y", np.array([0.25, 0.70, 0.05])) steps = assign_step_methods(model, []) assert isinstance(steps, CategoricalGibbsMetropolis) def test_binomial(self): """Test binomial distribution is assigned metropolis method.""" with Model() as model: - Binomial('x', 10, 0.5) + Binomial("x", 10, 0.5) steps = assign_step_methods(model, []) assert isinstance(steps, Metropolis) def test_normal_nograd_op(self): """Test normal distribution without an implemented gradient is assigned slice method""" with Model() as model: - x = Normal('x', 0, 1) + x = Normal("x", 0, 1) # a custom Theano Op that does not have a grad: is_64 = theano.config.floatX == "float64" itypes = [tt.dscalar] if is_64 else [tt.fscalar] otypes = [tt.dscalar] if is_64 else [tt.fscalar] + @theano.as_op(itypes, otypes) def kill_grad(x): return x data = np.random.normal(size=(100,)) - Normal("y", mu=kill_grad(x), sd=1, observed=data.astype(theano.config.floatX)) + Normal( + "y", mu=kill_grad(x), sd=1, observed=data.astype(theano.config.floatX) + ) steps = assign_step_methods(model, []) assert isinstance(steps, Slice) @@ -391,7 +938,7 @@ class TestPopulationSamplers(object): def test_checks_population_size(self): """Test that population samplers check the population size.""" with Model() as model: - n = Normal('n', mu=0, sd=1) + n = Normal("n", mu=0, sd=1) for stepper in TestPopulationSamplers.steppers: step = stepper() with pytest.raises(ValueError): @@ -401,91 +948,101 @@ def test_checks_population_size(self): def test_parallelized_chains_are_random(self): with Model() as model: - x = Normal('x', 0, 1) + x = Normal("x", 0, 1) for stepper in TestPopulationSamplers.steppers: step = stepper() - trace = sample(chains=4, draws=20, tune=0, step=DEMetropolis(), - parallelize=True) - samples = np.array(trace.get_values('x', combine=False))[:,5] + trace = sample( + chains=4, draws=20, tune=0, step=DEMetropolis(), parallelize=True + ) + samples = np.array(trace.get_values("x", combine=False))[:, 5] - assert len(set(samples)) == 4, 'Parallelized {} ' \ - 'chains are identical.'.format(stepper) + assert ( + len(set(samples)) == 4 + ), "Parallelized {} " "chains are identical.".format(stepper) pass -@pytest.mark.xfail(condition=(theano.config.floatX == "float32"), reason="Fails on float32") +@pytest.mark.xfail( + condition=(theano.config.floatX == "float32"), reason="Fails on float32" +) class TestNutsCheckTrace(object): def test_multiple_samplers(self, caplog): with Model(): - prob = Beta('prob', alpha=5., beta=3.) - Binomial('outcome', n=1, p=prob) + prob = Beta("prob", alpha=5.0, beta=3.0) + Binomial("outcome", n=1, p=prob) caplog.clear() - sample(3, tune=2, discard_tuned_samples=False, - n_init=None, chains=1) + sample(3, tune=2, discard_tuned_samples=False, n_init=None, chains=1) messages = [msg.msg for msg in caplog.records] - assert all('boolean index did not' not in msg for msg in messages) + assert all("boolean index did not" not in msg for msg in messages) def test_bad_init_nonparallel(self): with Model(): - HalfNormal('a', sd=1, testval=-1, transform=None) + HalfNormal("a", sd=1, testval=-1, transform=None) with pytest.raises(SamplingError) as error: sample(init=None, chains=1, random_seed=1) - error.match('Bad initial') - + error.match("Bad initial") + # TODO: This could probably be parameterized instead def test_bad_init_parallel(self): with Model(): - HalfNormal('a', sd=1, testval=-1, transform=None) + HalfNormal("a", sd=1, testval=-1, transform=None) with pytest.raises(ParallelSamplingError) as error: sample(init=None, cores=4, random_seed=1) - error.match('Bad initial') + error.match("Bad initial") def test_linalg(self, caplog): with Model(): - a = Normal('a', shape=2) + a = Normal("a", shape=2) a = tt.switch(a > 0, np.inf, a) b = tt.slinalg.solve(floatX(np.eye(2)), a) - Normal('c', mu=b, shape=2) + Normal("c", mu=b, shape=2) caplog.clear() trace = sample(20, init=None, tune=5, chains=2) warns = [msg.msg for msg in caplog.records] - assert np.any(trace['diverging']) + assert np.any(trace["diverging"]) assert ( - any('divergence after tuning' in warn - for warn in warns) - or - any('divergences after tuning' in warn - for warn in warns) - or - any('only diverging samples' in warn - for warn in warns)) + any("divergence after tuning" in warn for warn in warns) + or any("divergences after tuning" in warn for warn in warns) + or any("only diverging samples" in warn for warn in warns) + ) with pytest.raises(ValueError) as error: trace.report.raise_ok() - error.match('issues during sampling') + error.match("issues during sampling") assert not trace.report.ok def test_sampler_stats(self): with Model() as model: - x = Normal('x', mu=0, sd=1) + x = Normal("x", mu=0, sd=1) trace = sample(draws=10, tune=1, chains=1) # Assert stats exist and have the correct shape. expected_stat_names = { - 'depth', 'diverging', 'energy', 'energy_error', 'model_logp', - 'max_energy_error', 'mean_tree_accept', 'step_size', - 'step_size_bar', 'tree_size', 'tune' + "depth", + "diverging", + "energy", + "energy_error", + "model_logp", + "max_energy_error", + "mean_tree_accept", + "step_size", + "step_size_bar", + "tree_size", + "tune", } - assert(trace.stat_names == expected_stat_names) + assert trace.stat_names == expected_stat_names for varname in trace.stat_names: - assert(trace.get_sampler_stats(varname).shape == (10,)) + assert trace.get_sampler_stats(varname).shape == (10,) # Assert model logp is computed correctly: computing post-sampling # and tracking while sampling should give same results. - model_logp_ = np.array([ - model.logp(trace.point(i, chain=c)) - for c in trace.chains for i in range(len(trace)) - ]) - assert((trace.model_logp == model_logp_).all()) + model_logp_ = np.array( + [ + model.logp(trace.point(i, chain=c)) + for c in trace.chains + for i in range(len(trace)) + ] + ) + assert (trace.model_logp == model_logp_).all() From 7fd8033539aae2859b84ca00c2a462b32f7e8e0f Mon Sep 17 00:00:00 2001 From: springcoil Date: Sun, 28 Oct 2018 11:08:55 +0100 Subject: [PATCH 7/9] Change ParallelSampling to Sampling --- pymc3/tests/test_step.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pymc3/tests/test_step.py b/pymc3/tests/test_step.py index 8c87fd87b69..f7c5a96a1b5 100644 --- a/pymc3/tests/test_step.py +++ b/pymc3/tests/test_step.py @@ -987,7 +987,7 @@ def test_bad_init_nonparallel(self): def test_bad_init_parallel(self): with Model(): HalfNormal("a", sd=1, testval=-1, transform=None) - with pytest.raises(ParallelSamplingError) as error: + with pytest.raises(SamplingError) as error: sample(init=None, cores=4, random_seed=1) error.match("Bad initial") From 79bbfc22fb4a2ade7e164684555f39ef11a5c3fb Mon Sep 17 00:00:00 2001 From: springcoil Date: Sun, 28 Oct 2018 15:43:13 +0100 Subject: [PATCH 8/9] Adding back in ParallelSampling --- pymc3/tests/test_step.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/pymc3/tests/test_step.py b/pymc3/tests/test_step.py index f7c5a96a1b5..1ffc0133201 100644 --- a/pymc3/tests/test_step.py +++ b/pymc3/tests/test_step.py @@ -987,8 +987,10 @@ def test_bad_init_nonparallel(self): def test_bad_init_parallel(self): with Model(): HalfNormal("a", sd=1, testval=-1, transform=None) - with pytest.raises(SamplingError) as error: - sample(init=None, cores=4, random_seed=1) + + with pytest.raises(ParallelSamplingError) as error: + sample(init=None, cores=2, random_seed=1) + assert 0 error.match("Bad initial") def test_linalg(self, caplog): From defcc219ac2b5f09ed8c258e4bf70b4ed61de862 Mon Sep 17 00:00:00 2001 From: springcoil Date: Sun, 28 Oct 2018 15:46:55 +0100 Subject: [PATCH 9/9] AAAGH remove assertion --- pymc3/tests/test_step.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/pymc3/tests/test_step.py b/pymc3/tests/test_step.py index 1ffc0133201..805d356bdfe 100644 --- a/pymc3/tests/test_step.py +++ b/pymc3/tests/test_step.py @@ -987,10 +987,8 @@ def test_bad_init_nonparallel(self): def test_bad_init_parallel(self): with Model(): HalfNormal("a", sd=1, testval=-1, transform=None) - with pytest.raises(ParallelSamplingError) as error: sample(init=None, cores=2, random_seed=1) - assert 0 error.match("Bad initial") def test_linalg(self, caplog):