import torch
from torch import nn
import numpy as np
import matplotlib as mat
mat.use("TkAgg")
import matplotlib.pyplot as plt
import time
from torch.autograd import Variable
import cv2
torch.manual_seed(1) # reproducible
LR = 0.02 # learning rate
class LSNN(nn.Module):
def __init__(self):
super(LSNN, self).__init__()
self.lstm = nn.LSTM(
input_size=2,
hidden_size=32, # rnn hidden unit
num_layers=1, # 有几层 RNN layers
batch_first=True, # input & output 会是以 batch size 为第一维度的特征集 e.g. (batch, time_step, input_size)
)
self.hidden = (torch.autograd.Variable(torch.zeros(1, 1, 32)),torch.autograd.Variable(torch.zeros(1, 1, 32)))#1表示隐藏层数目,1表示批数目,32表示隐藏层size,lstm有两个状态矩阵
self.out = nn.Linear(32, 1)
def forward(self,x):
# x (batch_size, time_step, input_size)(批量,[值1,值2],输入层数目)
#
用sin预测cos
最新推荐文章于 2022-04-11 19:46:41 发布