提交 0f685103 authored 作者: James Bergstra's avatar James Bergstra

committing half-baked sigmoid optimization that wasnt done for scipy

上级 e3fc9429
...@@ -338,3 +338,47 @@ register_local_1msigmoid = False ...@@ -338,3 +338,47 @@ register_local_1msigmoid = False
if register_local_1msigmoid: if register_local_1msigmoid:
opt.register_canonicalize(local_1msigmoid) opt.register_canonicalize(local_1msigmoid)
if 0:
# This code is if'd out because it is not complete,
# and it isn't obviously a good idea anyway.
# The motivation here was to identify the last exp() node
# in the SciPy2010 article, which was not optimized away at the time of publication,
# so the example is actually not numerically stable, even though it should be.
@opt.register_stabilize
@gof.local_optimizer([tensor.mul])
def local_sigm_gest(node):
print "CANONICALIZE"
print sigm_canonicalize(node)
def sigm_canonicalize(node):
add = tensor.add
mul = tensor.mul
div = tensor.true_div
if node.op == tensor.add:
rval = []
for i in node.inputs:
rval += sigm_canonicalize(i)
return rval
if node.op == tensor.mul:
rval = sigm_canonicalize(node.inputs[0])
for i in node.inputs[1:]:
old_rval = rval
rval = []
for t1 in sigm_canonicalize(i):
for t0 in old_rval:
assert t1.owner.op == div
assert t0.owner.op == div
t0top, t0bot = t0.owner.inputs
t1top, t1bot = t1.owner.inputs
rval.append(div(mul(*(t0top+t1top)), mul(*(t0bot+t1bot))))
if len(rval) > 100:
# This loop can be exponentially long.
# aborting
return []
elif len(node.outputs)>1:
return []
else:
return [node.outputs[0]]
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论