示例#1
0
def test_model():
    raw_trace = np.genfromtxt(TEST_DATA_PATH, delimiter=',')
    dt = 0.0001

    vcinfer = VCInfer(raw_trace, dt, config='config_testing.json')
    vcinfer.momenta()
    vcinfer.psd_calc()
    vcinfer.estimate_taus()
    vcinfer.reset_obs_unc()
    vcinfer.set_obs_unc_mean()
    vcinfer.set_obs_unc_std()

    dist_list = ['LogNormal', 'TruncNormal']  #, 'Exponential' it takes ages

    for dist_type in dist_list:
        vcinfer.first_guess(distType=dist_type)
        vcinfer.optimize_likelihood()

        vcinfer.create_model()
        vcinfer.run_sampler()
        vcinfer.plot_mc_results(save_pdf=True)
        assert 'map' in vcinfer.inference_results
        assert 'mh' in vcinfer.inference_results

        for el in ['weights', 'parameters', 'metrics']:
            assert el in vcinfer.inference_results['map']

        for el in ['weights', 'parameters', 'dic', 'mcmc_object']:
            assert el in vcinfer.inference_results['mh']
示例#2
0
def test_likelihood_est_f():
    config_file = os.path.join(CONFIG_DIR, 'config.json')

    with open(config_file, mode='r') as fp:
        config = json.load(fp)

    raw_trace = np.genfromtxt(TEST_DATA_PATH, delimiter=',')
    dt = 0.0001

    vcinfer = VCInfer(raw_trace, dt)
    vcinfer.momenta()
    vcinfer.psd_calc()
    vcinfer.estimate_taus()
    vcinfer.reset_obs_unc()
    vcinfer.set_obs_unc_mean()
    vcinfer.set_obs_unc_std()

    vcinfer.first_guess(distType='LogNormal')
    vcinfer.optimize_likelihood()
    vcinfer.plot_likelihood(save_pdf=True)

    assert len(vcinfer.likelihood_samples.index
               ) == config['likelihood_par']['nsamples']
    assert 'kde_ll' in vcinfer.likelihood_estim
    assert 'moments_sim' in vcinfer.likelihood_estim

    assert len(
        vcinfer.likelihood_estim['moments_sim']['mean']) == vcinfer.n_moments
示例#3
0
def test_first_guess():

    raw_trace = np.genfromtxt(TEST_DATA_PATH, delimiter=',')
    dt = 0.0001

    vcinfer = VCInfer(raw_trace, dt)
    vcinfer.momenta()
    vcinfer.psd_calc()
    vcinfer.estimate_taus()
    vcinfer.reset_obs_unc()
    vcinfer.set_obs_unc_mean()
    vcinfer.set_obs_unc_std()

    dist_list = ['LogNormal', 'Exponential', 'TruncNormal']

    for dist_type in dist_list:
        logging.info('******************** Inference using {} weights'.format(
            dist_type))
        vcinfer.first_guess(distType=dist_type)
        assert vcinfer.param_priors['pw0'][0] > 0.
        assert vcinfer.param_priors['pw1'][0] > 0.
        assert vcinfer.param_priors['freq'][0] > 0.