2014-05-13 4 views
2

Theano의 0, (?,), (1 ,?), (?,?) 모양과의 차이점은 무엇입니까? 제가Theano의 변수 모양의 차이점

arr = np.array([1,2,3]) 

정의 어레이 (3)의 어레이는 왜? 어떻게 (3,1) 배열을 정의 할 수 있습니까?

게다가, 나는 다음과 같이 코드를 작성 :

import theano.tensor as T 
from theano import shared 
import numpy as np 
from theano import function 


class hiddenLayer(): 
    """ Hidden Layer class 
    """ 
    def __init__(self, inputs, n_in, n_out, act_func): 
     rng = np.random 
     self.W = shared(np.asarray(rng.uniform(low=-4*np.sqrt(6./(n_in + n_out)), 
               high=4*np.sqrt(6./(n_in + n_out)), 
               size=(n_in, n_out)), 
            dtype=T.config.floatX), 
         name='W') 
     self.inputs = inputs 
     self.b = shared(np.zeros(n_out, dtype=T.config.floatX), name='b') 
     self.x = T.dvector('x') 
     self.z = T.dot(self.x, self.W) + self.b 
     self.ac = function([self.x], self.z) 

a = hiddenLayer(np.asarray([1, 2, 3], dtype=T.config.floatX), 3, 3, T.tanh) 
print a.ac(a.inputs, a.z) 

가 왜 오류보고!

'Expected an array-like object, but found a Variable: ' 
TypeError: ('Bad input argument to theano function at index 1(0-based)', 'Expected an array-like object, but found a Variable: maybe you are trying to call a function on a (possibly shared) variable instead of a numeric array?') 

매우 감사를

+1

정확히 같은 복제본은 아니지만 [관련 스레드의이 답변] (http://stackoverflow.com/a/22074424/1634191)에는'numpy.array' 모양의 차이점에 대한 설명이 있습니다. – wflynny

+0

왜 내가 (3) 배열을 theano.function에 전달하면 위와 같이 오류가 발생합니까? x는 모양이 (?,) 인 T.dvector로 정의되며, 내가 통과하는 것은 (3,) 배열입니다. 왜 그것이 배열과 같은 객체를 기대한다고 말했습니까? – BoscoTsang

답변

2

당신은 a.ac()a.z를 전달하는 데 노력하고있다, a.z은 실제로 결과입니다.a.ac(x)입니다. a.x, a.Wa.b 모든 평가 될 수있을 때까지

a.ac(a.inputs) 
# array([ 8.61379147, -13.0183053 , -4.41056323]) 

상징적 변수 a.z의 값은 미정이다 :

대신, 당신은 아마이 작업을 수행 할 수 있습니다. 이 같은 theano.function 작품의 구문은 :

find_x = theano.function([<inputs needed to compute x>], <output x>) 

실제로 find_x()를 호출 할

, 당신은 단지 대괄호에게 물건을 제공해야하고, theano.function에 두 번째 인수는 find_x()의 반환 값이됩니다.

+0

대단히 감사합니다! – BoscoTsang

관련 문제