Giter Site home page Giter Site logo

demand_forecast's Introduction

Deep Demand Forecast Models

Pytorch Implementation of DeepAR, MQ-RNN, Deep Factor Models, LSTNet, and TPA-LSTM. Furthermore, combine all these model to deep demand forecast model API.

Requirements

Please install Pytorch before run it, and

pip install -r requirements.txt

Run tests

# DeepAR
python deepar.py -e 100 -spe 3 -nl 1 -l g -not 168 -sp -rt -es 10 -hs 50  -sl 60 -ms

# MQ-RNN
python mq_rnn.py -e 100 -spe 3 -nl 1 -sp -sl 72 -not 168 -rt -ehs 50 -dhs 20 -ss -es 10 -ms

# Deep Factors
python deep_factors.py -e 100 -spe 3 -rt -not 168 -sp -sl 168 -ms

# TPA-LSTM
python tpa_lstm.py -e 1000 -spe 1 -nl 1 -not 168 -sl 30 -sp -rt -max

DeepAR
alt text
MQ-RNN
alt text
Deep Factors
alt text
TPA-LSTM
alt text

Arguments

Arguments Details
-e number of episodes
-spe steps per episode
-sl sequence length
-not number of observations to train
-ms mean scaler on y
-max max scaler on y
-nl number of layers
-l likelihood to select, "g" or "nb"
-rt run test data
-sample_size sample size to sample after
training in deep factors/deepar, default 100

TO DO

  • Deep Factor Model
  • TPA-LSTM pytorch
  • LSTNet pytorch
  • Debug Uber Extreme forcaster
  • Modeling Extreme Events in TS
  • Intermittent Demand Forecasting
  • Model API

Demand Forecast Dataset Resources

Reference

demand_forecast's People

Contributors

jingw2 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

demand_forecast's Issues

tpa_lstm 问题

在运行 python tpa_lstm.py -e 1 -spe 3 -nl 3 -not 200 -sl 100 -sp -rt -max的时候
-not 200 -sl 100 训练集+测试集大于200的时候会无法运行
报错
RuntimeError: Calculated padded input size per channel: (99 x 24). Kernel size: (199 x 1). Kernel size can't be greater than actual input size
导入的date长度为600但是无法使用更多的数据进行训练,求解,谢谢你!。

DeepAR模型训练LSTM层输入有问题?

这里输入到lstm的样本inp维度是 (1,1,12)? 那相当于喂给lstm的步长就是1? 那这不就是一个全连接网络了吗,没有用到RNN的特性啊。是不是有哪里搞错了 。 我参数都是按照readme里面输入的
image

Consult and ask for help

Hello, jingw2:
I use matlab 2020 official deep learning example code (LSTM) to do time series data prediction, the result is that I have not learned the characteristics of the amplitude change of the original signal, but learned the quasi periodic characteristics, as shown in the figure:
overview picture
问题概貌
Details of the picture
问题细节
Is this pure signal data time series suitable for deep learning prediction?

     I  want to improve the prediction accuracy,For example, the prediction accuracy is increased from RMSE = 289 to RMSE = 220?Please give me your advice,thank you very much!

best wishes,
Mr.Wang

TPA-LSTM only one input feature

TPA-LSTM looks to only support one input feature. Would you like me to update it to enable multiple features? Seems important for a complete implementation unless I'm mistaken on the usage of your code.

关于高斯分布的负对数似然函数

negative_likelihood = torch.log(sigma + 1) + (z - mu) ** 2 / (2 * sigma ** 2) + 6
新人求教,高斯分布的负对数似然函数的计算公式中的6是怎么来的?sigma为什么要+1?谢谢

AttributeError: module 'util' has no attribute 'MaxScaler'

Traceback (most recent call last):
File "tpa_lstm.py", line 249, in
losses, mape_list = train(X, y, args)
File "tpa_lstm.py", line 134, in train
yscaler = util.MaxScaler()
AttributeError: module 'util' has no attribute 'MaxScaler'

intertiment issunes and fixes

replace like this

@staticmethod
    def multistage(X, y, forecast_period, num_sample_points=200):
        glm = multistage_glm.MultiStageGLM()
        Xtrain = X[:-forecast_period]
        ytrain = y
        Xtest = X[-forecast_period:]
        #######      ytest = y[-forecast_period:]
        print(Xtrain.shape,ytrain.shape)
        glm.fit(Xtrain, ytrain)
        yfit = glm.predict(Xtrain)
        ypred_list = []
        for _ in range(num_sample_points):
            ypred = glm.predict(Xtest)
            ypred_list.append(ypred.reshape((-1, 1)))
        ypred = np.concatenate(ypred_list, axis=1)
        
        p50 = np.quantile(ypred, 0.5, axis=1)
        p25 = np.quantile(ypred, 0.25, axis=1)
        p90 = np.quantile(ypred, 0.90, axis=1)

        return yfit, p50

tpa-lstm怎么处理变长的batch

楼主的代码中obs_len明确规定了每批次输入数据的长度是固定的,很多任务的时序数据为变长的,这时该怎么处理呢?由于长度为变长,卷积核的大小就无法固定,也就无法在 time step上 做卷积

quantile loss是不是错了?

针对MQRNN的问题:
相关代码:
image

ypred_rho - yf是不是应该改成yf - ypred_rho ?同时,按照quantile loss公式不应该是不同horizon先累加,然后平均么?我看你后面直接loss.mean了,相当于不同horizon也平均了。
还有一个问题,对于某一轮来说,如果采样一次就进行一次loss.backward(),那args.step_per_epoch 这个参数的意义何在?直接加大args.num_epoches的值不就好了?我在实现的过程中,发现如果不同args.step_per_epoch的loss做avg,然后整体进行一次loss.backward()效果也还可以。不知道你对这个怎么看?

DeepAR Xf在预测的时候怎么用

如果我没理解做的话,xf是test phase的X。我看你的实现里不区分原论文的zt和xt。zt是原始序列,如果把zt和xt合并起来,test phase时的zt就是target。 所以xf_test 里面有y_test, 实际上拿不到,也不能输入。请问怎么解决?或者如果我理解有误请指正。

The following error occurred when Run 'python deep_factors.py -e 100 -spe 3 -rt -not 168 -sp -sl 168 -ms',why ?

demand_forecast-master>python deep_factors.py -e 100 -spe 3 -rt -not 168 -sp -sl 168 -ms
Traceback (most recent call last):
File "C:\Anaconda\lib\site-packages\pandas\core\arrays\datetimelike.py", line 932, in _cmp_method
other = self._validate_comparison_value(other)
File "C:\Anaconda\lib\site-packages\pandas\core\arrays\datetimelike.py", line 451, in _validate_comparison_value
raise InvalidComparison(other)
pandas.core.arrays.datetimelike.InvalidComparison: 2014-01-01

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "deep_factors.py", line 259, in
data = data.loc[(data["date"] >= date(2014, 1, 1)) & (data["date"] <= date(2014, 3, 1))]
File "C:\Anaconda\lib\site-packages\pandas\core\ops\common.py", line 65, in new_method
return method(self, other)
File "C:\Anaconda\lib\site-packages\pandas\core\arraylike.py", line 49, in ge
return self._cmp_method(other, operator.ge)
File "C:\Anaconda\lib\site-packages\pandas\core\series.py", line 4948, in _cmp_method
res_values = ops.comparison_op(lvalues, rvalues, op)
File "C:\Anaconda\lib\site-packages\pandas\core\ops\array_ops.py", line 229, in comparison_op
res_values = op(lvalues, rvalues)
File "C:\Anaconda\lib\site-packages\pandas\core\ops\common.py", line 65, in new_method
return method(self, other)
File "C:\Anaconda\lib\site-packages\pandas\core\arraylike.py", line 49, in ge
return self._cmp_method(other, operator.ge)
File "C:\Anaconda\lib\site-packages\pandas\core\arrays\datetimelike.py", line 934, in _cmp_method
return invalid_comparison(self, other, op)
File "C:\Anaconda\lib\site-packages\pandas\core\ops\invalid.py", line 34, in invalid_comparison
raise TypeError(f"Invalid comparison between dtype={left.dtype} and {typ}")
TypeError: Invalid comparison between dtype=datetime64[ns] and date

(demand) F:\MsVsPython\ImportPytorchNet\jingw2-DeepAR\11\demand_forecast-master>

Help!

@QuanhanSun,你好!请问你是在windows还是linux环境下跑通这些程序的?

生成batch是有放回抽样的

您好,您代码里batch生成的方式是直接sample了一些样本,没有记录index,这样是不是没法保证所有样本都参与到训练中?另外每个epcho跑多少个batch怎么确定呢?

Forking-Sequence in MQ-RNN

Hi,

Very nice project!

针对MQ-RNN,论文在「3.3. Training Scheme」这个章节,提到了「Forking-Sequence」的训练方法,但是代码中好像并木有相关的体现。

因此,想请问下,这部分是在哪里实现的呢?或者 我有什么遗漏的地方吗?

AttributeError: module 'util' has no attribute 'batch_generator'

Traceback (most recent call last): |
File "tpa_lstm.py", line 249, in
losses, mape_list = train(X, y, args)
File "tpa_lstm.py", line 145, in train
Xtrain, ytrain, Xf, yf = util.batch_generator(Xtr, ytr, obs_len, seq_len, args.batch_size)
AttributeError: module 'util' has no attribute 'batch_generator'

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.