Пример #1
0
def atest2_normal_bbvi_elbo():
    """
    Tests that the ELBO increases
    """
    model = pf.GASReg(formula="y ~ x1 + x2", data=data, family=pf.Laplace())
    x = model.fit('BBVI',iterations=100, record_elbo=True)
    assert(x.elbo_records[-1]>x.elbo_records[0])
Пример #2
0
def test_normal_bbvi_mini_batch_elbo():
    """
    Tests that the ELBO increases
    """
    model = pf.GASReg(formula="y ~ x1 + x2", data=data, family=pf.Normal())
    x = model.fit('BBVI', iterations=100, mini_batch=32, record_elbo=True)
    assert (x.elbo_records[-1] > x.elbo_records[0])
Пример #3
0
def test_t_predict_is_length():
    """
	Tests that the length of the predict IS dataframe is equal to no of steps h
	"""
    model = pf.GASReg(formula="y ~ x1", data=data, family=pf.GASt())
    x = model.fit()
    assert (model.predict_is(h=5).shape[0] == 5)
def test_normal_bbvi_elbo():
    """
    Tests that the ELBO increases
    """
    model = pf.GASReg(formula="y ~ x1 + x2", data=data, family=pf.Poisson())
    x = model.fit('BBVI',iterations=200, record_elbo=True, map_start=False)
    assert(x.elbo_records[-1]>x.elbo_records[0])
Пример #5
0
def test2_poisson_predict_is_nans():
	"""
	Tests that the predictions in-sample are not NaNs
	"""
	model = pf.GASReg(formula="y ~ x1 + x2", data=data, family=pf.GASPoisson())
	x = model.fit()
	x.summary()
	assert(len(model.predict_is(h=5).values[np.isnan(model.predict_is(h=5).values)]) == 0)
Пример #6
0
def atest_normal_predict_is_nans():
    """
    Tests that the predictions in-sample are not NaNs
    """
    model = pf.GASReg(formula="y ~ x1", data=data, family=pf.Laplace())
    x = model.fit()
    x.summary()
    assert(len(model.predict_is(h=5).values[np.isnan(model.predict_is(h=5).values)]) == 0)
Пример #7
0
def test2_ppc():
    """
    Tests PPC value
    """
    model = pf.GASReg(formula="y ~ x1  + x2", data=data, family=pf.Normal())
    x = model.fit('BBVI', iterations=100)
    p_value = model.ppc()
    assert (0.0 <= p_value <= 1.0)
Пример #8
0
def atest_ppc():
    """
    Tests PPC value
    """
    model = pf.GASReg(formula="y ~ x1", data=data, family=pf.Laplace())
    x = model.fit('BBVI', iterations=100)
    p_value = model.ppc()
    assert(0.0 <= p_value <= 1.0)
def test_skewt_predict_length():
    """
	Tests that the length of the predict dataframe is equal to no of steps h
	"""
    model = pf.GASReg(formula="y ~ x1", data=data, family=pf.Skewt())
    x = model.fit()
    x.summary()
    assert (model.predict(h=5, oos_data=data_oos).shape[0] == 5)
Пример #10
0
def atest2_normal_predict_nans():
    """
    Tests that the predictions are not NaNs
    """
    model = pf.GASReg(formula="y ~ x1 + x2", data=data, family=pf.Laplace())
    x = model.fit()
    x.summary()
    assert(len(model.predict(h=5, oos_data=data_oos).values[np.isnan(model.predict(h=5, 
        oos_data=data_oos).values)]) == 0)
Пример #11
0
def test_poisson_predict_nans():
	"""
	Tests that the predictions are not NaNs
	"""
	model = pf.GASReg(formula="y ~ x1", data=data, family=pf.GASPoisson())
	x = model.fit()
	x.summary()
	assert(len(model.predict(h=5, oos_data=data_oos).values[np.isnan(model.predict(h=5, 
		oos_data=data_oos).values)]) == 0)
Пример #12
0
def test2_sample_model():
    """
    Tests sampling function
    """
    model = pf.GASReg(formula="y ~ x1 + x2", data=data, family=pf.Normal())
    x = model.fit('BBVI', iterations=100)
    sample = model.sample(nsims=100)
    assert (sample.shape[0] == 100)
    assert (sample.shape[1] == len(data))
def test_skewt_bbvi():
    """
	Tests an GASReg model estimated with BBVI, and tests that the latent variable
	vector length is correct, and that value are not nan
	"""
    model = pf.GASReg(formula="y ~ x1", data=data, family=pf.Skewt())
    x = model.fit('BBVI', iterations=100)
    assert (len(model.latent_variables.z_list) == 5)
    lvs = np.array([i.value for i in model.latent_variables.z_list])
    assert (len(lvs[np.isnan(lvs)]) == 0)
def test_skewt_basic():
    """
	Tests the length of the latent variable vector for an GASReg model
	with no AR or MA terms, and tests that the values are not nan
	"""
    model = pf.GASReg(formula="y ~ x1", data=data, family=pf.Skewt())
    x = model.fit()
    assert (len(model.latent_variables.z_list) == 5)
    lvs = np.array([i.value for i in model.latent_variables.z_list])
    assert (len(lvs[np.isnan(lvs)]) == 0)
Пример #15
0
def test_t_pml():
    """
	Tests an GASReg model estimated with PML, and tests that the latent variable
	vector length is correct, and that value are not nan
	"""
    model = pf.GASReg(formula="y ~ x1", data=data, family=pf.GASt())
    x = model.fit('PML')
    assert (len(model.latent_variables.z_list) == 4)
    lvs = np.array([i.value for i in model.latent_variables.z_list])
    assert (len(lvs[np.isnan(lvs)]) == 0)
Пример #16
0
def test2_t_normal():
    """
	Tests an GASReg model estimated with Laplace, with multiple predictors, and 
	tests that the latent variable vector length is correct, and that value are not nan
	"""
    model = pf.GASReg(formula="y ~ x1 + x2", data=data, family=pf.GASt())
    x = model.fit('Laplace')
    assert (len(model.latent_variables.z_list) == 5)
    lvs = np.array([i.value for i in model.latent_variables.z_list])
    assert (len(lvs[np.isnan(lvs)]) == 0)
Пример #17
0
def test_normal_laplace():
    """
    Tests an GASReg model estimated with Laplace approximation, and tests that the latent variable
    vector length is correct, and that value are not nan
    """
    model = pf.GASReg(formula="y ~ x1", data=data, family=pf.Normal())
    x = model.fit('Laplace')
    assert (len(model.latent_variables.z_list) == 3)
    lvs = np.array([i.value for i in model.latent_variables.z_list])
    assert (len(lvs[np.isnan(lvs)]) == 0)
Пример #18
0
def test_normal_mh():
    """
    Tests an GASReg model estimated with Metropolis-Hastings, and tests that the latent variable
    vector length is correct, and that value are not nan
    """
    model = pf.GASReg(formula="y ~ x1", data=data, family=pf.Normal())
    x = model.fit('M-H', nsims=300)
    assert (len(model.latent_variables.z_list) == 3)
    lvs = np.array([i.value for i in model.latent_variables.z_list])
    assert (len(lvs[np.isnan(lvs)]) == 0)
Пример #19
0
def atest2_predict_is_intervals():
    """
    Tests prediction intervals are ordered correctly
    """
    model = pf.GASReg(formula="y ~ x1  + x2", data=data, family=pf.Laplace())
    x = model.fit()
    predictions = model.predict_is(h=10, intervals=True)
    assert(np.all(predictions['99% Prediction Interval'].values > predictions['95% Prediction Interval'].values))
    assert(np.all(predictions['95% Prediction Interval'].values > predictions['5% Prediction Interval'].values))
    assert(np.all(predictions['5% Prediction Interval'].values > predictions['1% Prediction Interval'].values))
Пример #20
0
def test_normal_bbvi_mini_batch():
    """
    Tests an ARIMA model estimated with BBVI and that the length of the latent variable
    list is correct, and that the estimated latent variables are not nan
    """
    model = pf.GASReg(formula="y ~ x1", data=data, family=pf.Normal())
    x = model.fit('BBVI', iterations=100, mini_batch=32)
    assert (len(model.latent_variables.z_list) == 3)
    lvs = np.array([i.value for i in model.latent_variables.z_list])
    assert (len(lvs[np.isnan(lvs)]) == 0)
def test2_normal_bbvi():
    """
    Tests an GASReg model estimated with BBVI, with multiple predictors, and 
    tests that the latent variable vector length is correct, and that value are not nan
    """
    model = pf.GASReg(formula="y ~ x1 + x2", data=data, family=pf.Poisson())
    x = model.fit('BBVI',iterations=100)
    assert(len(model.latent_variables.z_list) == 3)
    lvs = np.array([i.value for i in model.latent_variables.z_list])
    assert(len(lvs[np.isnan(lvs)]) == 0)
def test2_predict_is_intervals_bbvi():
    """
    Tests prediction intervals are ordered correctly
    """
    model = pf.GASReg(formula="y ~ x1 + x2", data=data, family=pf.Poisson())
    x = model.fit('BBVI', iterations=100)
    predictions = model.predict_is(h=10, intervals=True)
    assert(np.all(predictions['99% Prediction Interval'].values >= predictions['95% Prediction Interval'].values))
    assert(np.all(predictions['95% Prediction Interval'].values >= predictions['5% Prediction Interval'].values))
    assert(np.all(predictions['5% Prediction Interval'].values >= predictions['1% Prediction Interval'].values))
Пример #23
0
def atest_predict_intervals_bbvi():
    """
    Tests prediction intervals are ordered correctly
    """
    model = pf.GASReg(formula="y ~ x1", data=data, family=pf.Laplace())
    x = model.fit('BBVI', iterations=100)
    predictions = model.predict(h=10, oos_data=data_oos, intervals=True)

    assert(np.all(predictions['99% Prediction Interval'].values > predictions['95% Prediction Interval'].values))
    assert(np.all(predictions['95% Prediction Interval'].values > predictions['5% Prediction Interval'].values))
    assert(np.all(predictions['5% Prediction Interval'].values > predictions['1% Prediction Interval'].values))
def test_predict_intervals():
    """
    Tests prediction intervals are ordered correctly
    """
    model = pf.GASReg(formula="y ~ x1", data=data, family=pf.Poisson())
    x = model.fit()
    predictions = model.predict(h=10, oos_data=data_oos, intervals=True)

    assert(np.all(predictions['99% Prediction Interval'].values >= predictions['95% Prediction Interval'].values))
    assert(np.all(predictions['95% Prediction Interval'].values >= predictions['5% Prediction Interval'].values))
    assert(np.all(predictions['5% Prediction Interval'].values >= predictions['1% Prediction Interval'].values))
Пример #25
0
def test2_normal_no_terms():
    """
    Tests the length of the latent variable vector for an GASReg model
    with no AR or MA terms, and two predictors, and tests that the values 
    are not nan
    """
    model = pf.GASReg(formula="y ~ x1 + x2", data=data, family=pf.Normal())
    x = model.fit()
    assert (len(model.latent_variables.z_list) == 4)
    lvs = np.array([i.value for i in model.latent_variables.z_list])
    assert (len(lvs[np.isnan(lvs)]) == 0)
Пример #26
0
def test2_poisson_couple_terms():
	"""
	Tests the length of the latent variable vector for an GASReg model
	with 1 AR and 1 MA term, and two predictors, and tests that the values 
	are not nan
	"""
	model = pf.GASReg(formula="y ~ x1 + x2", data=data, family=pf.GASPoisson())
	x = model.fit()
	assert(len(model.latent_variables.z_list) == 3)
	lvs = np.array([i.value for i in model.latent_variables.z_list])
	assert(len(lvs[np.isnan(lvs)]) == 0)
Пример #27
0
def build_model(data, family=pf.families.Laplace, formula=None):
    if formula is None:
        formula = "casos~temp_min"
    model = pf.GASReg(data=data, family=family(), formula=formula)
    return model