2014-06-20 48 views
1

我想通過一個實例使用Theano解決基於GPU隨機微分方程到工作中發現hereTheano 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.47
    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) 

產量:

類型錯誤:( '在編譯節點發生以下錯誤',再次播送{0(GpuDimShuffle {X,0} 0.0), '\ n' ,'super(type,obj):obj必須是一個實例或類型的子類型')

我在Theano 0.6.0

回答

1

如果更新的開發版本,它爲我工作:

http://www.deeplearning.net/software/theano/install.html#bleeding-edge-install-instructions

我們儘量保持開發版本非常穩定,我每個人都電子書籍使用它,因爲它包含自上次發佈以來的許多修復程序。

如果不能解決這個問題,錯誤是特定於您的操作系統或python版本的。我們需要更多關於它的信息。還總是提供帶回溯的完整錯誤消息。這提供了更多的調試信息。