예제 #1
0
def atest2_normal_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 + x2", data=data, family=pf.Laplace())
    x = model.fit()
    assert(model.predict_is(h=5).shape[0] == 5)
예제 #2
0
def atest_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, map_start=False)
    assert(x.elbo_records[-1]>x.elbo_records[0])
예제 #3
0
def test_bbvi_mini_batch_elbo():
    """
    Tests that the ELBO increases
    """
    model = pf.ARIMA(data=data, ar=1, ma=1, family=pf.Laplace())
    x = model.fit('BBVI', iterations=100, mini_batch=32, record_elbo=True)
    assert (x.elbo_records[-1] > x.elbo_records[0])
예제 #4
0
def test_laplace_predict_is_length():
    """
	Tests that the prediction IS dataframe length is equal to the number of steps h
	"""
    model = pf.GAS(data=data, ar=2, sc=2, family=pf.Laplace())
    x = model.fit()
    assert (model.predict_is(h=5).shape[0] == 5)
예제 #5
0
def test_laplace_bbvi_elbo():
    """
    Tests that the ELBO increases
    """
    model = pf.GAS(data=data, ar=1, sc=1, family=pf.Laplace())
    x = model.fit('BBVI', iterations=100, record_elbo=True, map_start=False)
    assert (x.elbo_records[-1] > x.elbo_records[0])
예제 #6
0
def test2_bbvi_mini_batch_elbo():
    """
    Tests that the ELBO increases
    """
    model = pf.GASX(formula="y ~ x1 + x2", data=data, ar=1, sc=1, family=pf.Laplace())
    x = model.fit('BBVI',iterations=500, mini_batch=32, record_elbo=True, map_start=False)
    assert(x.elbo_records[-1]>x.elbo_records[0])
예제 #7
0
def test_predict_length():
    """
    Tests that the prediction dataframe length is equal to the number of steps h
    """
    model = pf.ARIMA(data=data, ar=2, ma=2, family=pf.Laplace())
    x = model.fit()
    assert (model.predict(h=5).shape[0] == 5)
예제 #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)
예제 #9
0
def atest_normal_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.Laplace())
    x = model.fit()
    x.summary()
    assert(model.predict(h=5, oos_data=data_oos).shape[0] == 5)
def test_laplace_predict_length():
    """
	Tests that the prediction dataframe length is equal to the number of steps h
	"""
    model = pf.GASLLT(data=data, family=pf.Laplace())
    x = model.fit()
    x.summary()
    assert (model.predict(h=5).shape[0] == 5)
예제 #11
0
def test_ppc():
    """
    Tests PPC value
    """
    model = pf.ARIMA(data=data, ar=2, ma=2, family=pf.Laplace())
    x = model.fit('BBVI', iterations=100)
    p_value = model.ppc()
    assert (0.0 <= p_value <= 1.0)
예제 #12
0
def atest2_normal_predict_is_nans():
    """
    Tests that the predictions in-sample are not NaNs
    """
    model = pf.GASReg(formula="y ~ x1 + x2", 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)
예제 #13
0
def test2_ppc():
    """
    Tests PPC value
    """
    model = pf.GASX(formula="y ~ x1 + x2", data=data, ar=1, sc=1, family=pf.Laplace())
    x = model.fit('BBVI', iterations=100)
    p_value = model.ppc()
    assert(0.0 <= p_value <= 1.0)
예제 #14
0
def test_laplace_ppc():
    """
    Tests PPC value
    """
    model = pf.GAS(data=data, ar=1, sc=1, family=pf.Laplace())
    x = model.fit('BBVI', iterations=100)
    p_value = model.ppc()
    assert (0.0 <= p_value <= 1.0)
예제 #15
0
def test_predict_nans():
    """
    Tests that the predictions are not nans
    """
    model = pf.ARIMA(data=data, ar=2, ma=2, family=pf.Laplace())
    x = model.fit()
    assert (len(
        model.predict(h=5).values[np.isnan(model.predict(h=5).values)]) == 0)
예제 #16
0
def test2_sample_model():
    """
    Tests sampling function
    """
    model = pf.GASX(formula="y ~ x1 + x2", data=data, ar=1, sc=1, family=pf.Laplace())
    x = model.fit('BBVI', iterations=100)
    sample = model.sample(nsims=100)
    assert(sample.shape[0]==100)
    assert(sample.shape[1]==len(data)-1)
예제 #17
0
def test_predict_is_nonconstant():
    """
    We should not really have predictions that are constant (should be some difference)...
    This captures bugs with the predict function not iterating forward
    """
    model = pf.ARIMA(data=data, ar=2, ma=2, family=pf.Laplace())
    x = model.fit()
    predictions = model.predict_is(h=10, intervals=False)
    assert (not np.all(predictions.values == predictions.values[0]))
예제 #18
0
def test_predict_nonconstant():
    """
    We should not really have predictions that are constant (should be some difference)...
    This captures bugs with the predict function not iterating forward
    """
    model = pf.GASX(formula="y ~ x1", data=data, ar=1, sc=1, family=pf.Laplace())
    x = model.fit()
    predictions = model.predict(h=10, oos_data=data_oos, intervals=False)
    assert(not np.all(predictions.values==predictions.values[0]))
def test_laplace_sample_model():
    """
    Tests sampling function
    """
    model = pf.GASLLT(data=data, family=pf.Laplace())
    x = model.fit('BBVI', iterations=100)
    sample = model.sample(nsims=100)
    assert (sample.shape[0] == 100)
    assert (sample.shape[1] == len(data) - 1)
예제 #20
0
def test_laplace_predict_nans():
    """
	Tests that the predictions are not nans
	"""
    model = pf.GAS(data=data, ar=2, sc=2, family=pf.Laplace())
    x = model.fit()
    x.summary()
    assert (len(
        model.predict(h=5).values[np.isnan(model.predict(h=5).values)]) == 0)
예제 #21
0
def atest_normal_predict_nans():
    """
    Tests that the predictions are not NaNs
    """
    model = pf.GASReg(formula="y ~ x1", 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)
예제 #22
0
def atest_sample_model():
    """
    Tests sampling function
    """
    model = pf.GASReg(formula="y ~ x1", data=data, family=pf.Laplace())
    x = model.fit('BBVI', iterations=100)
    sample = model.sample(nsims=100)
    assert(sample.shape[0]==100)
    assert(sample.shape[1]==len(data))
예제 #23
0
def atest_normal_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.Laplace())
    x = model.fit('PML')
    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)
예제 #24
0
def test2_pml():
    """
    Tests an GASX model estimated with PML, with multiple predictors, and 
    tests that the latent variable vector length is correct, and that value are not nan
    """
    model = pf.GASX(formula="y ~ x1 + x2", data=data, ar=1, sc=1, family=pf.Laplace())
    x = model.fit('PML')
    assert(len(model.latent_variables.z_list) == 6)
    lvs = np.array([i.value for i in model.latent_variables.z_list])
    assert(len(lvs[np.isnan(lvs)]) == 0)
예제 #25
0
def test_mh():
    """
    Tests an GASX model estimated with Metropolis-Hastings, and tests that the latent variable
    vector length is correct, and that value are not nan
    """
    model = pf.GASX(formula="y ~ x1", data=data, ar=1, sc=1, family=pf.Laplace())
    x = model.fit('M-H',nsims=300)
    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)
예제 #26
0
def test_laplace_mh():
    """
	Tests an GAS model estimated with Metropolis-Hastings and that the length of the 
	latent variable list is correct, and that the estimated latent variables are not nan
	"""
    model = pf.GAS(data=data, ar=1, sc=1, family=pf.Laplace())
    x = model.fit('M-H', nsims=300)
    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)
예제 #27
0
def test_laplace_bbvi():
    """
	Tests an GAS 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.GAS(data=data, ar=1, sc=1, family=pf.Laplace())
    x = model.fit('BBVI', iterations=100)
    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)
예제 #28
0
def test_bbvi():
    """
    Tests an GASX model estimated with BBVI, and tests that the latent variable
    vector length is correct, and that value are not nan
    """
    model = pf.GASX(formula="y ~ x1", data=data, ar=1, sc=1, family=pf.Laplace())
    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)
예제 #29
0
def test_bbvi_mini_batch():
    """
    Tests an GASX 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.GASX(formula="y ~ x1", data=data, ar=1, sc=1, family=pf.Laplace())
    x = model.fit('BBVI',iterations=500, mini_batch=32)
    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)
예제 #30
0
def test_laplace_pml():
    """
	Tests a PML model estimated with Laplace approximation and that the length of the 
	latent variable list is correct, and that the estimated latent variables are not nan
	"""
    model = pf.GAS(data=data, ar=1, sc=1, family=pf.Laplace())
    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)