提交 dcbc3e43 authored 作者: James Bergstra's avatar James Bergstra

Commented on why local_1msigmoid is not registered. Modified 1msigmoid test to not run

when the 1msigmoid optimization is not registered.
上级 c42414b6
...@@ -294,9 +294,8 @@ def local_inv_1_plus_exp(node): ...@@ -294,9 +294,8 @@ def local_inv_1_plus_exp(node):
sigmoid(tensor.neg(nonconsts[0].owner.inputs[0])), sigmoid(tensor.neg(nonconsts[0].owner.inputs[0])),
scalar_inputs) scalar_inputs)
# Registration is below, and conditional.
#@opt.register_canonicalize @gof.local_optimizer([tensor.sub])
@gof.local_optimizer([tensor.inv])
def local_1msigmoid(node): def local_1msigmoid(node):
""" """
1-sigm(x) -> sigm(-x) 1-sigm(x) -> sigm(-x)
...@@ -313,3 +312,13 @@ def local_1msigmoid(node): ...@@ -313,3 +312,13 @@ def local_1msigmoid(node):
if numpy.allclose(numpy.sum(val_l), 1): if numpy.allclose(numpy.sum(val_l), 1):
return [sigmoid(-sub_r.owner.inputs[0])] return [sigmoid(-sub_r.owner.inputs[0])]
register_local_1msigmoid = False
# This is False because the Stabilize pattern above
# is looking for 1-sigm. Also Canonizer turns neg into *(-1) and so
# this optimization might set off an unwanted chain of things.
# OTH - this transformation can be seen as pushing normal arithmetic either below or above the
# sigmoidal nonlinearity... so if the canonicalized form had anything to say about that then it
# would be a consideration... anyway leaving False for now.
if register_local_1msigmoid:
opt.register_canonicalize(local_1msigmoid)
...@@ -7,6 +7,7 @@ from theano.tests import unittest_tools as utt ...@@ -7,6 +7,7 @@ from theano.tests import unittest_tools as utt
from theano.tensor.tests import test_basic as TT from theano.tensor.tests import test_basic as TT
from theano.tensor.nnet import * from theano.tensor.nnet import *
from theano.tensor.nnet.sigm import register_local_1msigmoid
class T_sigmoid(unittest.TestCase): class T_sigmoid(unittest.TestCase):
...@@ -21,7 +22,6 @@ class T_softplus(unittest.TestCase): ...@@ -21,7 +22,6 @@ class T_softplus(unittest.TestCase):
def test_elemwise(self): def test_elemwise(self):
utt.verify_grad(softplus, [numpy.random.rand(3,4)]) utt.verify_grad(softplus, [numpy.random.rand(3,4)])
class T_sigmoid_opts(unittest.TestCase): class T_sigmoid_opts(unittest.TestCase):
def test_exp_over_1_plus_exp(self): def test_exp_over_1_plus_exp(self):
m = theano.config.mode m = theano.config.mode
...@@ -53,6 +53,9 @@ class T_sigmoid_opts(unittest.TestCase): ...@@ -53,6 +53,9 @@ class T_sigmoid_opts(unittest.TestCase):
T.mul] T.mul]
def test_1msigmoid(self): def test_1msigmoid(self):
if not register_local_1msigmoid:
return
m = theano.config.mode m = theano.config.mode
if m == 'FAST_COMPILE': if m == 'FAST_COMPILE':
m = 'FAST_RUN' m = 'FAST_RUN'
...@@ -70,6 +73,3 @@ class T_sigmoid_opts(unittest.TestCase): ...@@ -70,6 +73,3 @@ class T_sigmoid_opts(unittest.TestCase):
assert [node.op for node in f.maker.env.toposort()] == [tensor.neg, assert [node.op for node in f.maker.env.toposort()] == [tensor.neg,
sigmoid_inplace] sigmoid_inplace]
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论