def test_sample_model():
    """
    Tests sampling function
    """
    model = pf.GASLLEV(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) - 1)
예제 #2
0
def test_poisson_predict_nans():
    """
	Tests that the predictions are not nans
	"""
    model = pf.GASLLEV(data=countdata, family=pf.GASPoisson())
    x = model.fit()
    x.summary()
    assert (len(
        model.predict(h=5).values[np.isnan(model.predict(h=5).values)]) == 0)
def test_skewt_couple_terms_integ():
    """
	Tests latent variable list length is correct, and that the estimated
	latent variables are not nan
	"""
    model = pf.GASLLEV(data=data, integ=1, family=pf.Skewt())
    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)
def test_skewt_predict_nans():
    """
	Tests that the predictions are not nans
	model = pf.GASLLEV(data=data, family=pf.Skewt())
	"""
    model = pf.GASLLEV(data=data, family=pf.Skewt())
    x = model.fit()
    x.summary()
    assert (len(
        model.predict(h=5).values[np.isnan(model.predict(h=5).values)]) == 0)
def test_skewt_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.GASLLEV(data=data, family=pf.Skewt())
    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)
def test_skewt_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.GASLLEV(data=data, family=pf.Skewt())
    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)
예제 #7
0
def test_t_predict_is_nans():
    """
    Tests that the in-sample predictions are not nans
    """
    model = pf.GASLLEV(data=data, family=pf.t())
    x = model.fit()
    x.summary()
    assert (len(
        model.predict_is(h=5).values[np.isnan(
            model.predict_is(h=5).values)]) == 0)
예제 #8
0
def test_poisson_laplace():
    """
	Tests an GAS 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.GASLLEV(data=countdata, family=pf.GASPoisson())
    x = model.fit('Laplace')
    assert (len(model.latent_variables.z_list) == 1)
    lvs = np.array([i.value for i in model.latent_variables.z_list])
    assert (len(lvs[np.isnan(lvs)]) == 0)
예제 #9
0
def test_poisson_couple_terms():
    """
	Tests latent variable list length is correct, and that the estimated
	latent variables are not nan
	"""
    model = pf.GASLLEV(data=countdata, family=pf.GASPoisson())
    x = model.fit()
    assert (len(model.latent_variables.z_list) == 1)
    lvs = np.array([i.value for i in model.latent_variables.z_list])
    assert (len(lvs[np.isnan(lvs)]) == 0)
예제 #10
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.GASLLEV(data=data, family=pf.GASLaplace())
    x = model.fit('BBVI', iterations=100)
    assert (len(model.latent_variables.z_list) == 2)
    lvs = np.array([i.value for i in model.latent_variables.z_list])
    assert (len(lvs[np.isnan(lvs)]) == 0)
def test_skewt_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.GASLLEV(data=data, family=pf.Skewt())
    x = model.fit('BBVI', iterations=100, mini_batch=32)
    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)
예제 #12
0
def test_t_bbvi_mini_batch_elbo():
    """
    Tests that the ELBO increases
    """
    model = pf.GASLLEV(data=data, family=pf.t())
    x = model.fit('BBVI',
                  iterations=100,
                  mini_batch=32,
                  record_elbo=True,
                  map_start=False)
    assert (x.elbo_records[-1] > x.elbo_records[0])
예제 #13
0
def test_t_couple_terms_integ():
    """
    Tests an GAS model with 1 AR and 1 MA term, integrated once, and that
    the latent variable list length is correct, and that the estimated
    latent variables are not nan
    """
    model = pf.GASLLEV(data=data, integ=1, family=pf.t())
    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)
def test_predict_is_intervals_bbvi():
    """
    Tests prediction intervals are ordered correctly
    """
    model = pf.GASLLEV(data=data, family=pf.Normal())
    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))
예제 #15
0
def test_t_predict_is_intervals_mh():
    """
    Tests prediction intervals are ordered correctly
    """
    model = pf.GASLLEV(data=data, family=pf.t())
    x = model.fit('M-H', nsims=400)
    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))
예제 #16
0
def test_poisson_predict_is_intervals():
    """
    Tests prediction intervals are ordered correctly
    """
    model = pf.GASLLEV(data=data, family=pf.Poisson())
    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))
예제 #17
0
def build_model(data, ar=2, sc=4, family=pf.families.Poisson, target=None):
    model = pf.GASLLEV(data=data, family=family(), target=target)
    return model
예제 #18
0
#print cpu_data
fig2 = plt.figure(figsize=(15, 5))
plt.plot(date, tempf, 'r-', linewidth=2)
plt.xlabel("Timestamp")
plt.ylabel("Filtered CPU Usage (%)")
plt.legend(['Filtered'])
plt.title("Filtered CPU usage")
plt.show()

cpu_data = tempf
print "start ensemble"
model1 = pf.ARIMA(data=cpu_data, ar=4, ma=0)
model2 = pf.ARIMA(data=cpu_data, ar=8, ma=0)
model3 = pf.LLEV(data=cpu_data)
#model4 = pf.GASLLEV(data=cpu_data, family=pf.GASt())
model4 = pf.GASLLEV(data=cpu_data, family=pf.Poisson())
model5 = pf.GPNARX(data=cpu_data, ar=1, kernel=pf.SquaredExponential())
model6 = pf.GPNARX(data=cpu_data, ar=2, kernel=pf.SquaredExponential())
model7 = pf.DynReg('CPUusage', data=dataframe)

mix = pf.Aggregate(learning_rate=1.0, loss_type='squared')
mix.add_model(model1)
mix.add_model(model2)
mix.add_model(model3)
#mix.add_model(model4)
#mix.add_model(model5)
#mix.add_model(model6)
mix.add_model(model7)

mix.tune_learning_rate(20)
print mix.learning_rate