Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
60b3686f
提交
60b3686f
authored
12月 17, 2015
作者:
Amjad Almahairi
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
working 1st version
上级
2176d21b
显示空白字符变更
内嵌
并排
正在显示
2 个修改的文件
包含
13 行增加
和
9 行删除
+13
-9
multinomial.py
theano/sandbox/multinomial.py
+10
-4
rng_mrg.py
theano/sandbox/rng_mrg.py
+3
-5
没有找到文件。
theano/sandbox/multinomial.py
浏览文件 @
60b3686f
...
@@ -236,11 +236,16 @@ class WeightedSelectionFromUniform(Op):
...
@@ -236,11 +236,16 @@ class WeightedSelectionFromUniform(Op):
(
pvals
,
unis
,
n_samples
)
=
ins
(
pvals
,
unis
,
n_samples
)
=
ins
(
z
,)
=
outs
(
z
,)
=
outs
if
n_samples
>
pvals
.
shape
[
1
]:
raise
ValueError
(
"Cannot sample without replacement n samples bigger "
"than the size of the distribution."
)
if
unis
.
shape
[
0
]
!=
pvals
.
shape
[
0
]
*
n_samples
:
if
unis
.
shape
[
0
]
!=
pvals
.
shape
[
0
]
*
n_samples
:
raise
ValueError
(
"unis.shape[0] != pvals.shape[0] * n_samples"
,
raise
ValueError
(
"unis.shape[0] != pvals.shape[0] * n_samples"
,
unis
.
shape
[
0
],
pvals
.
shape
[
0
],
n_samples
)
unis
.
shape
[
0
],
pvals
.
shape
[
0
],
n_samples
)
if
z
[
0
]
is
None
or
numpy
.
any
(
z
[
0
]
.
shape
!=
[
pvals
.
shape
[
0
],
n_samples
]):
z
[
0
]
=
numpy
.
zeros
((
pvals
.
shape
[
0
],
n_samples
),
dtype
=
node
.
outputs
[
0
]
.
dtype
)
if
z
[
0
]
is
None
or
not
numpy
.
all
(
z
[
0
]
.
shape
==
[
pvals
.
shape
[
0
],
n_samples
]):
z
[
0
]
=
-
1
*
numpy
.
ones
((
pvals
.
shape
[
0
],
n_samples
),
dtype
=
node
.
outputs
[
0
]
.
dtype
)
nb_multi
=
pvals
.
shape
[
0
]
nb_multi
=
pvals
.
shape
[
0
]
nb_outcomes
=
pvals
.
shape
[
1
]
nb_outcomes
=
pvals
.
shape
[
1
]
...
@@ -255,9 +260,10 @@ class WeightedSelectionFromUniform(Op):
...
@@ -255,9 +260,10 @@ class WeightedSelectionFromUniform(Op):
cummul
+=
pvals
[
n
,
m
]
cummul
+=
pvals
[
n
,
m
]
if
(
cummul
>
unis_n
):
if
(
cummul
>
unis_n
):
z
[
0
][
n
,
c
]
=
m
z
[
0
][
n
,
c
]
=
m
# set to zero so that it's not selected again
# set to zero
and re-normalize
so that it's not selected again
pvals
[
n
,
m
]
=
0.
pvals
[
n
,
m
]
=
0.
pvals
[
n
]
/=
pvals
[
n
]
.
sum
()
break
class
GpuMultinomialFromUniform
(
MultinomialFromUniform
,
GpuOp
):
class
GpuMultinomialFromUniform
(
MultinomialFromUniform
,
GpuOp
):
"""
"""
...
...
theano/sandbox/rng_mrg.py
浏览文件 @
60b3686f
...
@@ -1366,8 +1366,9 @@ class MRG_RandomStreams(object):
...
@@ -1366,8 +1366,9 @@ class MRG_RandomStreams(object):
def
weighted_selection
(
self
,
size
=
None
,
n
=
1
,
pvals
=
None
,
ndim
=
None
,
dtype
=
'int64'
,
def
weighted_selection
(
self
,
size
=
None
,
n
=
1
,
pvals
=
None
,
ndim
=
None
,
dtype
=
'int64'
,
nstreams
=
None
):
nstreams
=
None
):
"""
"""
Sample `n` times (`n` needs to be in [1, m], where m is pvals.shape[1], default 1)
Sample `n` times *WITHOUT replacement* from a multinomial distribution
*WITHOUT replacement* from a multinomial distribution defined by probabilities pvals.
defined by probabilities pvals. `n` needs to be in [1, m], where m is the number of
elements to select from, i.e. m == pvals.shape[1]. By default n = 1.
Example : WRITEME
Example : WRITEME
...
@@ -1387,9 +1388,6 @@ class MRG_RandomStreams(object):
...
@@ -1387,9 +1388,6 @@ class MRG_RandomStreams(object):
raise
TypeError
(
"You have to specify pvals"
)
raise
TypeError
(
"You have to specify pvals"
)
pvals
=
as_tensor_variable
(
pvals
)
pvals
=
as_tensor_variable
(
pvals
)
if
n
>
pvals
.
shape
[
1
]:
raise
ValueError
(
"Cannot sample without replacement n samples bigger "
"than the size of the distribution."
)
if
size
is
not
None
:
if
size
is
not
None
:
raise
ValueError
(
"Provided a size argument to "
raise
ValueError
(
"Provided a size argument to "
"MRG_RandomStreams.weighted_selection, which does not use "
"MRG_RandomStreams.weighted_selection, which does not use "
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论