1. 问题描述
-
已知 [k, k+n)时刻的正弦函数,预测 [k+t, k+n+t)时刻的正弦曲线。
-
因为每个时刻曲线上的点是一个值,即feature_len=1
-
如果给出50个时刻的点,即seq_len=50
-
如果只提供一条曲线供输入,即batch=1
-
输入的shape=[seq_len, batch, feature_len] = [50, 1, 1]。
2. 代码实现
import torch
import torch.nn as nn
import numpy as np
import torch.optim as optim
from matplotlib import pyplot as plt
input_size = 1
batch_size = 1
hidden_size = 16
num_layers = 1
output_size = 1
class Net(nn.Module):
def __init__(self):
super().__init__()
self.rnn = nn.RNN(
input_size=input_size,