Example #1
0
 def setUp(self):
     data = south()
     data['n_samples'] = 0
     np.random.seed(TEST_SEED)
     self.trace = Trace.from_csv(FULL_PATH + '/data/south_mvcm_5000', multi=True)
     self.single_trace = Trace.from_csv(FULL_PATH + '/data/south_mvcm_5000_0.csv')
     self.size_known = json.load(open(FULL_PATH + '/data/effective_size.json', 'r'))
Example #2
0
 def setUp(self):
     data = south()
     data['n_samples'] = 0
     np.random.seed(TEST_SEED)
     self.trace = Trace.from_csv(FULL_PATH + '/data/south_mvcm_5000',
                                 multi=True)
     self.single_trace = Trace.from_csv(FULL_PATH +
                                        '/data/south_mvcm_5000_0.csv')
     self.geweke_known = json.load(open(FULL_PATH + '/data/geweke.json'))
Example #3
0
 def setUp(self):
     data = south()
     data['n_samples'] = 0
     np.random.seed(TEST_SEED)
     test_methods = ['obm', 'bm', 'bartlett', 'hanning', 'tukey']
     self.trace = Trace.from_csv(FULL_PATH + '/data/south_mvcm_5000', multi=True)
     self.single_trace = Trace.from_csv(FULL_PATH + '/data/south_mvcm_5000_0.csv')
     self.bm = json.load(open(FULL_PATH + '/data/mcse_bm.json', 'r'))
     self.obm = json.load(open(FULL_PATH + '/data/mcse_obm.json', 'r'))
     self.tukey = json.load(open(FULL_PATH + '/data/mcse_hanning.json', 'r'))
     self.bartlett = json.load(open(FULL_PATH + '/data/mcse_bartlett.json', 'r'))
     self.hanning = self.tukey
Example #4
0
def build():
    models = []
    for cand in M.__dict__.values():
        if isinstance(cand, CLASSTYPES):
            if issubclass(cand, Sampler_Mixin):
                models.append(cand)
    for model in models:
        print('starting {}'.format(model))
        env = south()
        del env['M']
        run_with_seed(model, env=env, seed=TEST_SEED, fprefix=FULL_PATH + '/data/')
    return os.listdir(FULL_PATH + '/data/')
Example #5
0
 def setUp(self):
     data = south()
     data['n_samples'] = 0
     with open(FULL_PATH + '/data/psrf_noburn.json', 'r') as noburn:
         self.noburn = json.load(noburn)
     with open(FULL_PATH + '/data/psrf_brooks.json', 'r') as brooks:
         self.known_brooks = json.load(brooks)
     with open(FULL_PATH + '/data/psrf_gr.json', 'r') as gr:
         self.known_gr = json.load(gr)
     np.random.seed(TEST_SEED)
     self.trace = Trace.from_csv(FULL_PATH + '/data/south_mvcm_5000', multi=True)
     self.mockmodel = Hashmap(trace=self.trace)
Example #6
0
 def setUp(self):
     data = south()
     data['n_samples'] = 0
     with open(FULL_PATH + '/data/psrf_noburn.json', 'r') as noburn:
         self.noburn = json.load(noburn)
     with open(FULL_PATH + '/data/psrf_brooks.json', 'r') as brooks:
         self.known_brooks = json.load(brooks)
     with open(FULL_PATH + '/data/psrf_gr.json', 'r') as gr:
         self.known_gr = json.load(gr)
     np.random.seed(TEST_SEED)
     self.trace = Trace.from_csv(FULL_PATH + '/data/south_mvcm_5000',
                                 multi=True)
     self.mockmodel = Hashmap(trace=self.trace)
Example #7
0
def run_with_seed(cls, env=utils.south(), seed=TEST_SEED, fprefix=''):
    fname = str(cls).strip("'<>'").split('.')[-1].lower()
    try:
        env['n_samples'] = 0
        model = cls(**env)
    except TypeError:
        reduced = copy.deepcopy(env)
        del reduced['M']
        del reduced['W']
        reduced['n_samples'] = 0
        model = cls(**reduced)
    np.random.seed(TEST_SEED)
    model.draw()
    model.trace.to_df().to_csv(fprefix + fname + '.csv', index=False)
Example #8
0
def run_with_seed(cls, env=utils.south(), seed=TEST_SEED, fprefix = ''):
    fname = str(cls).strip("'<>'").split('.')[-1].lower()
    try:
        env['n_samples'] = 0
        model = cls(**env)
    except TypeError:
        reduced = copy.deepcopy(env)
        del reduced['M']
        del reduced['W']
        reduced['n_samples'] = 0
        model = cls(**reduced)
    np.random.seed(TEST_SEED)
    model.draw()
    model.trace.to_df().to_csv(fprefix + fname + '.csv', index=False)
Example #9
0
def build():
    models = []
    for cand in M.__dict__.values():
        if isinstance(cand, CLASSTYPES):
            if issubclass(cand, Sampler_Mixin):
                models.append(cand)
    for model in models:
        print('starting {}'.format(model))
        env = south()
        del env['M']
        run_with_seed(model,
                      env=env,
                      seed=TEST_SEED,
                      fprefix=FULL_PATH + '/data/')
    return os.listdir(FULL_PATH + '/data/')
Example #10
0
 def setUp(self):
     data = south()
     data['n_samples'] = 0
     np.random.seed(TEST_SEED)
     test_methods = ['obm', 'bm', 'bartlett', 'hanning', 'tukey']
     self.trace = Trace.from_csv(FULL_PATH + '/data/south_mvcm_5000',
                                 multi=True)
     self.single_trace = Trace.from_csv(FULL_PATH +
                                        '/data/south_mvcm_5000_0.csv')
     self.bm = json.load(open(FULL_PATH + '/data/mcse_bm.json', 'r'))
     self.obm = json.load(open(FULL_PATH + '/data/mcse_obm.json', 'r'))
     self.tukey = json.load(open(FULL_PATH + '/data/mcse_hanning.json',
                                 'r'))
     self.bartlett = json.load(
         open(FULL_PATH + '/data/mcse_bartlett.json', 'r'))
     self.hanning = self.tukey
Example #11
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"]
Example #12
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'])
Example #13
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'])
Example #14
0
 def setUp(self):
     data = south()
     data['n_samples'] = 0
     np.random.seed(TEST_SEED)
     self.trace = Trace.from_csv(FULL_PATH + '/data/south_mvcm_5000',
                                 multi=True)
Example #15
0
 def build_self(self):
     super(Model_Mixin, self).__init__()
     self.inputs = utils.south()
     self.__dict__.update(self.inputs)
     self.ignore_shape = False
     self.squeeze = True
Example #16
0
 def setUp(self):
     data = south()
     data['n_samples'] = 0
     np.random.seed(TEST_SEED)
     self.trace = Trace.from_csv(FULL_PATH + '/data/south_mvcm_5000', multi=True)
Example #17
0
 def build_self(self):
     super(Model_Mixin, self).__init__()
     self.inputs = utils.south()
     self.__dict__.update(self.inputs)
     self.ignore_shape = False
     self.squeeze = True