def get_fit_larger_uncertainties(): """ Returns fit file for unit tests, uses data with larger uncertainties. """ info_path = InfoPath(path='temp_data', dir_name="a01_eight_schools_large_uncert", sub_dir_name=InfoPath.DO_NOT_CREATE) run(info_path=info_path, func=run_model, data=get_data()) # Use data with increased uncertainties data = get_data() data["sigma"] = [u * 2 for u in data["sigma"]] return run(info_path=info_path, func=run_model, data=data)
def get_fit2(): """ Returns fit file for unit tests, uses data with larger uncertainties. """ info_path = InfoPath(path='temp_data', dir_name="a02_gaussian_mixture2", sub_dir_name=InfoPath.DO_NOT_CREATE) return run(info_path=info_path, func=run_model, data=get_data2())
def get_fit(): """ Returns fit file for unit tests. """ info_path = InfoPath(path='temp_data', dir_name="a01_eight_schools", sub_dir_name=InfoPath.DO_NOT_CREATE) return run(info_path=info_path, func=run_model, data=get_data())
def run_model(): data = { "J": 8, "y": [28, 8, -3, 7, -1, 1, 18, 12], "sigma": [15, 10, 16, 11, 9, 11, 10, 18] } # Will only run Stan once and cache the samples to disk fit = run(func=run_stan, mydata=data) print('\nColumn names: ') print(fit.column_names)
def get_fit1_divorse_age(): info_path = InfoPath(path='temp_data', dir_name="a05_divorse1_divorse_age", sub_dir_name=InfoPath.DO_NOT_CREATE) iters = get_iters() data = get_data1_divorse_age() return run(info_path=info_path, func=run_model1_divorse_age, data=data, sampling_iters=iters["sampling_iters"], warmup_iters=iters["warmup_iters"])
def test_run(): outdir = "tarpan/cmdstanpy/model_info/cache_test" if os.path.isdir(outdir): shutil.rmtree(outdir) data = {"count": 1} fit = run(myfunc, data=data) assert os.path.isfile(os.path.join(outdir, "stan_cache", "fit.pkl")) assert 'tau' in fit.column_names assert fit.get_drawset()['tau'].shape == (1000,) # Call it again fit = run(myfunc, data=data) assert 'tau' in fit.column_names assert fit.get_drawset()['tau'].shape == (1000,) # Ensure `myfunc` was called once assert data["count"] == 2
def get_fit3_treatment(): """ Returns fit file for unit tests. """ info_path = InfoPath(path='temp_data', dir_name="a04_height3_treatment", sub_dir_name=InfoPath.DO_NOT_CREATE) iters = get_iters() data = get_data3_treatment() return run(info_path=info_path, func=run_model3_treatment, data=data, sampling_iters=iters["sampling_iters"], warmup_iters=iters["warmup_iters"])