Exemplo n.º 1
0
 def test_options(self):
     exp_brooks = psrf(trace=self.mockmodel.trace)
     for k,v in exp_brooks.items():
         if k == 'Alphas':
             continue
         np.testing.assert_allclose(v, np.squeeze(self.known_brooks[k]),
                                    rtol=RTOL, atol=ATOL,
                                    err_msg='Failed in {}'.format(k))
     exp_brooks = psrf(chain=self.mockmodel.trace['Tau2'])
     np.testing.assert_allclose(exp_brooks['parameter'],
                                self.known_brooks['Tau2'],
                                rtol=RTOL, atol=ATOL,
                                err_msg='Failed in Tau2')
     test_completion = psrf(trace=self.trace, autoburnin=False)
     for k,v in self.noburn.items():
         if k == 'Alphas':
             continue
             np.testing.assert_allclose(v, np.squeeze(test_completion[k]),
                                    rtol=1e-5, atol=1e-5,
                                    err_msg='Failed in {}'.format(k))
     limit_vars = psrf(trace=self.trace, varnames=['Tau2', 'Sigma2'])
     for k,v in limit_vars.items():
         if k == 'Alphas':
             continue
         np.testing.assert_allclose(v, np.squeeze(limit_vars[k]),
                                    rtol=RTOL, atol=ATOL,
                                    err_msg='Failed in {}'.format(k))
Exemplo n.º 2
0
 def test_options(self):
     exp_brooks = psrf(trace=self.mockmodel.trace)
     for k, v in exp_brooks.items():
         if k == 'Alphas':
             continue
         np.testing.assert_allclose(v,
                                    np.squeeze(self.known_brooks[k]),
                                    rtol=RTOL,
                                    atol=ATOL,
                                    err_msg='Failed in {}'.format(k))
     exp_brooks = psrf(chain=self.mockmodel.trace['Tau2'])
     np.testing.assert_allclose(exp_brooks['parameter'],
                                self.known_brooks['Tau2'],
                                rtol=RTOL,
                                atol=ATOL,
                                err_msg='Failed in Tau2')
     test_completion = psrf(trace=self.trace, autoburnin=False)
     for k, v in self.noburn.items():
         if k == 'Alphas':
             continue
             np.testing.assert_allclose(v,
                                        np.squeeze(test_completion[k]),
                                        rtol=1e-5,
                                        atol=1e-5,
                                        err_msg='Failed in {}'.format(k))
     limit_vars = psrf(trace=self.trace, varnames=['Tau2', 'Sigma2'])
     for k, v in limit_vars.items():
         if k == 'Alphas':
             continue
         np.testing.assert_allclose(v,
                                    np.squeeze(limit_vars[k]),
                                    rtol=RTOL,
                                    atol=ATOL,
                                    err_msg='Failed in {}'.format(k))
Exemplo n.º 3
0
 def test_coef_recovery(self):
     #test with:
     #model=model, trace=model.trace, chain=model.trace['asdf']
     #autoburnin=False, method='original'
     exp_brooks = psrf(self.mockmodel)
     for k,v in exp_brooks.items():
         if k == 'Alphas':
             continue
         np.testing.assert_allclose(v, np.squeeze(self.known_brooks[k]),
                                    rtol=RTOL, atol=ATOL,
                                    err_msg='Failed in {}'.format(k))
     exp_gr = psrf(trace=self.trace, method='original')
     for k,v in exp_gr.items():
         if k == 'Alphas':
             continue
         np.testing.assert_allclose(v, np.squeeze(self.known_gr[k]),
                                    rtol=RTOL, atol=ATOL,
                                    err_msg='Failed in {}'.format(k))
Exemplo n.º 4
0
def build():
    data = south()
    del data['W']
    del data['M']
    model = pysal.model.spvcm.both.MVCM(**data, n_samples=0)
    np.random.seed(TEST_SEED)
    print('starting South 5000, njobs=4')
    model.sample(5000, n_jobs=4)
    print('starting PSRF')
    known_brooks = psrf(model)
    known_gr = psrf(model, method='original')

    import json
    with open(FULL_PATH + '/data/' + 'psrf_brooks.json', 'w') as brooks:
        json.dump(known_brooks, brooks)
    with open(FULL_PATH + '/data/' + 'psrf_gr.json', 'w') as gr:
        json.dump(known_gr, gr)
    for i, method in enumerate(['bm', 'obm', 'bartlett', 'hanning']):
        known_mcse = mcse(model, varnames=['Tau2'], method=method)
        with open(FULL_PATH + '/data/' + 'mcse_{}.json'.format(i, method),
                  'w') as mcse_file:
            json.dump(known_mcse, mcse_file)

    known_hpd = hpd_interval(model, varnames=['Sigma2'])
    with open(FULL_PATH + '/data/' + 'hpd_interval.json', 'w') as hpd_file:
        json.dump(known_hpd, hpd_file)

    known_size = effective_size(model, varnames=['Tau2'], use_R=False)
    with open(FULL_PATH + '/data/' + 'effective_size.json', 'w') as size_file:
        json.dump(known_size, size_file)

    known_geweke = geweke(model, varnames=['Sigma2'])
    known_geweke = [{k: v.tolist()
                     for k, v in known.items()} for known in known_geweke]
    with open(FULL_PATH + '/data/' + 'geweke.json', 'w') as geweke_file:
        json.dump(known_geweke, geweke_file)

    model.trace.to_csv(FULL_PATH + '/data/' + 'south_mvcm_5000.csv')
    return ([
        FULL_PATH + '/data/' + 'psrf_{}.json'.format(k)
        for k in ['brooks', 'gr']
    ] + [FULL_PATH + '/data/south_mvcm_5000.csv'])
Exemplo n.º 5
0
def build():
    data = south()
    del data["W"]
    del data["M"]
    model = pysal.model.spvcm.both.MVCM(**data, n_samples=0)
    np.random.seed(TEST_SEED)
    print("starting South 5000, njobs=4")
    model.sample(5000, n_jobs=4)
    print("starting PSRF")
    known_brooks = psrf(model)
    known_gr = psrf(model, method="original")

    import json

    with open(FULL_PATH + "/data/" + "psrf_brooks.json", "w") as brooks:
        json.dump(known_brooks, brooks)
    with open(FULL_PATH + "/data/" + "psrf_gr.json", "w") as gr:
        json.dump(known_gr, gr)
    for i, method in enumerate(["bm", "obm", "bartlett", "hanning"]):
        known_mcse = mcse(model, varnames=["Tau2"], method=method)
        with open(
            FULL_PATH + "/data/" + "mcse_{}.json".format(i, method), "w"
        ) as mcse_file:
            json.dump(known_mcse, mcse_file)

    known_hpd = hpd_interval(model, varnames=["Sigma2"])
    with open(FULL_PATH + "/data/" + "hpd_interval.json", "w") as hpd_file:
        json.dump(known_hpd, hpd_file)

    known_size = effective_size(model, varnames=["Tau2"], use_R=False)
    with open(FULL_PATH + "/data/" + "effective_size.json", "w") as size_file:
        json.dump(known_size, size_file)

    known_geweke = geweke(model, varnames=["Sigma2"])
    known_geweke = [{k: v.tolist() for k, v in known.items()} for known in known_geweke]
    with open(FULL_PATH + "/data/" + "geweke.json", "w") as geweke_file:
        json.dump(known_geweke, geweke_file)

    model.trace.to_csv(FULL_PATH + "/data/" + "south_mvcm_5000.csv")
    return [
        FULL_PATH + "/data/" + "psrf_{}.json".format(k) for k in ["brooks", "gr"]
    ] + [FULL_PATH + "/data/south_mvcm_5000.csv"]
Exemplo n.º 6
0
 def test_coef_recovery(self):
     #test with:
     #model=model, trace=model.trace, chain=model.trace['asdf']
     #autoburnin=False, method='original'
     exp_brooks = psrf(self.mockmodel)
     for k, v in exp_brooks.items():
         if k == 'Alphas':
             continue
         np.testing.assert_allclose(v,
                                    np.squeeze(self.known_brooks[k]),
                                    rtol=RTOL,
                                    atol=ATOL,
                                    err_msg='Failed in {}'.format(k))
     exp_gr = psrf(trace=self.trace, method='original')
     for k, v in exp_gr.items():
         if k == 'Alphas':
             continue
         np.testing.assert_allclose(v,
                                    np.squeeze(self.known_gr[k]),
                                    rtol=RTOL,
                                    atol=ATOL,
                                    err_msg='Failed in {}'.format(k))
Exemplo n.º 7
0
def build():
    data = south()
    del data['W']
    del data['M']
    model = pysal.model.spvcm.both.MVCM(**data, n_samples=0)
    np.random.seed(TEST_SEED)
    print('starting South 5000, njobs=4')
    model.sample(5000,n_jobs=4)
    print('starting PSRF')
    known_brooks = psrf(model)
    known_gr = psrf(model, method='original')


    import json
    with open(FULL_PATH + '/data/' + 'psrf_brooks.json', 'w') as brooks:
        json.dump(known_brooks, brooks)
    with open(FULL_PATH + '/data/' + 'psrf_gr.json', 'w') as gr:
        json.dump(known_gr, gr)
    for i, method in enumerate(['bm', 'obm', 'bartlett', 'hanning']):
        known_mcse = mcse(model, varnames=['Tau2'], method=method)
        with open(FULL_PATH + '/data/' + 'mcse_{}.json'.format(i,method), 'w') as mcse_file:
            json.dump(known_mcse, mcse_file)

    known_hpd = hpd_interval(model, varnames=['Sigma2'])
    with open(FULL_PATH + '/data/' + 'hpd_interval.json', 'w') as hpd_file:
        json.dump(known_hpd, hpd_file)

    known_size = effective_size(model, varnames=['Tau2'], use_R=False)
    with open(FULL_PATH + '/data/' + 'effective_size.json', 'w') as size_file:
        json.dump(known_size, size_file)

    known_geweke = geweke(model, varnames=['Sigma2'])
    known_geweke = [{k:v.tolist() for k,v in known.items()} for known in known_geweke]
    with open(FULL_PATH + '/data/' + 'geweke.json', 'w') as geweke_file:
        json.dump(known_geweke, geweke_file)

    model.trace.to_csv(FULL_PATH + '/data/' + 'south_mvcm_5000.csv')
    return ([FULL_PATH + '/data/' + 'psrf_{}.json'.format(k)
             for k in ['brooks', 'gr']] + [FULL_PATH + '/data/south_mvcm_5000.csv'])