2016-11-03 2 views
0

Theano는 인덱스 할당을 지원하지 않습니다. 좋아,하지만이theano 텐서 변수의 단일 요소에 대한 인덱스 할당 값

theano.tensor.set_subtensor(x,y) 

이고 그것을 당신이 [5] B = 또는 [5] + = B 그런 짓을하려는 경우, theano.tensor를 참조 stated

것입니다. 아래 set_subtensor() 및 theano.tensor.inc_subtensor()를 참조하십시오.

따라서 set_subtensor는 인덱스 할당 작업을 시뮬레이트합니까? 글쎄. set_subtensor는 다음 예제와 같이 ndims가 < 인 경우 예상대로 작동하는 것 같습니다.

>>> a = theano.tensor.zeros(10) 
>>> a.eval() 
array([ 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.], dtype=float32) 
>>> aa = theano.tensor.set_subtensor(a[5], 5.0) 
>>> aa.eval() 
array([ 0., 0., 0., 0., 0., 5., 0., 0., 0., 0.], dtype=float32) 

멋진, a.shape == aa.shape하는 [5] = 5.0의 다음 더 어두워로 해보자 복제 할 = AA를 설정할 수 있습니다. set_subtensor 대상 인덱스에 지정된 값을 할당 한 동안

>>> b = theano.tensor.zeros((5,5)) 
>>> b.eval() 
array([[ 0., 0., 0., 0., 0.], 
     [ 0., 0., 0., 0., 0.], 
     [ 0., 0., 0., 0., 0.], 
     [ 0., 0., 0., 0., 0.], 
     [ 0., 0., 0., 0., 0.]], dtype=float32) 
>>> bb = theano.tensor.set_subtensor(b[2][2], 5.0) 
>>> bb.eval() 
array([ 0., 0., 5., 0., 0.], dtype=float32) 
>>> bb.shape.eval() 
array([5]) 

, 그것은 업데이트 된 값으로 전체 업데이트 텐서 변수 있었으나 결국 subtensor를 반환하지 않습니다.

ndims> = 2 인 theano tensors의 단일 요소에 인덱스 값을 할당하는 방법을 아는 사람이 있습니까?

답변

0

알아낼 수있었습니다. ndims> = 2 인 텐서의 단일 요소에 값을 인덱스 할당하려면 딤섬 위로 업데이트 된 값으로 서브 센서를 재귀 적으로 설정해야합니다. 예를 들면 : ndims와

>>> b = theano.tensor.zeros((5,5)) 
>>> b.eval() 
array([[ 0., 0., 0., 0., 0.], 
     [ 0., 0., 0., 0., 0.], 
     [ 0., 0., 0., 0., 0.], 
     [ 0., 0., 0., 0., 0.], 
     [ 0., 0., 0., 0., 0.]], dtype=float32) 
>>> bb = theano.tensor.set_subtensor(b[2][2], 5.0) 
>>> bb.eval() 
array([ 0., 0., 5., 0., 0.], dtype=float32) 
>>> b = theano.tensor.set_subtensor(b[2], bb) 
>>> b.eval() 
array([[ 0., 0., 0., 0., 0.], 
     [ 0., 0., 0., 0., 0.], 
     [ 0., 0., 5., 0., 0.], 
     [ 0., 0., 0., 0., 0.], 
     [ 0., 0., 0., 0., 0.]], dtype=float32) 

=

>>> c = theano.tensor.zeros((2,2,2)) 
>>> c.eval() 
array([[[ 0., 0.], 
     [ 0., 0.]], 

     [[ 0., 0.], 
     [ 0., 0.]]], dtype=float32) 
>>> ccc = theano.tensor.set_subtensor(c[0][0][0], 5.0) 
>>> ccc.eval() 
array([ 5., 0.], dtype=float32) 
>>> cc = theano.tensor.set_subtensor(c[0][0], ccc) 
>>> cc.eval() 
array([[ 5., 0.], 
     [ 0., 0.]], dtype=float32) 
>>> c = theano.tensor.set_subtensor(c[0], cc) 
>>> c.eval() 
array([[[ 5., 0.], 
     [ 0., 0.]], 

     [[ 0., 0.], 
     [ 0., 0.]]], dtype=float32) 

3 어쩌면 인덱스 할당에 간단/빠른 방법이있다, 그러나 이것은 내가 찾은 것입니다.