Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
bebe79eb
提交
bebe79eb
authored
7月 11, 2016
作者:
Kumar Krishna Agrawal
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Updated documentation, added test
上级
4390245e
隐藏空白字符变更
内嵌
并排
正在显示
2 个修改的文件
包含
19 行增加
和
13 行删除
+19
-13
basic.py
theano/tensor/basic.py
+3
-1
test_basic.py
theano/tensor/tests/test_basic.py
+16
-12
没有找到文件。
theano/tensor/basic.py
浏览文件 @
bebe79eb
...
@@ -3142,11 +3142,13 @@ def var(input, axis=None, keepdims=False, corrected=False):
...
@@ -3142,11 +3142,13 @@ def var(input, axis=None, keepdims=False, corrected=False):
corrected : bool
corrected : bool
If this is set to True, the 'corrected_two_pass' algorithm is
If this is set to True, the 'corrected_two_pass' algorithm is
used to compute the variance.
used to compute the variance.
Refer : http://www.cs.yale.edu/publications/techreports/tr222.pdf
Notes
Notes
-----
-----
It
uses the two-pass algorithm for more stable results.
By default,
uses the two-pass algorithm for more stable results.
https://en.wikipedia.org/wiki/Algorithms_for_calculating_variance#Two-pass_algorithm
https://en.wikipedia.org/wiki/Algorithms_for_calculating_variance#Two-pass_algorithm
Also supports 'corrected_two_pass' algorithm, as mentioned above.
There exist other implementations that are even more stable, but probably
There exist other implementations that are even more stable, but probably
slower.
slower.
...
...
theano/tensor/tests/test_basic.py
浏览文件 @
bebe79eb
...
@@ -3609,16 +3609,16 @@ class T_Join_and_Split(unittest.TestCase):
...
@@ -3609,16 +3609,16 @@ class T_Join_and_Split(unittest.TestCase):
f
=
function
([
a
,
b
],
s
,
mode
=
self
.
mode
)
f
=
function
([
a
,
b
],
s
,
mode
=
self
.
mode
)
v
=
numpy
.
zeros
((
2
,
3
,
2
))
v
=
numpy
.
zeros
((
2
,
3
,
2
))
v
[:,:,
0
]
=
v1
v
[:,:,
0
]
=
v1
v
[:,:,
1
]
=
v2
v
[:,:,
1
]
=
v2
out
=
f
(
v1
,
v2
)
out
=
f
(
v1
,
v2
)
self
.
assertTrue
(
v
.
shape
==
out
.
shape
)
self
.
assertTrue
(
v
.
shape
==
out
.
shape
)
self
.
assertTrue
(
numpy
.
all
(
v
==
out
))
self
.
assertTrue
(
numpy
.
all
(
v
==
out
))
s
=
stack
([
a
,
b
],
axis
=-
2
)
s
=
stack
([
a
,
b
],
axis
=-
2
)
f
=
function
([
a
,
b
],
s
,
mode
=
self
.
mode
)
f
=
function
([
a
,
b
],
s
,
mode
=
self
.
mode
)
v
=
numpy
.
zeros
((
2
,
2
,
3
))
v
=
numpy
.
zeros
((
2
,
2
,
3
))
v
[:,
0
,:]
=
v1
v
[:,
0
,:]
=
v1
v
[:,
1
,:]
=
v2
v
[:,
1
,:]
=
v2
out
=
f
(
v1
,
v2
)
out
=
f
(
v1
,
v2
)
self
.
assertTrue
(
v
.
shape
==
out
.
shape
)
self
.
assertTrue
(
v
.
shape
==
out
.
shape
)
self
.
assertTrue
(
numpy
.
all
(
v
==
out
))
self
.
assertTrue
(
numpy
.
all
(
v
==
out
))
# Testing out-of-bounds axis
# Testing out-of-bounds axis
...
@@ -5437,7 +5437,7 @@ def test_tile():
...
@@ -5437,7 +5437,7 @@ def test_tile():
# Test 1,2,3,4-dimensional cases.
# Test 1,2,3,4-dimensional cases.
# Test input x has the shape [2], [2, 4], [2, 4, 3], [2, 4, 3, 5].
# Test input x has the shape [2], [2, 4], [2, 4, 3], [2, 4, 3, 5].
test_shape
=
[
2
,
4
,
3
,
5
]
test_shape
=
[
2
,
4
,
3
,
5
]
k
=
0
k
=
0
for
xtype
in
[
vector
(),
matrix
(),
tensor3
(),
tensor4
()]:
for
xtype
in
[
vector
(),
matrix
(),
tensor3
(),
tensor4
()]:
x
=
xtype
x
=
xtype
k
=
k
+
1
k
=
k
+
1
...
@@ -5495,7 +5495,7 @@ def test_tile():
...
@@ -5495,7 +5495,7 @@ def test_tile():
reps_
=
r
[:
k
-
1
]
reps_
=
r
[:
k
-
1
]
f
=
function
([
x
],
tile
(
x
,
reps_
,
ndim_
))
f
=
function
([
x
],
tile
(
x
,
reps_
,
ndim_
))
assert
numpy
.
all
(
f
(
x_
)
==
numpy
.
tile
(
x_
,
[
1
,
1
]
+
reps_
))
assert
numpy
.
all
(
f
(
x_
)
==
numpy
.
tile
(
x_
,
[
1
,
1
]
+
reps_
))
# error raising test: ndim not specified when reps is vector
# error raising test: ndim not specified when reps is vector
reps
=
ivector
()
reps
=
ivector
()
numpy
.
testing
.
assert_raises
(
ValueError
,
tile
,
x
,
reps
)
numpy
.
testing
.
assert_raises
(
ValueError
,
tile
,
x
,
reps
)
...
@@ -5503,7 +5503,7 @@ def test_tile():
...
@@ -5503,7 +5503,7 @@ def test_tile():
# error raising test: not a integer
# error raising test: not a integer
for
reps
in
[
2.5
,
fscalar
(),
fvector
()]:
for
reps
in
[
2.5
,
fscalar
(),
fvector
()]:
numpy
.
testing
.
assert_raises
(
ValueError
,
tile
,
x
,
reps
)
numpy
.
testing
.
assert_raises
(
ValueError
,
tile
,
x
,
reps
)
# error raising test: the dimension of reps exceeds 1
# error raising test: the dimension of reps exceeds 1
reps
=
imatrix
()
reps
=
imatrix
()
numpy
.
testing
.
assert_raises
(
ValueError
,
tile
,
x
,
reps
)
numpy
.
testing
.
assert_raises
(
ValueError
,
tile
,
x
,
reps
)
...
@@ -5514,14 +5514,14 @@ def test_tile():
...
@@ -5514,14 +5514,14 @@ def test_tile():
if
k
>
1
:
if
k
>
1
:
ndim
=
k
-
1
ndim
=
k
-
1
numpy
.
testing
.
assert_raises
(
ValueError
,
tile
,
x
,
reps
,
ndim
)
numpy
.
testing
.
assert_raises
(
ValueError
,
tile
,
x
,
reps
,
ndim
)
# error raising test: reps is list, len(reps) > ndim
# error raising test: reps is list, len(reps) > ndim
r
=
[
2
,
3
,
4
,
5
,
6
]
r
=
[
2
,
3
,
4
,
5
,
6
]
reps
=
r
[:
k
+
1
]
reps
=
r
[:
k
+
1
]
ndim
=
k
ndim
=
k
numpy
.
testing
.
assert_raises
(
ValueError
,
tile
,
x
,
reps
,
ndim
)
numpy
.
testing
.
assert_raises
(
ValueError
,
tile
,
x
,
reps
,
ndim
)
# error raising test:
# error raising test:
# reps is tensor.vector and len(reps_value) > ndim,
# reps is tensor.vector and len(reps_value) > ndim,
# reps_value is the real value when excuting the function.
# reps_value is the real value when excuting the function.
reps
=
ivector
()
reps
=
ivector
()
...
@@ -6319,8 +6319,6 @@ def test_var():
...
@@ -6319,8 +6319,6 @@ def test_var():
f
=
function
([
a
],
var
(
a
))
f
=
function
([
a
],
var
(
a
))
a_val
=
numpy
.
arange
(
60
)
.
reshape
(
3
,
4
,
5
)
a_val
=
numpy
.
arange
(
60
)
.
reshape
(
3
,
4
,
5
)
# print numpy.var(a_val)
# print f(a_val)
assert
numpy
.
allclose
(
numpy
.
var
(
a_val
),
f
(
a_val
))
assert
numpy
.
allclose
(
numpy
.
var
(
a_val
),
f
(
a_val
))
f
=
function
([
a
],
var
(
a
,
axis
=
0
))
f
=
function
([
a
],
var
(
a
,
axis
=
0
))
...
@@ -6333,7 +6331,13 @@ def test_var():
...
@@ -6333,7 +6331,13 @@ def test_var():
assert
numpy
.
allclose
(
numpy
.
var
(
a_val
,
axis
=
2
),
f
(
a_val
))
assert
numpy
.
allclose
(
numpy
.
var
(
a_val
,
axis
=
2
),
f
(
a_val
))
f
=
function
([
a
],
var
(
a
,
corrected
=
True
))
f
=
function
([
a
],
var
(
a
,
corrected
=
True
))
assert
numpy
.
allclose
(
numpy
.
var
(
a_val
),
f
(
a_val
))
mean_a
=
numpy
.
mean
(
a_val
)
centered_a
=
a_val
-
mean_a
v
=
numpy
.
mean
(
centered_a
**
2
)
error
=
(
numpy
.
mean
(
centered_a
))
**
2
v
=
v
-
error
assert
numpy
.
allclose
(
v
,
f
(
a_val
))
class
T_sum
(
unittest
.
TestCase
):
class
T_sum
(
unittest
.
TestCase
):
def
test_sum_overflow
(
self
):
def
test_sum_overflow
(
self
):
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论