如何使用向量列表作为theano函数的输入?

时间:2018-11-12 13:29:35

标签: python python-3.x theano theano.scan

我想定义一个theano.scan函数,将不同大小的向量列表作为输入。最好的方法是什么?

如果我像下面的示例那样执行愚蠢的实现,则会收到有关时间索引的错误:

import theano
import theano.tensor as T
import numpy as np

def step(time): # compute the average time step of a time grid
   dt=time[1:] - time[:-1]
   return T.mean(dt)

time_list=T.vector('time_list')
results, updates=theano.scan(fn=step, sequences=[time_list])

f=theano.function(inputs=[time_list], outputs=[results], updates=updates)

time_grid_1 = np.array([0, 100, 1100, 2100, 5100])  
time_grid_2 = np.array([0, 200, 1200, 2200]) 
time_grid_3 = np.array([0, 300, 1300, 2300, 3300, 4300]) 
time_grids = [time_grid_1 , time_grid_2 , time_grid_3 ]

我理解为什么会出错:这是因为time_list被声明为简单的1D向量。因此,其元素为标量,因此尝试计算dt = time [1:]-time [:-1]没有任何意义。

因此,我想将time_list定义为矢量的theano列表,我在文档中找不到该列表。

0 个答案:

没有答案