Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
ae635037
提交
ae635037
authored
2月 09, 2016
作者:
Amjad Almahairi
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
change weighted_selection to multinomial_wo_replacement
上级
d775ab46
隐藏空白字符变更
内嵌
并排
正在显示
3 个修改的文件
包含
19 行增加
和
19 行删除
+19
-19
multinomial.py
theano/sandbox/multinomial.py
+1
-1
rng_mrg.py
theano/sandbox/rng_mrg.py
+6
-6
test_multinomial_wo_replacement.py
theano/sandbox/tests/test_multinomial_wo_replacement.py
+12
-12
没有找到文件。
theano/sandbox/multinomial.py
浏览文件 @
ae635037
...
@@ -194,7 +194,7 @@ class MultinomialFromUniform(Op):
...
@@ -194,7 +194,7 @@ class MultinomialFromUniform(Op):
break
break
class
WeightedSelection
FromUniform
(
Op
):
class
MultinomialWOReplacement
FromUniform
(
Op
):
"""
"""
Converts samples from a uniform into sample from a multinomial.
Converts samples from a uniform into sample from a multinomial.
...
...
theano/sandbox/rng_mrg.py
浏览文件 @
ae635037
...
@@ -1363,8 +1363,8 @@ class MRG_RandomStreams(object):
...
@@ -1363,8 +1363,8 @@ class MRG_RandomStreams(object):
raise
NotImplementedError
((
"MRG_RandomStreams.multinomial only"
raise
NotImplementedError
((
"MRG_RandomStreams.multinomial only"
" implemented for pvals.ndim = 2"
))
" implemented for pvals.ndim = 2"
))
def
weighted_selection
(
self
,
size
=
None
,
n
=
1
,
pvals
=
None
,
ndim
=
None
,
dtype
=
'int64'
,
def
multinomial_wo_replacement
(
self
,
size
=
None
,
n
=
1
,
pvals
=
None
,
ndim
=
None
,
dtype
=
'int64'
,
nstreams
=
None
):
nstreams
=
None
):
"""
"""
Sample `n` times *WITHOUT replacement* from a multinomial distribution
Sample `n` times *WITHOUT replacement* from a multinomial distribution
defined by probabilities pvals, and returns the indices of the sampled
defined by probabilities pvals, and returns the indices of the sampled
...
@@ -1394,21 +1394,21 @@ class MRG_RandomStreams(object):
...
@@ -1394,21 +1394,21 @@ class MRG_RandomStreams(object):
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.
multinomial_wo_replacement
, which does not use "
"the size argument."
)
"the size argument."
)
if
ndim
is
not
None
:
if
ndim
is
not
None
:
raise
ValueError
(
"Provided an ndim argument to "
raise
ValueError
(
"Provided an ndim argument to "
"MRG_RandomStreams.
weighted_selection
, which does not use "
"MRG_RandomStreams.
multinomial_wo_replacement
, which does not use "
"the ndim argument."
)
"the ndim argument."
)
if
pvals
.
ndim
==
2
:
if
pvals
.
ndim
==
2
:
# size = [pvals.shape[0], as_tensor_variable(n)]
# size = [pvals.shape[0], as_tensor_variable(n)]
size
=
pvals
[:,
0
]
.
shape
*
n
size
=
pvals
[:,
0
]
.
shape
*
n
unis
=
self
.
uniform
(
size
=
size
,
ndim
=
1
,
nstreams
=
nstreams
)
unis
=
self
.
uniform
(
size
=
size
,
ndim
=
1
,
nstreams
=
nstreams
)
op
=
multinomial
.
WeightedSelection
FromUniform
(
dtype
)
op
=
multinomial
.
MultinomialWOReplacement
FromUniform
(
dtype
)
n_samples
=
as_tensor_variable
(
n
)
n_samples
=
as_tensor_variable
(
n
)
return
op
(
pvals
,
unis
,
n_samples
)
return
op
(
pvals
,
unis
,
n_samples
)
else
:
else
:
raise
NotImplementedError
((
"MRG_RandomStreams.
weighted_selection
only"
raise
NotImplementedError
((
"MRG_RandomStreams.
multinomial_wo_replacement
only"
" implemented for pvals.ndim = 2"
))
" implemented for pvals.ndim = 2"
))
def
normal
(
self
,
size
,
avg
=
0.0
,
std
=
1.0
,
ndim
=
None
,
def
normal
(
self
,
size
,
avg
=
0.0
,
std
=
1.0
,
ndim
=
None
,
...
...
theano/sandbox/tests/test_
weighted_selec
t.py
→
theano/sandbox/tests/test_
multinomial_wo_replacemen
t.py
浏览文件 @
ae635037
...
@@ -9,12 +9,12 @@ class test_OP(unittest.TestCase):
...
@@ -9,12 +9,12 @@ class test_OP(unittest.TestCase):
def
test_select_distinct
(
self
):
def
test_select_distinct
(
self
):
"""
"""
Tests that
WeightedSelection
FromUniform always selects distinct elements
Tests that
MultinomialWOReplacement
FromUniform always selects distinct elements
"""
"""
p
=
tensor
.
fmatrix
()
p
=
tensor
.
fmatrix
()
u
=
tensor
.
fvector
()
u
=
tensor
.
fvector
()
n
=
tensor
.
iscalar
()
n
=
tensor
.
iscalar
()
m
=
multinomial
.
WeightedSelection
FromUniform
(
'auto'
)(
p
,
u
,
n
)
m
=
multinomial
.
MultinomialWOReplacement
FromUniform
(
'auto'
)(
p
,
u
,
n
)
f
=
function
([
p
,
u
,
n
],
m
,
allow_input_downcast
=
True
)
f
=
function
([
p
,
u
,
n
],
m
,
allow_input_downcast
=
True
)
...
@@ -32,13 +32,13 @@ class test_OP(unittest.TestCase):
...
@@ -32,13 +32,13 @@ class test_OP(unittest.TestCase):
def
test_fail_select_alot
(
self
):
def
test_fail_select_alot
(
self
):
"""
"""
Tests that
WeightedSelection
FromUniform fails when asked to sample more
Tests that
MultinomialWOReplacement
FromUniform fails when asked to sample more
elements than the actual number of elements
elements than the actual number of elements
"""
"""
p
=
tensor
.
fmatrix
()
p
=
tensor
.
fmatrix
()
u
=
tensor
.
fvector
()
u
=
tensor
.
fvector
()
n
=
tensor
.
iscalar
()
n
=
tensor
.
iscalar
()
m
=
multinomial
.
WeightedSelection
FromUniform
(
'auto'
)(
p
,
u
,
n
)
m
=
multinomial
.
MultinomialWOReplacement
FromUniform
(
'auto'
)(
p
,
u
,
n
)
f
=
function
([
p
,
u
,
n
],
m
,
allow_input_downcast
=
True
)
f
=
function
([
p
,
u
,
n
],
m
,
allow_input_downcast
=
True
)
...
@@ -52,13 +52,13 @@ class test_OP(unittest.TestCase):
...
@@ -52,13 +52,13 @@ class test_OP(unittest.TestCase):
def
test_select_proportional_to_weight
(
self
):
def
test_select_proportional_to_weight
(
self
):
"""
"""
Tests that
WeightedSelection
FromUniform selects elements, on average,
Tests that
MultinomialWOReplacement
FromUniform selects elements, on average,
proportional to the their probabilities
proportional to the their probabilities
"""
"""
p
=
tensor
.
fmatrix
()
p
=
tensor
.
fmatrix
()
u
=
tensor
.
fvector
()
u
=
tensor
.
fvector
()
n
=
tensor
.
iscalar
()
n
=
tensor
.
iscalar
()
m
=
multinomial
.
WeightedSelection
FromUniform
(
'auto'
)(
p
,
u
,
n
)
m
=
multinomial
.
MultinomialWOReplacement
FromUniform
(
'auto'
)(
p
,
u
,
n
)
f
=
function
([
p
,
u
,
n
],
m
,
allow_input_downcast
=
True
)
f
=
function
([
p
,
u
,
n
],
m
,
allow_input_downcast
=
True
)
...
@@ -83,13 +83,13 @@ class test_function(unittest.TestCase):
...
@@ -83,13 +83,13 @@ class test_function(unittest.TestCase):
def
test_select_distinct
(
self
):
def
test_select_distinct
(
self
):
"""
"""
Tests that
weighted_selection
always selects distinct elements
Tests that
multinomial_wo_replacement
always selects distinct elements
"""
"""
th_rng
=
RandomStreams
(
12345
)
th_rng
=
RandomStreams
(
12345
)
p
=
tensor
.
fmatrix
()
p
=
tensor
.
fmatrix
()
n
=
tensor
.
iscalar
()
n
=
tensor
.
iscalar
()
m
=
th_rng
.
weighted_selection
(
pvals
=
p
,
n
=
n
)
m
=
th_rng
.
multinomial_wo_replacement
(
pvals
=
p
,
n
=
n
)
f
=
function
([
p
,
n
],
m
,
allow_input_downcast
=
True
)
f
=
function
([
p
,
n
],
m
,
allow_input_downcast
=
True
)
...
@@ -106,14 +106,14 @@ class test_function(unittest.TestCase):
...
@@ -106,14 +106,14 @@ class test_function(unittest.TestCase):
def
test_fail_select_alot
(
self
):
def
test_fail_select_alot
(
self
):
"""
"""
Tests that
weighted_selection
fails when asked to sample more
Tests that
multinomial_wo_replacement
fails when asked to sample more
elements than the actual number of elements
elements than the actual number of elements
"""
"""
th_rng
=
RandomStreams
(
12345
)
th_rng
=
RandomStreams
(
12345
)
p
=
tensor
.
fmatrix
()
p
=
tensor
.
fmatrix
()
n
=
tensor
.
iscalar
()
n
=
tensor
.
iscalar
()
m
=
th_rng
.
weighted_selection
(
pvals
=
p
,
n
=
n
)
m
=
th_rng
.
multinomial_wo_replacement
(
pvals
=
p
,
n
=
n
)
f
=
function
([
p
,
n
],
m
,
allow_input_downcast
=
True
)
f
=
function
([
p
,
n
],
m
,
allow_input_downcast
=
True
)
...
@@ -126,14 +126,14 @@ class test_function(unittest.TestCase):
...
@@ -126,14 +126,14 @@ class test_function(unittest.TestCase):
def
test_select_proportional_to_weight
(
self
):
def
test_select_proportional_to_weight
(
self
):
"""
"""
Tests that
weighted_selection
selects elements, on average,
Tests that
multinomial_wo_replacement
selects elements, on average,
proportional to the their probabilities
proportional to the their probabilities
"""
"""
th_rng
=
RandomStreams
(
12345
)
th_rng
=
RandomStreams
(
12345
)
p
=
tensor
.
fmatrix
()
p
=
tensor
.
fmatrix
()
n
=
tensor
.
iscalar
()
n
=
tensor
.
iscalar
()
m
=
th_rng
.
weighted_selection
(
pvals
=
p
,
n
=
n
)
m
=
th_rng
.
multinomial_wo_replacement
(
pvals
=
p
,
n
=
n
)
f
=
function
([
p
,
n
],
m
,
allow_input_downcast
=
True
)
f
=
function
([
p
,
n
],
m
,
allow_input_downcast
=
True
)
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论