① lstm做交通预测的输入输出是什么样的
间序列预测分析就是利用过去一段时间内某事件时间的特征来预测未来一段时间内该事件的特征。这是一类相对比较复杂的预测建模问题,和回归分析模型的预测不同,时间序列模型是依赖于事件发生的先后顺序的,同样大小的值改变顺序后输入模型产生的结果是不同的。
举个栗子:根据过去两年某股票的每天的股价数据推测之后一周的股价变化;根据过去2年某店铺每周想消费人数预测下周来店消费的人数等等
RNN 和 LSTM 模型
时间序列模型最常用最强大的的工具就是递归神经网络(recurrent neural network, RNN)。相比与普通神经网络的各计算结果之间相互独立的特点,RNN的每一次隐含层的计算结果都与当前输入以及上一次的隐含层结果相关。通过这种方法,RNN的计算结果便具备了记忆之前几次结果的特点。
典型的RNN网路结构如下:
② Istm比rnn多了什么模块
多了一个蓝牙模块!!
③ 为什么说gru和lstm可以解决传统rnn梯度消失的问题
在向量微积分中,标量场的梯度是一个向量场。标量场中某一点上的梯度指向标量场增长最快的方向,梯度的长度是这个最大的变化率。更严格的说,从欧几里得空间Rn到R的函数的梯度是在Rn某一点最佳的线性近似。在这个意义上,梯度是雅可比矩阵的一个特殊情况。
④ 如何用Tensorflow实现RNN
class TextLoader():
def __init__(self, data_dir, batch_size, seq_length, encoding='utf-8'):
self.data_dir = data_dir
self.batch_size = batch_size
self.seq_length = seq_length
self.encoding = encoding
#第一次运行程序时只有input.txt一个文件,剩下两个文件是运行之后产生的
input_file = os.path.join(data_dir, "input.txt")
vocab_file = os.path.join(data_dir, "vocab.pkl")
tensor_file = os.path.join(data_dir, "data.npy")
#如果是第一次执行则调用preprocess函数,否则调用load_preprocessed函数。
if not (os.path.exists(vocab_file) and os.path.exists(tensor_file)):
print("reading text file")
self.preprocess(input_file, vocab_file, tensor_file)
else:
print("loading preprocessed files")
self.load_preprocessed(vocab_file, tensor_file)
self.create_batches()
self.reset_batch_pointer()
def preprocess(self, input_file, vocab_file, tensor_file):
with codecs.open(input_file, "r", encoding=self.encoding) as f:
data = f.read()
#使用Counter函数对输入数据进行统计。counter保存data中每个字符出现的次数
counter = collections.Counter(data)
#对counter进行排序,出现次数最多的排在前面
count_pairs = sorted(counter.items(), key=lambda x: -x[1])
#将data中出现的所有字符保存,这里有65个,所以voacb_size=65
self.chars, _ = zip(*count_pairs)
self.vocab_size = len(self.chars)
#按照字符出现次数多少顺序将chars保存,vocab中存储的是char和顺序,这样方便将data转化为索引
self.vocab = dict(zip(self.chars, range(len(self.chars))))
with open(vocab_file, 'wb') as f:
#保存chars
cPickle.mp(self.chars, f)
#将data中每个字符转化为索引下标。
self.tensor = np.array(list(map(self.vocab.get, data)))
np.save(tensor_file, self.tensor)
def load_preprocessed(self, vocab_file, tensor_file):
#如果是第二次运行,则可以直接读取之前保存的chars和tensor
with open(vocab_file, 'rb') as f:
self.chars = cPickle.load(f)
self.vocab_size = len(self.chars)
self.vocab = dict(zip(self.chars, range(len(self.chars))))
self.tensor = np.load(tensor_file)
self.num_batches = int(self.tensor.size / (self.batch_size *
self.seq_length))
def create_batches(self):
#首先将数据按batch_size切割,然后每个batch_size在按照seq_length进行切割
self.num_batches = int(self.tensor.size / (self.batch_size *
self.seq_length))
if self.num_batches == 0:
assert False, "Not enough data. Make seq_length and batch_size small."
self.tensor = self.tensor[:self.num_batches * self.batch_size * self.seq_length]
xdata = self.tensor
#构造target,这里使用上一个词预测下一个词,所以直接将x向后一个字符即可
ydata = np.(self.tensor)
ydata[:-1] = xdata[1:]
ydata[-1] = xdata[0]
#将数据进行切分,这里我们假设数据总长度为10000,batch_size为100, seq_length为10.
# 所以num_batches=10,所以,xdata在reshape之后变成[100, 100],然后在第二个维度上切成10份,
# 所以最终得到[100, 10, 10]的数据
self.x_batches = np.split(xdata.reshape(self.batch_size, -1),
self.num_batches, 1)
self.y_batches = np.split(ydata.reshape(self.batch_size, -1),
self.num_batches, 1)
def next_batch(self):
x, y = self.x_batches[self.pointer], self.y_batches[self.pointer]
self.pointer += 1
return x, y
def reset_batch_pointer(self):
self.pointer = 0
⑤ 只有一层隐藏层的CNN(RNN)算是深度学习吗
都可以,这个现在没有特别明晰的界限和定义,不必过分关心.
个人觉得用层数来界定深还是浅有点low, 深度学习与传统机器学习的最大区别是在于它的弹性,它的层数和结构可以非常方便的的延伸和拓展.
⑥ 实际波动率的概念
要明确实际波动率,首先要从波动率的概念入手。波动率(Volatility):是指关于资产未来价格不确定性的度量。它通常用资产回报率的标准差来衡量。也可以指某一证券的一年最高价减去最低价的值再除以最低价所得到的比率。业内将波动率定义为价格比率自然对数的标准差。波动率的种类有:实际波动率,隐含波动率,历史波动率等等,实际波动率便是波动率的一种。