2016-01-07 63 views
3

假设我有一个Theano符号x并运行以下代码。是否有身份识别功能?

x.name = "x" 
y = x 
y.name = "y" 

当然x.name的是那么"y"有没有一个身份识别功能,可以让我做下面的事情?

x.name = "x" 
y = T.identity(x) 
y.name = "y" 

预期的行为是y现在看到是x功能,并且它们都正确命名。当然Theano编译器会简单地合并这些符号,因为y只是x

的原因,我问这个是因为我有像以下,其中filterfeature是Theano符号和nonlinear或者是TrueFalse的情况。

activation = T.dot(feature, filter) 
activation.name = "activation" 
response = T.nnet.sigmoid(activation) if nonlinear else activation 
response.name = "response" 

的问题是,在nonlinearFalse的情况下,我activation符号将被命名为"response"

我可以解决该问题的解决这个问题:

activation = T.dot(feature, filter) 
activation.name = "activation" 
if nonlinear: 
    response = T.nnet.sigmoid(activation) 
    response.name = "response" 
else: 
    response = activation 
    response.name = "activation&response" 

但身份的功能会更优雅:

activation = T.dot(feature, filter) 
activation.name = "activation" 
response = T.nnet.sigmoid(activation) if nonlinear else T.identity(activation) 
response.name = "response" 
+0

我不熟悉Theano,但将deepcopy的帮助? –

+1

@JayanthKoushik不,Theano符号是符号数学表达式,而不是常规的Python数据。 –

回答

3

上张量的copy(name=None) function是你想要的。

第一个例子变成这样:

x.name = "x" 
y = x.copy("y") 

第二个例子变成这样:

activation = T.dot(feature, filter) 
activation.name = "activation" 
response = T.nnet.sigmoid(activation) if nonlinear else activation.copy() 
response.name = "response" 
相关问题