cmdstanpy 1.2.4__tar.gz → 1.2.5__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {cmdstanpy-1.2.4/cmdstanpy.egg-info → cmdstanpy-1.2.5}/PKG-INFO +1 -1
- cmdstanpy-1.2.5/cmdstanpy/_version.py +3 -0
- {cmdstanpy-1.2.4 → cmdstanpy-1.2.5}/cmdstanpy/model.py +3 -3
- {cmdstanpy-1.2.4 → cmdstanpy-1.2.5}/cmdstanpy/stanfit/mcmc.py +13 -10
- {cmdstanpy-1.2.4 → cmdstanpy-1.2.5/cmdstanpy.egg-info}/PKG-INFO +1 -1
- {cmdstanpy-1.2.4 → cmdstanpy-1.2.5}/test/test_model.py +5 -2
- {cmdstanpy-1.2.4 → cmdstanpy-1.2.5}/test/test_sample.py +31 -30
- cmdstanpy-1.2.4/cmdstanpy/_version.py +0 -3
- {cmdstanpy-1.2.4 → cmdstanpy-1.2.5}/LICENSE.md +0 -0
- {cmdstanpy-1.2.4 → cmdstanpy-1.2.5}/MANIFEST.in +0 -0
- {cmdstanpy-1.2.4 → cmdstanpy-1.2.5}/README.md +0 -0
- {cmdstanpy-1.2.4 → cmdstanpy-1.2.5}/cmdstanpy/__init__.py +0 -0
- {cmdstanpy-1.2.4 → cmdstanpy-1.2.5}/cmdstanpy/cmdstan_args.py +0 -0
- {cmdstanpy-1.2.4 → cmdstanpy-1.2.5}/cmdstanpy/compilation.py +0 -0
- {cmdstanpy-1.2.4 → cmdstanpy-1.2.5}/cmdstanpy/install_cmdstan.py +0 -0
- {cmdstanpy-1.2.4 → cmdstanpy-1.2.5}/cmdstanpy/install_cxx_toolchain.py +0 -0
- {cmdstanpy-1.2.4 → cmdstanpy-1.2.5}/cmdstanpy/progress.py +0 -0
- {cmdstanpy-1.2.4 → cmdstanpy-1.2.5}/cmdstanpy/py.typed +0 -0
- {cmdstanpy-1.2.4 → cmdstanpy-1.2.5}/cmdstanpy/stanfit/__init__.py +0 -0
- {cmdstanpy-1.2.4 → cmdstanpy-1.2.5}/cmdstanpy/stanfit/gq.py +0 -0
- {cmdstanpy-1.2.4 → cmdstanpy-1.2.5}/cmdstanpy/stanfit/laplace.py +0 -0
- {cmdstanpy-1.2.4 → cmdstanpy-1.2.5}/cmdstanpy/stanfit/metadata.py +0 -0
- {cmdstanpy-1.2.4 → cmdstanpy-1.2.5}/cmdstanpy/stanfit/mle.py +0 -0
- {cmdstanpy-1.2.4 → cmdstanpy-1.2.5}/cmdstanpy/stanfit/pathfinder.py +0 -0
- {cmdstanpy-1.2.4 → cmdstanpy-1.2.5}/cmdstanpy/stanfit/runset.py +0 -0
- {cmdstanpy-1.2.4 → cmdstanpy-1.2.5}/cmdstanpy/stanfit/vb.py +0 -0
- {cmdstanpy-1.2.4 → cmdstanpy-1.2.5}/cmdstanpy/utils/__init__.py +0 -0
- {cmdstanpy-1.2.4 → cmdstanpy-1.2.5}/cmdstanpy/utils/cmdstan.py +0 -0
- {cmdstanpy-1.2.4 → cmdstanpy-1.2.5}/cmdstanpy/utils/command.py +0 -0
- {cmdstanpy-1.2.4 → cmdstanpy-1.2.5}/cmdstanpy/utils/data_munging.py +0 -0
- {cmdstanpy-1.2.4 → cmdstanpy-1.2.5}/cmdstanpy/utils/filesystem.py +0 -0
- {cmdstanpy-1.2.4 → cmdstanpy-1.2.5}/cmdstanpy/utils/json.py +0 -0
- {cmdstanpy-1.2.4 → cmdstanpy-1.2.5}/cmdstanpy/utils/logging.py +0 -0
- {cmdstanpy-1.2.4 → cmdstanpy-1.2.5}/cmdstanpy/utils/stancsv.py +0 -0
- {cmdstanpy-1.2.4 → cmdstanpy-1.2.5}/cmdstanpy.egg-info/SOURCES.txt +0 -0
- {cmdstanpy-1.2.4 → cmdstanpy-1.2.5}/cmdstanpy.egg-info/dependency_links.txt +0 -0
- {cmdstanpy-1.2.4 → cmdstanpy-1.2.5}/cmdstanpy.egg-info/entry_points.txt +0 -0
- {cmdstanpy-1.2.4 → cmdstanpy-1.2.5}/cmdstanpy.egg-info/requires.txt +0 -0
- {cmdstanpy-1.2.4 → cmdstanpy-1.2.5}/cmdstanpy.egg-info/top_level.txt +0 -0
- {cmdstanpy-1.2.4 → cmdstanpy-1.2.5}/pyproject.toml +0 -0
- {cmdstanpy-1.2.4 → cmdstanpy-1.2.5}/setup.cfg +0 -0
- {cmdstanpy-1.2.4 → cmdstanpy-1.2.5}/test/test_cmdstan_args.py +0 -0
- {cmdstanpy-1.2.4 → cmdstanpy-1.2.5}/test/test_compiler_opts.py +0 -0
- {cmdstanpy-1.2.4 → cmdstanpy-1.2.5}/test/test_compliance.py +0 -0
- {cmdstanpy-1.2.4 → cmdstanpy-1.2.5}/test/test_cxx_installation.py +0 -0
- {cmdstanpy-1.2.4 → cmdstanpy-1.2.5}/test/test_generate_quantities.py +0 -0
- {cmdstanpy-1.2.4 → cmdstanpy-1.2.5}/test/test_install_cmdstan.py +0 -0
- {cmdstanpy-1.2.4 → cmdstanpy-1.2.5}/test/test_laplace.py +0 -0
- {cmdstanpy-1.2.4 → cmdstanpy-1.2.5}/test/test_log_prob.py +0 -0
- {cmdstanpy-1.2.4 → cmdstanpy-1.2.5}/test/test_metadata.py +0 -0
- {cmdstanpy-1.2.4 → cmdstanpy-1.2.5}/test/test_optimize.py +0 -0
- {cmdstanpy-1.2.4 → cmdstanpy-1.2.5}/test/test_pathfinder.py +0 -0
- {cmdstanpy-1.2.4 → cmdstanpy-1.2.5}/test/test_runset.py +0 -0
- {cmdstanpy-1.2.4 → cmdstanpy-1.2.5}/test/test_utils.py +0 -0
- {cmdstanpy-1.2.4 → cmdstanpy-1.2.5}/test/test_variational.py +0 -0
|
@@ -205,9 +205,9 @@ class CmdStanModel:
|
|
|
205
205
|
self._compiler_options.add_include_path(path)
|
|
206
206
|
|
|
207
207
|
# try to detect models w/out parameters, needed for sampler
|
|
208
|
-
if not cmdstan_version_before(
|
|
209
|
-
2,
|
|
210
|
-
):
|
|
208
|
+
if (not cmdstan_version_before(2, 27)) and cmdstan_version_before(
|
|
209
|
+
2, 36
|
|
210
|
+
):
|
|
211
211
|
try:
|
|
212
212
|
model_info = self.src_info()
|
|
213
213
|
if 'parameters' in model_info:
|
|
@@ -412,7 +412,7 @@ class CmdStanMCMC:
|
|
|
412
412
|
self._step_size[chain] = float(step_size.strip())
|
|
413
413
|
if self._metadata.cmdstan_config['metric'] != 'unit_e':
|
|
414
414
|
line = fd.readline().strip() # metric type
|
|
415
|
-
line = fd.readline().lstrip(' #\t')
|
|
415
|
+
line = fd.readline().lstrip(' #\t').rstrip()
|
|
416
416
|
num_unconstrained_params = len(line.split(','))
|
|
417
417
|
if chain == 0: # can't allocate w/o num params
|
|
418
418
|
if self.metric_type == 'diag_e':
|
|
@@ -429,18 +429,21 @@ class CmdStanMCMC:
|
|
|
429
429
|
),
|
|
430
430
|
dtype=float,
|
|
431
431
|
)
|
|
432
|
-
if
|
|
433
|
-
|
|
434
|
-
self._metric[chain, :] = [float(x) for x in xs]
|
|
435
|
-
else:
|
|
436
|
-
xs = line.split(',')
|
|
437
|
-
self._metric[chain, 0, :] = [float(x) for x in xs]
|
|
438
|
-
for i in range(1, num_unconstrained_params):
|
|
439
|
-
line = fd.readline().lstrip(' #\t').strip()
|
|
432
|
+
if line:
|
|
433
|
+
if self.metric_type == 'diag_e':
|
|
440
434
|
xs = line.split(',')
|
|
441
|
-
self._metric[chain,
|
|
435
|
+
self._metric[chain, :] = [float(x) for x in xs]
|
|
436
|
+
else:
|
|
437
|
+
xs = line.strip().split(',')
|
|
438
|
+
self._metric[chain, 0, :] = [
|
|
442
439
|
float(x) for x in xs
|
|
443
440
|
]
|
|
441
|
+
for i in range(1, num_unconstrained_params):
|
|
442
|
+
line = fd.readline().lstrip(' #\t').rstrip()
|
|
443
|
+
xs = line.split(',')
|
|
444
|
+
self._metric[chain, i, :] = [
|
|
445
|
+
float(x) for x in xs
|
|
446
|
+
]
|
|
444
447
|
else: # unit_e changed in 2.34 to have an extra line
|
|
445
448
|
pos = fd.tell()
|
|
446
449
|
line = fd.readline().strip()
|
|
@@ -95,10 +95,13 @@ def test_exe_only() -> None:
|
|
|
95
95
|
assert not model2._fixed_param
|
|
96
96
|
|
|
97
97
|
|
|
98
|
-
def
|
|
98
|
+
def test_legacy_fixed_param() -> None:
|
|
99
99
|
stan = os.path.join(DATAFILES_PATH, 'datagen_poisson_glm.stan')
|
|
100
100
|
model = CmdStanModel(stan_file=stan)
|
|
101
|
-
|
|
101
|
+
if cmdstan_version_before(2, 36):
|
|
102
|
+
assert model._fixed_param
|
|
103
|
+
else:
|
|
104
|
+
assert not model._fixed_param
|
|
102
105
|
|
|
103
106
|
|
|
104
107
|
def test_model_pedantic(caplog: pytest.LogCaptureFixture) -> None:
|
|
@@ -642,13 +642,18 @@ def test_fixed_param_good() -> None:
|
|
|
642
642
|
assert datagen_fit.step_size is None
|
|
643
643
|
|
|
644
644
|
|
|
645
|
-
def
|
|
645
|
+
def test_sample_no_params() -> None:
|
|
646
646
|
stan = os.path.join(DATAFILES_PATH, 'datagen_poisson_glm.stan')
|
|
647
647
|
datagen_model = CmdStanModel(stan_file=stan)
|
|
648
648
|
datagen_fit = datagen_model.sample(iter_sampling=100, show_progress=False)
|
|
649
|
-
assert datagen_fit.step_size is None
|
|
650
649
|
summary = datagen_fit.summary()
|
|
651
|
-
|
|
650
|
+
|
|
651
|
+
if cmdstan_version_before(2, 36):
|
|
652
|
+
assert 'lp__' not in list(summary.index)
|
|
653
|
+
assert datagen_fit.step_size is None
|
|
654
|
+
else:
|
|
655
|
+
assert 'lp__' in list(summary.index)
|
|
656
|
+
assert np.isnan(datagen_fit.step_size).all()
|
|
652
657
|
|
|
653
658
|
exe_only = os.path.join(DATAFILES_PATH, 'exe_only')
|
|
654
659
|
shutil.copyfile(datagen_model.exe_file, exe_only)
|
|
@@ -656,9 +661,14 @@ def test_fixed_param_unspecified() -> None:
|
|
|
656
661
|
datagen2_model = CmdStanModel(exe_file=exe_only)
|
|
657
662
|
datagen2_fit = datagen2_model.sample(iter_sampling=200, show_console=True)
|
|
658
663
|
assert datagen2_fit.chains == 4
|
|
659
|
-
assert datagen2_fit.step_size is None
|
|
660
664
|
summary = datagen2_fit.summary()
|
|
661
|
-
|
|
665
|
+
|
|
666
|
+
if cmdstan_version_before(2, 36):
|
|
667
|
+
assert datagen2_fit.step_size is None
|
|
668
|
+
assert 'lp__' not in list(summary.index)
|
|
669
|
+
else:
|
|
670
|
+
assert np.isnan(datagen2_fit.step_size).all()
|
|
671
|
+
assert 'lp__' in list(summary.index)
|
|
662
672
|
|
|
663
673
|
|
|
664
674
|
def test_index_bounds_error() -> None:
|
|
@@ -823,7 +833,7 @@ def test_validate_good_run() -> None:
|
|
|
823
833
|
assert 'Treedepth satisfactory for all transitions.' in diagnostics
|
|
824
834
|
assert 'No divergent transitions found.' in diagnostics
|
|
825
835
|
assert 'E-BFMI satisfactory' in diagnostics
|
|
826
|
-
assert '
|
|
836
|
+
assert 'effective sample size satisfactory' in diagnostics.lower()
|
|
827
837
|
|
|
828
838
|
|
|
829
839
|
def test_validate_big_run() -> None:
|
|
@@ -986,6 +996,12 @@ def test_from_csv_fixed_param() -> None:
|
|
|
986
996
|
assert fixed_param_sample.draws_pd().shape == (100, 88)
|
|
987
997
|
|
|
988
998
|
|
|
999
|
+
def test_from_csv_no_param_hmc() -> None:
|
|
1000
|
+
csv_path = os.path.join(DATAFILES_PATH, 'no_param_hmc_sample.csv')
|
|
1001
|
+
no_parameters_sample = from_csv(path=csv_path)
|
|
1002
|
+
assert no_parameters_sample.draws_pd().shape == (100, 93)
|
|
1003
|
+
|
|
1004
|
+
|
|
989
1005
|
def test_custom_metric() -> None:
|
|
990
1006
|
stan = os.path.join(DATAFILES_PATH, 'bernoulli.stan')
|
|
991
1007
|
jdata = os.path.join(DATAFILES_PATH, 'bernoulli.data.json')
|
|
@@ -1621,33 +1637,18 @@ def test_validate_sample_sig_figs(stanfile='bernoulli.stan'):
|
|
|
1621
1637
|
|
|
1622
1638
|
|
|
1623
1639
|
def test_validate_summary_sig_figs() -> None:
|
|
1624
|
-
# construct CmdStanMCMC from logistic model output
|
|
1625
|
-
|
|
1626
|
-
|
|
1627
|
-
|
|
1628
|
-
|
|
1629
|
-
|
|
1630
|
-
|
|
1631
|
-
|
|
1632
|
-
seed=12345,
|
|
1633
|
-
data=rdata,
|
|
1634
|
-
output_dir=DATAFILES_PATH,
|
|
1635
|
-
sig_figs=17,
|
|
1636
|
-
method_args=sampler_args,
|
|
1640
|
+
# construct CmdStanMCMC from logistic model output
|
|
1641
|
+
fit = from_csv(
|
|
1642
|
+
[
|
|
1643
|
+
os.path.join(DATAFILES_PATH, 'logistic_output_1.csv'),
|
|
1644
|
+
os.path.join(DATAFILES_PATH, 'logistic_output_2.csv'),
|
|
1645
|
+
os.path.join(DATAFILES_PATH, 'logistic_output_3.csv'),
|
|
1646
|
+
os.path.join(DATAFILES_PATH, 'logistic_output_4.csv'),
|
|
1647
|
+
]
|
|
1637
1648
|
)
|
|
1638
|
-
runset = RunSet(args=cmdstan_args, chains=4)
|
|
1639
|
-
runset._csv_files = [
|
|
1640
|
-
os.path.join(DATAFILES_PATH, 'logistic_output_1.csv'),
|
|
1641
|
-
os.path.join(DATAFILES_PATH, 'logistic_output_2.csv'),
|
|
1642
|
-
os.path.join(DATAFILES_PATH, 'logistic_output_3.csv'),
|
|
1643
|
-
os.path.join(DATAFILES_PATH, 'logistic_output_4.csv'),
|
|
1644
|
-
]
|
|
1645
|
-
retcodes = runset._retcodes
|
|
1646
|
-
for i in range(len(retcodes)):
|
|
1647
|
-
runset._set_retcode(i, 0)
|
|
1648
|
-
fit = CmdStanMCMC(runset)
|
|
1649
1649
|
|
|
1650
1650
|
sum_default = fit.summary()
|
|
1651
|
+
|
|
1651
1652
|
beta1_default = format(sum_default.iloc[1, 0], '.18g')
|
|
1652
1653
|
assert beta1_default.startswith('1.3')
|
|
1653
1654
|
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|