Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
aef8cd99
提交
aef8cd99
authored
2月 08, 2016
作者:
Amjad Almahairi
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
fixed datatype issues
上级
e4904c8c
显示空白字符变更
内嵌
并排
正在显示
2 个修改的文件
包含
18 行增加
和
8 行删除
+18
-8
multinomial.py
theano/sandbox/multinomial.py
+10
-2
test_weighted_select.py
theano/sandbox/tests/test_weighted_select.py
+8
-6
没有找到文件。
theano/sandbox/multinomial.py
浏览文件 @
aef8cd99
...
@@ -12,6 +12,7 @@ if cuda_available:
...
@@ -12,6 +12,7 @@ if cuda_available:
from
theano.sandbox.cuda
import
CudaNdarrayType
from
theano.sandbox.cuda
import
CudaNdarrayType
from
theano.sandbox.cuda.basic_ops
import
host_from_gpu
,
gpu_from_host
from
theano.sandbox.cuda.basic_ops
import
host_from_gpu
,
gpu_from_host
from
theano.sandbox.cuda.opt
import
register_opt
from
theano.sandbox.cuda.opt
import
register_opt
import
sys
class
MultinomialFromUniform
(
Op
):
class
MultinomialFromUniform
(
Op
):
...
@@ -218,7 +219,10 @@ class WeightedSelectionFromUniform(Op):
...
@@ -218,7 +219,10 @@ class WeightedSelectionFromUniform(Op):
if
unis
.
ndim
!=
1
:
if
unis
.
ndim
!=
1
:
raise
NotImplementedError
(
'unis ndim should be 1'
,
unis
.
ndim
)
raise
NotImplementedError
(
'unis ndim should be 1'
,
unis
.
ndim
)
if
self
.
odtype
==
'auto'
:
if
self
.
odtype
==
'auto'
:
odtype
=
pvals
.
dtype
if
sys
.
maxsize
>
2
**
32
:
odtype
=
'int64'
else
:
odtype
=
'int32'
else
:
else
:
odtype
=
self
.
odtype
odtype
=
self
.
odtype
out
=
T
.
tensor
(
dtype
=
odtype
,
broadcastable
=
pvals
.
type
.
broadcastable
)
out
=
T
.
tensor
(
dtype
=
odtype
,
broadcastable
=
pvals
.
type
.
broadcastable
)
...
@@ -241,8 +245,12 @@ class WeightedSelectionFromUniform(Op):
...
@@ -241,8 +245,12 @@ class WeightedSelectionFromUniform(Op):
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
sys
.
maxsize
>
2
**
32
:
odtype
=
'int64'
else
:
odtype
=
'int32'
if
z
[
0
]
is
None
or
not
numpy
.
all
(
z
[
0
]
.
shape
==
[
pvals
.
shape
[
0
],
n_samples
]):
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
=
'int'
)
z
[
0
]
=
-
1
*
numpy
.
ones
((
pvals
.
shape
[
0
],
n_samples
),
dtype
=
odtype
)
nb_multi
=
pvals
.
shape
[
0
]
nb_multi
=
pvals
.
shape
[
0
]
nb_outcomes
=
pvals
.
shape
[
1
]
nb_outcomes
=
pvals
.
shape
[
1
]
...
...
theano/sandbox/tests/test_weighted_select.py
浏览文件 @
aef8cd99
...
@@ -19,6 +19,7 @@ class test_OP(unittest.TestCase):
...
@@ -19,6 +19,7 @@ class test_OP(unittest.TestCase):
f
=
function
([
p
,
u
,
n
],
m
,
allow_input_downcast
=
True
)
f
=
function
([
p
,
u
,
n
],
m
,
allow_input_downcast
=
True
)
n_elements
=
1000
n_elements
=
1000
all_indices
=
range
(
n_elements
)
numpy
.
random
.
seed
(
12345
)
numpy
.
random
.
seed
(
12345
)
for
i
in
[
5
,
10
,
50
,
100
,
500
,
n_elements
]:
for
i
in
[
5
,
10
,
50
,
100
,
500
,
n_elements
]:
uni
=
numpy
.
random
.
rand
(
i
)
.
astype
(
config
.
floatX
)
uni
=
numpy
.
random
.
rand
(
i
)
.
astype
(
config
.
floatX
)
...
@@ -27,7 +28,7 @@ class test_OP(unittest.TestCase):
...
@@ -27,7 +28,7 @@ class test_OP(unittest.TestCase):
res
=
f
(
pvals
,
uni
,
i
)
res
=
f
(
pvals
,
uni
,
i
)
res
=
numpy
.
squeeze
(
res
)
res
=
numpy
.
squeeze
(
res
)
assert
len
(
res
)
==
i
assert
len
(
res
)
==
i
assert
numpy
.
all
(
numpy
.
in1d
(
numpy
.
unique
(
res
),
r
es
)),
res
assert
numpy
.
all
(
numpy
.
in1d
(
numpy
.
unique
(
res
),
all_indic
es
)),
res
def
test_fail_select_alot
(
self
):
def
test_fail_select_alot
(
self
):
"""
"""
...
@@ -63,13 +64,13 @@ class test_OP(unittest.TestCase):
...
@@ -63,13 +64,13 @@ class test_OP(unittest.TestCase):
n_elements
=
100
n_elements
=
100
n_selected
=
10
n_selected
=
10
mean_rtol
=
0.0
4
mean_rtol
=
0.0
005
numpy
.
random
.
seed
(
12345
)
numpy
.
random
.
seed
(
12345
)
pvals
=
numpy
.
random
.
randint
(
1
,
100
,
(
1
,
n_elements
))
.
astype
(
config
.
floatX
)
pvals
=
numpy
.
random
.
randint
(
1
,
100
,
(
1
,
n_elements
))
.
astype
(
config
.
floatX
)
pvals
/=
pvals
.
sum
(
1
)
pvals
/=
pvals
.
sum
(
1
)
avg_pvals
=
numpy
.
zeros
((
n_elements
,))
avg_pvals
=
numpy
.
zeros
((
n_elements
,))
for
rep
in
range
(
1000
):
for
rep
in
range
(
1000
0
):
uni
=
numpy
.
random
.
rand
(
n_selected
)
.
astype
(
config
.
floatX
)
uni
=
numpy
.
random
.
rand
(
n_selected
)
.
astype
(
config
.
floatX
)
res
=
f
(
pvals
,
uni
,
n_selected
)
res
=
f
(
pvals
,
uni
,
n_selected
)
res
=
numpy
.
squeeze
(
res
)
res
=
numpy
.
squeeze
(
res
)
...
@@ -93,6 +94,7 @@ class test_function(unittest.TestCase):
...
@@ -93,6 +94,7 @@ class test_function(unittest.TestCase):
f
=
function
([
p
,
n
],
m
,
allow_input_downcast
=
True
)
f
=
function
([
p
,
n
],
m
,
allow_input_downcast
=
True
)
n_elements
=
1000
n_elements
=
1000
all_indices
=
range
(
n_elements
)
numpy
.
random
.
seed
(
12345
)
numpy
.
random
.
seed
(
12345
)
for
i
in
[
5
,
10
,
50
,
100
,
500
,
n_elements
]:
for
i
in
[
5
,
10
,
50
,
100
,
500
,
n_elements
]:
pvals
=
numpy
.
random
.
randint
(
1
,
100
,
(
1
,
n_elements
))
.
astype
(
config
.
floatX
)
pvals
=
numpy
.
random
.
randint
(
1
,
100
,
(
1
,
n_elements
))
.
astype
(
config
.
floatX
)
...
@@ -100,7 +102,7 @@ class test_function(unittest.TestCase):
...
@@ -100,7 +102,7 @@ class test_function(unittest.TestCase):
res
=
f
(
pvals
,
i
)
res
=
f
(
pvals
,
i
)
res
=
numpy
.
squeeze
(
res
)
res
=
numpy
.
squeeze
(
res
)
assert
len
(
res
)
==
i
assert
len
(
res
)
==
i
assert
numpy
.
all
(
numpy
.
in1d
(
numpy
.
unique
(
res
),
r
es
)),
res
assert
numpy
.
all
(
numpy
.
in1d
(
numpy
.
unique
(
res
),
all_indic
es
)),
res
def
test_fail_select_alot
(
self
):
def
test_fail_select_alot
(
self
):
"""
"""
...
@@ -137,13 +139,13 @@ class test_function(unittest.TestCase):
...
@@ -137,13 +139,13 @@ class test_function(unittest.TestCase):
n_elements
=
100
n_elements
=
100
n_selected
=
10
n_selected
=
10
mean_rtol
=
0.0
4
mean_rtol
=
0.0
005
numpy
.
random
.
seed
(
12345
)
numpy
.
random
.
seed
(
12345
)
pvals
=
numpy
.
random
.
randint
(
1
,
100
,
(
1
,
n_elements
))
.
astype
(
config
.
floatX
)
pvals
=
numpy
.
random
.
randint
(
1
,
100
,
(
1
,
n_elements
))
.
astype
(
config
.
floatX
)
pvals
/=
pvals
.
sum
(
1
)
pvals
/=
pvals
.
sum
(
1
)
avg_pvals
=
numpy
.
zeros
((
n_elements
,))
avg_pvals
=
numpy
.
zeros
((
n_elements
,))
for
rep
in
range
(
1000
):
for
rep
in
range
(
1000
0
):
res
=
f
(
pvals
,
n_selected
)
res
=
f
(
pvals
,
n_selected
)
res
=
numpy
.
squeeze
(
res
)
res
=
numpy
.
squeeze
(
res
)
avg_pvals
[
res
]
+=
1
avg_pvals
[
res
]
+=
1
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论