Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
85438346
提交
85438346
authored
3月 19, 2012
作者:
Olivier Delalleau
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #552 from nouiz/err_size
Make MRG random generator raise an error when there is bad size gived.
上级
58c73c21
d6479fdb
隐藏空白字符变更
内嵌
并排
正在显示
4 个修改的文件
包含
34 行增加
和
4 行删除
+34
-4
NEWS.txt
NEWS.txt
+2
-0
dev_start_guide.txt
doc/dev_start_guide.txt
+1
-1
rng_mrg.py
theano/sandbox/rng_mrg.py
+14
-3
test_rng_mrg.py
theano/sandbox/test_rng_mrg.py
+17
-0
没有找到文件。
NEWS.txt
浏览文件 @
85438346
...
...
@@ -32,6 +32,8 @@ New Features
* If you use Enthought Python Distribution (EPD) now we use its blas
implementation by default (tested on Linux and Windows)
(Frederic B., Simon McGregor)
* MRG random now raises an error with a clear message when the passed shape
contains dimensions with bad value like 0. (Frédéric B. reported by Ian G.)
Sparse Sandbox graduate
* Remove0 op: it removes stored elements with value 0. (Frederic B.)
...
...
doc/dev_start_guide.txt
浏览文件 @
85438346
...
...
@@ -357,7 +357,7 @@ Then in your ``~/.emacs`` file, add this:
;; Next two lines are the checks to do. You can add more if you wish.
(epy-setup-checker "pyflakes %f") ;; For python syntax check
(epy-setup-checker "pep8 %f") ;; For pep8 check
(epy-setup-checker "pep8
-r
%f") ;; For pep8 check
...
...
theano/sandbox/rng_mrg.py
浏览文件 @
85438346
...
...
@@ -14,7 +14,7 @@ from theano.tensor import (raw_random, TensorType, as_tensor_variable,
from
theano.tensor
import
zeros_like
,
sqrt
,
log
,
sin
,
cos
,
join
,
prod
from
theano.compile
import
optdb
from
theano.gof
import
local_optimizer
from
theano.gof.python25
import
all
from
theano.gof.python25
import
all
,
any
import
multinomial
...
...
@@ -730,6 +730,11 @@ class MRG_RandomStreams(object):
msg
=
"size must be a tuple of int or a Theano variable"
assert
all
([
isinstance
(
i
,
int
)
or
isinstance
(
i
,
Variable
)
for
i
in
size
]),
msg
if
any
([
isinstance
(
i
,
int
)
and
i
<=
0
for
i
in
size
]):
raise
ValueError
(
"The specified size contains a dimension with value <= 0"
,
size
)
else
:
msg
=
"size must be a tuple of int or a Theano variable"
assert
isinstance
(
size
,
Variable
)
and
size
.
ndim
==
1
,
msg
...
...
@@ -786,8 +791,8 @@ class MRG_RandomStreams(object):
Sample `n` (currently `n` needs to be 1) times from a multinomial
distribution defined by probabilities pvals.
Example : pvals = [[.98,
.01, .01], [.01, .98 .01]] will probably result
in [[1,0,0],[0,1,0]].
Example : pvals = [[.98,
.01, .01], [.01, .98, .01]] will
probably result
in [[1,0,0],[0,1,0]].
.. note::
`size` and `ndim` are only there keep the same signature as other
...
...
@@ -797,6 +802,12 @@ class MRG_RandomStreams(object):
if
pvals
is
None
:
raise
TypeError
(
"You have to specify pvals"
)
pvals
=
as_tensor_variable
(
pvals
)
if
size
is
not
None
:
if
any
([
isinstance
(
i
,
int
)
and
i
<=
0
for
i
in
size
]):
raise
ValueError
(
"The specified size contains a dimension with value <= 0"
,
size
)
if
n
==
1
and
pvals
.
ndim
==
2
:
ndim
,
size
,
bcast
=
raw_random
.
_infer_ndim_bcast
(
ndim
,
size
,
pvals
[:,
0
])
...
...
theano/sandbox/test_rng_mrg.py
浏览文件 @
85438346
...
...
@@ -597,3 +597,20 @@ def test_multinomial():
sys
.
stdout
.
flush
()
basic_multinomialtest
(
f
,
steps
,
sample_size
,
pvals
,
prefix
=
'gpu mrg '
)
numpy
.
testing
.
assert_array_almost_equal
(
out
,
gpu_out
,
decimal
=
6
)
class
T_MRG
(
unittest
.
TestCase
):
def
test_bad_size
(
self
):
R
=
MRG_RandomStreams
(
234
,
use_cuda
=
False
)
for
size
in
[
(
0
,
100
),
(
-
1
,
100
),
(
1
,
0
),
]:
self
.
assertRaises
(
ValueError
,
R
.
uniform
,
size
)
self
.
assertRaises
(
ValueError
,
R
.
binomial
,
size
)
self
.
assertRaises
(
ValueError
,
R
.
multinomial
,
size
,
1
,
[])
self
.
assertRaises
(
ValueError
,
R
.
normal
,
size
)
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论