Exemplo n.º 1
0
def test_ou_predict_is_length():
    """
	Tests that the prediction IS dataframe length is equal to the number of steps h
	"""
    model = pf.GPNARX(data=data, ar=2, kernel=pf.OrnsteinUhlenbeck())
    x = model.fit()
    assert (model.predict_is(h=5).shape[0] == 5)
Exemplo n.º 2
0
def test_predict_is_length():
    """
	Tests that the prediction IS dataframe length is equal to the number of steps h
	"""
    model = pf.GPNARX(data=data, ar=2, kernel=pf.SquaredExponential())
    x = model.fit()
    assert (model.predict_is(h=5).shape[0] == 5)
Exemplo n.º 3
0
def test_per_predict_length():
    """
	Tests that the prediction dataframe length is equal to the number of steps h
	"""
    model = pf.GPNARX(data=data, ar=2, kernel=pf.Periodic())
    x = model.fit()
    x.summary()
    assert (model.predict(h=5).shape[0] == 5)
Exemplo n.º 4
0
def test_predict_nans():
    """
	Tests that the predictions are not nans
	"""
    model = pf.GPNARX(data=data, ar=2, kernel=pf.SquaredExponential())
    x = model.fit()
    x.summary()
    assert (len(
        model.predict(h=5).values[np.isnan(model.predict(h=5).values)]) == 0)
Exemplo n.º 5
0
def test_rq_predict_nans():
    """
	Tests that the predictions are not nans
	"""
    model = pf.GPNARX(data=data, ar=2, kernel=pf.RationalQuadratic())
    x = model.fit()
    x.summary()
    assert (len(
        model.predict(h=5).values[np.isnan(model.predict(h=5).values)]) == 0)
Exemplo n.º 6
0
def test_ou_predict_nans():
    """
	Tests that the predictions are not nans
	"""
    model = pf.GPNARX(data=data, ar=2, kernel=pf.OrnsteinUhlenbeck())
    x = model.fit()
    x.summary()
    assert (len(
        model.predict(h=5).values[np.isnan(model.predict(h=5).values)]) == 0)
Exemplo n.º 7
0
def test_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.GPNARX(data=data, ar=1, kernel=pf.SquaredExponential())
    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)
Exemplo n.º 8
0
def test_mh():
    """
	Tests an GPNARX 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.GPNARX(data=data, ar=1, kernel=pf.SquaredExponential())
    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)
Exemplo n.º 9
0
def test_per_predict_is_nans():
    """
	Tests that the in-sample predictions are not nans
	"""
    model = pf.GPNARX(data=data, ar=2, kernel=pf.Periodic())
    x = model.fit()
    x.summary()
    assert (len(
        model.predict_is(h=5).values[np.isnan(
            model.predict_is(h=5).values)]) == 0)
Exemplo n.º 10
0
def test_bbvi():
    """
	Tests an GPNARX 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.GPNARX(data=data, ar=1, kernel=pf.SquaredExponential())
    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)
Exemplo n.º 11
0
def test_per_couple_terms_integ():
    """
	Tests an GPNARX model with 1 AR term, integrated once, and that
	the latent variable list length is correct, and that the estimated
	latent variables are not nan
	"""
    model = pf.GPNARX(data=data, ar=1, integ=1, kernel=pf.Periodic())
    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)
Exemplo n.º 12
0
def test_rq_couple_terms():
    """
	Tests an GPNARX model with 1 AR term and that
	the latent variable list length is correct, and that the estimated
	latent variables are not nan
	"""
    model = pf.GPNARX(data=data, ar=1, kernel=pf.RationalQuadratic())
    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)
Exemplo n.º 13
0
         markersize=5,
         label=u'Observations')

# ================================================================================== #
# Building PyFLUX Gaussian Process Model

import pyflux as pf
from pyflux import GPNARX

#growthdata = pd.read_csv('http://www.pyflux.com/notebooks/GDPC1.csv')
#USgrowth = pd.DataFrame(np.diff(np.log(growthdata['VALUE']))[149:len(growthdata['VALUE'])])
#USgrowth.index = pd.to_datetime(growthdata['DATE'].values[1+149:len(growthdata)])
#USgrowth.columns = ['US Real GDP Growth']

plt.figure(1)
plt.subplot(511)
plt.plot(X[:, 0])
plt.subplot(512)
plt.plot(X[:, 1])
plt.subplot(513)
plt.plot(X[:, 2])
plt.subplot(514)
plt.plot(X[:, 3])
plt.subplot(515)
plt.plot(X[:, 4])

rng = pd.date_range('1/1/2018', periods=1000, freq='S')
train = pd.DataFrame(X[:, 0], index=rng, columns=['Values1'])
model = pf.GPNARX(train, ar=10, kernel=pf.SquaredExponential())
fit = model.fit()
fit.summary()
Exemplo n.º 14
0
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
Exemplo n.º 15
0
growthdata = pd.read_csv('http://www.pyflux.com/notebooks/GDPC1.csv')
USgrowth = pd.DataFrame(np.diff(np.log(growthdata['VALUE']))[149:len(growthdata['VALUE'])])
USgrowth.index = pd.to_datetime(growthdata['DATE'].values[1+149:len(growthdata)])
USgrowth.columns = ['US Real GDP Growth']
plt.figure(figsize=(15,5))
plt.plot(USgrowth)
plt.ylabel('Real GDP Growth')
plt.title('US Real GDP Growth');
plt.show()

model1 = pf.ARIMA(data=USgrowth, ar=4, ma=0)
model2 = pf.ARIMA(data=USgrowth, ar=8, ma=0)
model3 = pf.LLEV(data=USgrowth)
#model4 = pf.GASLLEV(data=USgrowth, family=pf.GASt())
model5 = pf.GPNARX(data=USgrowth, ar=1, kernel=pf.SquaredExponential())
model6 = pf.GPNARX(data=USgrowth, ar=2, kernel=pf.SquaredExponential())

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.tune_learning_rate(40)
mix.learning_rate

mix.plot_weights(h=40, figsize=(15,5))
mix.show()
Exemplo n.º 16
0
def build_model(data, ar=4, kernel=pf.SquaredExponential, target=None):
    model = pf.GPNARX(data=data, ar=ar, kernel=kernel())
    return model