PYMC需水量预测

时间:2016-04-06 18:54:32

标签: python-3.x numpy matplotlib bayesian pymc

我正在制定一个考虑时间和气象条件的水需求预测模型。我是新手,并努力生成预测数组。理想情况下,它会考虑前几年的用水需求+气象条件+时间,然后利用当前时间和气象条件来生成需求预测。

这是我的代码,显示的图表对预测没有多大意义

import pymc as pm
import scipy
from scipy import stats, signal
import pandas as pd
import numpy as np
from pymc import Normal, Dirichlet, Categorical, Gamma, deterministic, MCMC, Matplot, Poisson, graph, Exponential, DiscreteUniform
import matplotlib.pyplot as plt

#load data into the code
value_array2013=np.loadtxt('C:\\Users\\User\\Desktop\\Data 4 python\\2013 Effluent flow Value.csv', delimiter=',')
value_array2014=np.loadtxt('C:\\Users\\User\\Desktop\\Data 4 python\\2014 Effluent flow Value.csv', delimiter=',')
time_array2013=np.loadtxt('C:\\Users\\User\\Desktop\\Data 4 python\\Time 2013.csv', delimiter=',')
time_array2014=np.loadtxt('C:\\Users\\User\\Desktop\\Data 4 python\\Time 2014.csv', delimiter=',')
hourly=np.loadtxt('C:\\Users\\User\\Desktop\\Data 4 python\\24hr time 2014.csv', delimiter=',')
dtemp2014=np.loadtxt('C:\\Users\\User\\Desktop\\Data 4 python\\corrected temp K.csv', delimiter=',')

#make prior distirbution
n=np.random.normal(size=len(time_array2014))

#make likelihood(tau)--> uninformed
tau=pm.Gamma('tau',alpha=0.1, beta=0.1)

#max temp and max time
j=305.3
h=365

#making demand equation that uses the previous value and %change in time and temp
demandd=np.zeros(len(time_array2014))
for i in range(0,len(time_array2014)):
    demandd[i]=demandd[i-1]+demandd[i-1]*((dtemp2014[i]-dtemp2014[i-1])/j)+demandd[i-1]*((time_array2014[i]-time_array2014[i-1])/h)

#demand + random variable will give actual demand
y=demandd+n

#observed variable to test y against
@pm.observed
@pm.stochastic(plot=False)
def demand (value=value_array2014,mu=y,tau=n):
    return pm.lognormal_like(value,mu,tau)

#specify the model
model=pm.Model({'y':y,'tau':tau,'n':n})

#instantiate MCMC
mcmc=pm.MCMC(model)
mcmc.sample(iter=10000, burn=1000)


#forecast
plt.scatter(time_array2014,y)
plt.show()

任何帮助将不胜感激!

0 个答案:

没有答案