提交 c2ccdc09 authored 作者: Brandon T. Willard's avatar Brandon T. Willard 提交者: Brandon T. Willard

Perform missing aet.nnet.sigmoid to aet.sigmoid replacements

上级 4265d4fb
...@@ -100,7 +100,7 @@ ...@@ -100,7 +100,7 @@
"x = aet.dmatrix('x')\n", "x = aet.dmatrix('x')\n",
"wh = th.shared(rng.normal(0, 1, (nfeatures, nhiddens)), borrow=True)\n", "wh = th.shared(rng.normal(0, 1, (nfeatures, nhiddens)), borrow=True)\n",
"bh = th.shared(np.zeros(nhiddens), borrow=True)\n", "bh = th.shared(np.zeros(nhiddens), borrow=True)\n",
"h = aet.nnet.sigmoid(aet.dot(x, wh) + bh)\n", "h = aet.sigmoid(aet.dot(x, wh) + bh)\n",
"\n", "\n",
"wy = th.shared(rng.normal(0, 1, (nhiddens, noutputs)))\n", "wy = th.shared(rng.normal(0, 1, (nhiddens, noutputs)))\n",
"by = th.shared(np.zeros(noutputs), borrow=True)\n", "by = th.shared(np.zeros(noutputs), borrow=True)\n",
...@@ -390,7 +390,7 @@ ...@@ -390,7 +390,7 @@
"outputs": [], "outputs": [],
"source": [ "source": [
"x, y, z = aet.scalars('xyz')\n", "x, y, z = aet.scalars('xyz')\n",
"e = aet.nnet.sigmoid((x + y + z)**2)\n", "e = aet.sigmoid((x + y + z)**2)\n",
"op = th.compile.builders.OpFromGraph([x, y, z], [e])\n", "op = th.compile.builders.OpFromGraph([x, y, z], [e])\n",
"\n", "\n",
"e2 = op(x, y, z) + op(z, y, x)\n", "e2 = op(x, y, z) + op(z, y, x)\n",
......
...@@ -63,7 +63,7 @@ hidden layer and a softmax output layer. ...@@ -63,7 +63,7 @@ hidden layer and a softmax output layer.
x = aet.dmatrix('x') x = aet.dmatrix('x')
wh = th.shared(rng.normal(0, 1, (nfeatures, nhiddens)), borrow=True) wh = th.shared(rng.normal(0, 1, (nfeatures, nhiddens)), borrow=True)
bh = th.shared(np.zeros(nhiddens), borrow=True) bh = th.shared(np.zeros(nhiddens), borrow=True)
h = aet.nnet.sigmoid(aet.dot(x, wh) + bh) h = aet.sigmoid(aet.dot(x, wh) + bh)
wy = th.shared(rng.normal(0, 1, (nhiddens, noutputs))) wy = th.shared(rng.normal(0, 1, (nhiddens, noutputs)))
by = th.shared(np.zeros(noutputs), borrow=True) by = th.shared(np.zeros(noutputs), borrow=True)
...@@ -211,7 +211,7 @@ node defines a nested graph, which will be visualized accordingly by ``d3viz``. ...@@ -211,7 +211,7 @@ node defines a nested graph, which will be visualized accordingly by ``d3viz``.
.. code:: python .. code:: python
x, y, z = aet.scalars('xyz') x, y, z = aet.scalars('xyz')
e = aet.nnet.sigmoid((x + y + z)**2) e = aet.sigmoid((x + y + z)**2)
op = th.compile.builders.OpFromGraph([x, y, z], [e]) op = th.compile.builders.OpFromGraph([x, y, z], [e])
e2 = op(x, y, z) + op(z, y, x) e2 = op(x, y, z) + op(z, y, x)
......
...@@ -276,9 +276,9 @@ the following: ...@@ -276,9 +276,9 @@ the following:
trng = aesara.tensor.random.utils.RandomStream(1234) trng = aesara.tensor.random.utils.RandomStream(1234)
def OneStep(vsample) : def OneStep(vsample) :
hmean = aet.nnet.sigmoid(aesara.dot(vsample, W) + bhid) hmean = aet.sigmoid(aesara.dot(vsample, W) + bhid)
hsample = trng.binomial(size=hmean.shape, n=1, p=hmean) hsample = trng.binomial(size=hmean.shape, n=1, p=hmean)
vmean = aet.nnet.sigmoid(aesara.dot(hsample, W.T) + bvis) vmean = aet.sigmoid(aesara.dot(hsample, W.T) + bvis)
return trng.binomial(size=vsample.shape, n=1, p=vmean, return trng.binomial(size=vsample.shape, n=1, p=vmean,
dtype=aesara.config.floatX) dtype=aesara.config.floatX)
...@@ -358,9 +358,9 @@ updated: ...@@ -358,9 +358,9 @@ updated:
# OneStep, with explicit use of the shared variables (W, bvis, bhid) # OneStep, with explicit use of the shared variables (W, bvis, bhid)
def OneStep(vsample, W, bvis, bhid): def OneStep(vsample, W, bvis, bhid):
hmean = aet.nnet.sigmoid(aesara.dot(vsample, W) + bhid) hmean = aet.sigmoid(aesara.dot(vsample, W) + bhid)
hsample = trng.binomial(size=hmean.shape, n=1, p=hmean) hsample = trng.binomial(size=hmean.shape, n=1, p=hmean)
vmean = aet.nnet.sigmoid(aesara.dot(hsample, W.T) + bvis) vmean = aet.sigmoid(aesara.dot(hsample, W.T) + bvis)
return trng.binomial(size=vsample.shape, n=1, p=vmean, return trng.binomial(size=vsample.shape, n=1, p=vmean,
dtype=aesara.config.floatX) dtype=aesara.config.floatX)
...@@ -394,9 +394,9 @@ Using the original Gibbs sampling example, with ``strict=True`` added to the ...@@ -394,9 +394,9 @@ Using the original Gibbs sampling example, with ``strict=True`` added to the
# Same OneStep as in original example. # Same OneStep as in original example.
def OneStep(vsample) : def OneStep(vsample) :
hmean = aet.nnet.sigmoid(aesara.dot(vsample, W) + bhid) hmean = aet.sigmoid(aesara.dot(vsample, W) + bhid)
hsample = trng.binomial(size=hmean.shape, n=1, p=hmean) hsample = trng.binomial(size=hmean.shape, n=1, p=hmean)
vmean = aet.nnet.sigmoid(aesara.dot(hsample, W.T) + bvis) vmean = aet.sigmoid(aesara.dot(hsample, W.T) + bvis)
return trng.binomial(size=vsample.shape, n=1, p=vmean, return trng.binomial(size=vsample.shape, n=1, p=vmean,
dtype=aesara.config.floatX) dtype=aesara.config.floatX)
...@@ -423,9 +423,9 @@ variables passed explicitly to ``OneStep`` and to scan: ...@@ -423,9 +423,9 @@ variables passed explicitly to ``OneStep`` and to scan:
# OneStep, with explicit use of the shared variables (W, bvis, bhid) # OneStep, with explicit use of the shared variables (W, bvis, bhid)
def OneStep(vsample, W, bvis, bhid) : def OneStep(vsample, W, bvis, bhid) :
hmean = aet.nnet.sigmoid(aesara.dot(vsample, W) + bhid) hmean = aet.sigmoid(aesara.dot(vsample, W) + bhid)
hsample = trng.binomial(size=hmean.shape, n=1, p=hmean) hsample = trng.binomial(size=hmean.shape, n=1, p=hmean)
vmean = aet.nnet.sigmoid(aesara.dot(hsample, W.T) + bvis) vmean = aet.sigmoid(aesara.dot(hsample, W.T) + bvis)
return trng.binomial(size=vsample.shape, n=1, p=vmean, return trng.binomial(size=vsample.shape, n=1, p=vmean,
dtype=aesara.config.floatX) dtype=aesara.config.floatX)
......
...@@ -54,7 +54,7 @@ ...@@ -54,7 +54,7 @@
x, y, b = aet.dvectors('x', 'y', 'b') x, y, b = aet.dvectors('x', 'y', 'b')
W = aet.dmatrix('W') W = aet.dmatrix('W')
y = aet.nnet.sigmoid(aet.dot(W, x) + b) y = aet.sigmoid(aet.dot(W, x) + b)
.. note:: The underlying code will return an exact 0 or 1 if an .. note:: The underlying code will return an exact 0 or 1 if an
element of x is too small or too big. element of x is too small or too big.
...@@ -174,8 +174,8 @@ ...@@ -174,8 +174,8 @@
x, y, b, c = aet.dvectors('x', 'y', 'b', 'c') x, y, b, c = aet.dvectors('x', 'y', 'b', 'c')
W = aet.dmatrix('W') W = aet.dmatrix('W')
V = aet.dmatrix('V') V = aet.dmatrix('V')
h = aet.nnet.sigmoid(aet.dot(W, x) + b) h = aet.sigmoid(aet.dot(W, x) + b)
x_recons = aet.nnet.sigmoid(aet.dot(V, h) + c) x_recons = aet.sigmoid(aet.dot(V, h) + c)
recon_cost = aet.nnet.binary_crossentropy(x_recons, x).mean() recon_cost = aet.nnet.binary_crossentropy(x_recons, x).mean()
.. function:: sigmoid_binary_crossentropy(output,target) .. function:: sigmoid_binary_crossentropy(output,target)
...@@ -203,11 +203,11 @@ ...@@ -203,11 +203,11 @@
x, y, b, c = aet.dvectors('x', 'y', 'b', 'c') x, y, b, c = aet.dvectors('x', 'y', 'b', 'c')
W = aet.dmatrix('W') W = aet.dmatrix('W')
V = aet.dmatrix('V') V = aet.dmatrix('V')
h = aet.nnet.sigmoid(aet.dot(W, x) + b) h = aet.sigmoid(aet.dot(W, x) + b)
x_precons = aet.dot(V, h) + c x_precons = aet.dot(V, h) + c
# final reconstructions are given by sigmoid(x_precons), but we leave # final reconstructions are given by sigmoid(x_precons), but we leave
# them unnormalized as sigmoid_binary_crossentropy applies sigmoid # them unnormalized as sigmoid_binary_crossentropy applies sigmoid
recon_cost = aet.nnet.sigmoid_binary_crossentropy(x_precons, x).mean() recon_cost = aet.sigmoid_binary_crossentropy(x_precons, x).mean()
.. function:: categorical_crossentropy(coding_dist,true_dist) .. function:: categorical_crossentropy(coding_dist,true_dist)
......
...@@ -20,7 +20,7 @@ class Mlp: ...@@ -20,7 +20,7 @@ class Mlp:
x = dmatrix("x") x = dmatrix("x")
wh = shared(self.rng.normal(0, 1, (nfeatures, nhiddens)), borrow=True) wh = shared(self.rng.normal(0, 1, (nfeatures, nhiddens)), borrow=True)
bh = shared(np.zeros(nhiddens), borrow=True) bh = shared(np.zeros(nhiddens), borrow=True)
h = aet.nnet.sigmoid(aet.dot(x, wh) + bh) h = aet.sigmoid(aet.dot(x, wh) + bh)
wy = shared(self.rng.normal(0, 1, (nhiddens, noutputs))) wy = shared(self.rng.normal(0, 1, (nhiddens, noutputs)))
by = shared(np.zeros(noutputs), borrow=True) by = shared(np.zeros(noutputs), borrow=True)
...@@ -46,7 +46,7 @@ class OfgNested: ...@@ -46,7 +46,7 @@ class OfgNested:
class Ofg: class Ofg:
def __init__(self): def __init__(self):
x, y, z = scalars("xyz") x, y, z = scalars("xyz")
e = aet.nnet.sigmoid((x + y + z) ** 2) e = aet.sigmoid((x + y + z) ** 2)
op = OpFromGraph([x, y, z], [e]) op = OpFromGraph([x, y, z], [e])
e2 = op(x, y, z) + op(z, y, x) e2 = op(x, y, z) + op(z, y, x)
...@@ -57,7 +57,7 @@ class Ofg: ...@@ -57,7 +57,7 @@ class Ofg:
class OfgSimple: class OfgSimple:
def __init__(self): def __init__(self):
x, y, z = scalars("xyz") x, y, z = scalars("xyz")
e = aet.nnet.sigmoid((x + y + z) ** 2) e = aet.sigmoid((x + y + z) ** 2)
op = OpFromGraph([x, y, z], [e]) op = OpFromGraph([x, y, z], [e])
e2 = op(x, y, z) e2 = op(x, y, z)
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论