我正在尝试使用Theano找到here
来解决GPU上解决SDE的问题我遇到了GpuDimShuffle错误,但我没看到任何一个dims不匹配......
import theano
import theano.tensor as T
from theano.tensor.shared_randomstreams import RandomStreams
import numpy as np
import matplotlib.pyplot as plt
import time
#define the ode function
#dc/dt = f(c, lambda)
#c is a vector with n components
def evolve(c, n, k, l):
return T.pow(c, n)/(T.pow(c, n)+T.pow(k,n)) - l*c
def euler(c, n, k, l, dt):
return T.cast(c + dt*evolve(c, n, k, l) + T.sqrt(dt)*c*rv_n, 'float32')
def rk4(c, n, k, l, dt):
'''
Adapted from
http://people.sc.fsu.edu/~jburkardt/c_src/stochastic_rk/stochastic_rk.html
'''
a21 = 2.71644396264860
a31 = - 6.95653259006152
a32 = 0.78313689457981
a41 = 0.0
a42 = 0.48257353309214
a43 = 0.26171080165848
a51 = 0.47012396888046
a52 = 0.36597075368373
a53 = 0.08906615686702
a54 = 0.07483912056879
q1 = 2.12709852335625
q2 = 2.73245878238737
q3 = 11.22760917474960
q4 = 13.36199560336697
x1 = c
k1 = dt * evolve(x1, n, k, l) + T.sqrt(dt) * c * rv_n
x2 = x1 + a21 * k1
k2 = dt * evolve(x2, n, k, l) + T.sqrt(dt) * c * rv_n
x3 = x1 + a31 * k1 + a32 * k2
k3 = dt * evolve(x3, n, k, l) + T.sqrt(dt) * c * rv_n
x4 = x1 + a41 * k1 + a42 * k2
k4 = dt * evolve(x4, n, k, l) + T.sqrt(dt) * c * rv_n
return T.cast(x1 + a51 * k1 + a52 * k2 + a53 * k3 + a54 * k4, 'float32')
#random
srng = RandomStreams(seed=31415)
#define symbolic variables
dt = T.fscalar("dt")
k = T.fscalar("k")
l = T.fscalar("l")
n = T.fscalar("n")
c = T.fvector("c")
#define numeric variables
num_samples = 50000
c0 = theano.shared(0.5*np.ones(num_samples, dtype='float32'))
n0 = 6
k0 = 0.5
l0 = 1/(1+np.power(k0, n0))
dt0 = 0.1
total_time = 8
total_steps = int(total_time/dt0)
rv_n = srng.normal(c.shape, std=0.05) #is a shared variable
#create loop
#first symbolic loop with everything
(cout, updates) = theano.scan(fn=rk4,
outputs_info=[c], #output shape
non_sequences=[n, k, l, dt], #fixed parameters
n_steps=total_steps)
#compile it
sim = theano.function(inputs=[n, k, l, dt],givens={c:c0}, outputs=cout,updates=updates,allow_input_downcast=True)
产量:
TypeError:('编译节点时发生以下错误',Rebroadcast {0(GpuDimShuffle {x,0} .0),'\ n','super(type,obj):obj必须是实例或者类型')的子类型
我在Theano 0.6.0
答案 0 :(得分:1)
如果您更新到开发版本,它对我有用:
http://www.deeplearning.net/software/theano/install.html#bleeding-edge-install-instructions
我们尽量保持开发版本非常稳定,并且我建议每个人都使用它,因为它自上一版本以来包含许多修复。
如果没有修复它,则错误特定于您的操作系统或python版本。我们需要更多有关它的信息。还始终使用回溯提供完整的错误消息。这提供了更多的调试信息。