Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
9a85dbc1
Unverified
提交
9a85dbc1
authored
9月 23, 2022
作者:
Nicolas Legrand
提交者:
GitHub
9月 23, 2022
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Update Scan Gibbs example in documentation
上级
8d612023
隐藏空白字符变更
内嵌
并排
正在显示
1 个修改的文件
包含
19 行增加
和
24 行删除
+19
-24
scan.rst
doc/library/scan.rst
+19
-24
没有找到文件。
doc/library/scan.rst
浏览文件 @
9a85dbc1
...
@@ -254,40 +254,35 @@ Another useful feature of scan, is that it can handle shared variables.
...
@@ -254,40 +254,35 @@ Another useful feature of scan, is that it can handle shared variables.
For example, if we want to implement a Gibbs chain of length 10 we would do
For example, if we want to implement a Gibbs chain of length 10 we would do
the following:
the following:
.. testsetup:: scan1
import aesara
import numpy
W_values = numpy.random.random((2, 2))
bvis_values = numpy.random.random((2,))
bhid_values = numpy.random.random((2,))
.. testcode:: scan1
.. testcode:: scan1
import aesara
import aesara
from aesara import tensor as at
import aesara.tensor as at
import numpy as np
W = aesara.shared(W_values) # we assume that ``W_values`` contains the
rng = np.random.default_rng(203940)
# initial values of your weight matrix
W_values = rng.uniform(size=(2, 2))
bvis_values = rng.uniform(size=(2,))
bhid_values = rng.uniform(size=(2,))
bvis = aesara.shared(bvis_values)
W = aesara.shared(W_values)
bhid = aesara.shared(bhid_values)
bvis = aesara.shared(bvis_values)
bhid = aesara.shared(bhid_values)
trng = aesara.tensor.random.utils
.RandomStream(1234)
srng = at.random
.RandomStream(1234)
def OneStep(vsample) :
def one_step(vsample):
hmean = at.sigmoid(aesara.dot(vsample, W) + bhid)
hmean = at.sigmoid(at.dot(vsample, W) + bhid)
hsample = trng.binomial(size=hmean.shape, n=1, p=hmean)
hsample = srng.binomial(1, hmean, size=hmean.shape)
vmean = at.sigmoid(aesara.dot(hsample, W.T) + bvis)
vmean = at.sigmoid(at.dot(hsample, W.T) + bvis)
return trng.binomial(size=vsample.shape, n=1, p=vmean,
dtype=aesara.config.floatX)
sample = aesara.tensor.vector(
)
return srng.binomial(1, vmean, size=vsample.shape
)
values, updates = aesara.scan(OneStep, outputs_info=sample, n_steps=10
)
sample = at.lvector(
)
gibbs10 = aesara.function([sample], values[-1], updates=updates
)
values, updates = aesara.scan(one_step, outputs_info=sample, n_steps=10
)
gibbs10 = aesara.function([sample], values[-1], updates=updates)
The first, and probably most crucial observation is that the updates
The first, and probably most crucial observation is that the updates
dictionary becomes important in this case. It links a shared variable
dictionary becomes important in this case. It links a shared variable
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论