您当前的位置: 首页 >  pytorch

段智华

暂无认证

  • 0浏览

    0关注

    1232博文

    0收益

  • 0浏览

    0点赞

    0打赏

    0留言

私信
关注
热门博文

Pytorch LSTM 时间序列预测

段智华 发布时间:2018-11-25 15:16:50 ,浏览量:0

Pytorch  LSTM 时间序列预测

https://github.com/pytorch/examples/blob/master/time_sequence_prediction/generate_sine_wave.py

Pytorch官网提供初学者入门的一个例子,有助于学习Pytorch时间序列预测。本例中使用两个LSTMCell单元学习从不同相位开始的一些正弦波信号,LSTM网络在学习了正弦波之后,试图预测未来的信号值。

generate_sine_wave.py生成模拟数据:

# -*- coding: utf-8 -*-

import numpy as np
import torch

np.random.seed(2)

T = 20
L = 1000
N = 100

x = np.empty((N, L), 'int64')

x[:] = np.array(range(L)) + np.random.randint(-4 * T, 4 * T, N).reshape(N, 1)
data = np.sin(x / 1.0 / T).astype('float64')
torch.save(data, open('traindata.pt', 'wb'))

LSTM数据序列预测:

# -*- coding: utf-8 -*-
from __future__ import print_function
import torch
import torch.nn as nn
import torch.optim as optim
import numpy a
关注
打赏
1659361485
查看更多评论
立即登录/注册

微信扫码登录

0.0433s