Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
3a890101
提交
3a890101
authored
8月 12, 2016
作者:
Faruk Ahmed
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
add ddof to var and std, apply Fred-fix to opt
上级
68290a96
隐藏空白字符变更
内嵌
并排
正在显示
3 个修改的文件
包含
31 行增加
和
7 行删除
+31
-7
basic.py
theano/tensor/basic.py
+18
-4
opt.py
theano/tensor/opt.py
+4
-3
test_basic.py
theano/tensor/tests/test_basic.py
+9
-0
没有找到文件。
theano/tensor/basic.py
浏览文件 @
3a890101
...
@@ -3099,7 +3099,7 @@ def mean(input, axis=None, dtype=None, op=False, keepdims=False,
...
@@ -3099,7 +3099,7 @@ def mean(input, axis=None, dtype=None, op=False, keepdims=False,
@constructor
@constructor
def
var
(
input
,
axis
=
None
,
keepdims
=
False
):
def
var
(
input
,
axis
=
None
,
ddof
=
0
,
keepdims
=
False
):
"""
"""
Computes the variance along the given axis(es) of a tensor `input`.
Computes the variance along the given axis(es) of a tensor `input`.
...
@@ -3108,6 +3108,8 @@ def var(input, axis=None, keepdims=False):
...
@@ -3108,6 +3108,8 @@ def var(input, axis=None, keepdims=False):
axis: None or int or (list of int) (see `Sum`)
axis: None or int or (list of int) (see `Sum`)
Compute the variance along this axis of the tensor.
Compute the variance along this axis of the tensor.
None means all axes (like numpy).
None means all axes (like numpy).
ddof: Degrees of freedom; 0 would compute the ML estimate, 1 would compute
the unbiased estimate.
keepdims : bool
keepdims : bool
If this is set to True, the axes which are reduced are
If this is set to True, the axes which are reduced are
left in the result as dimensions with size one. With this option,
left in the result as dimensions with size one. With this option,
...
@@ -3122,6 +3124,9 @@ def var(input, axis=None, keepdims=False):
...
@@ -3122,6 +3124,9 @@ def var(input, axis=None, keepdims=False):
"""
"""
if
isinstance
(
ddof
,
(
bool
)):
raise
ValueError
(
'Parameter keepdims is now at index 3: (input, axis=None, ddof=0, keepdims=False)'
)
input_ndim
=
input
.
type
.
ndim
input_ndim
=
input
.
type
.
ndim
if
axis
is
None
:
if
axis
is
None
:
axis
=
list
(
range
(
input_ndim
))
axis
=
list
(
range
(
input_ndim
))
...
@@ -3139,13 +3144,19 @@ def var(input, axis=None, keepdims=False):
...
@@ -3139,13 +3144,19 @@ def var(input, axis=None, keepdims=False):
centered_input
=
input
-
mean_input
centered_input
=
input
-
mean_input
# return the mean sqr
# return the mean sqr
v
=
mean
((
centered_input
**
2
),
axis
,
keepdims
=
keepdims
)
if
ddof
==
0
:
v
=
mean
((
centered_input
**
2
),
axis
,
keepdims
=
keepdims
)
else
:
shp
=
shape
(
input
)
-
ddof
v
=
sum
((
centered_input
**
2
),
axis
=
axis
,
keepdims
=
keepdims
)
for
i
in
axis
:
v
=
true_div
(
v
,
shp
[
i
])
v
.
name
=
'var'
v
.
name
=
'var'
return
v
return
v
@constructor
@constructor
def
std
(
input
,
axis
=
None
,
keepdims
=
False
):
def
std
(
input
,
axis
=
None
,
ddof
=
0
,
keepdims
=
False
):
"""
"""
Computes the standard deviation along the given axis(es) of a tensor `input`.
Computes the standard deviation along the given axis(es) of a tensor `input`.
...
@@ -3169,7 +3180,10 @@ def std(input, axis=None, keepdims=False):
...
@@ -3169,7 +3180,10 @@ def std(input, axis=None, keepdims=False):
"""
"""
ret
=
sqrt
(
var
(
input
=
input
,
axis
=
axis
,
keepdims
=
keepdims
))
if
isinstance
(
ddof
,
(
bool
)):
raise
ValueError
(
'Parameter keepdims is now at index 3: (input, axis=None, ddof=0, keepdims=False)'
)
ret
=
sqrt
(
var
(
input
=
input
,
axis
=
axis
,
ddof
=
ddof
,
keepdims
=
keepdims
))
ret
.
name
=
'std'
ret
.
name
=
'std'
return
ret
return
ret
...
...
theano/tensor/opt.py
浏览文件 @
3a890101
...
@@ -1902,17 +1902,17 @@ def local_subtensor_make_vector(node):
...
@@ -1902,17 +1902,17 @@ def local_subtensor_make_vector(node):
ret
=
[
x
.
owner
.
inputs
[
v
]]
ret
=
[
x
.
owner
.
inputs
[
v
]]
except
IndexError
:
except
IndexError
:
raise
NotScalarConstantError
(
"Bad user graph!"
)
raise
NotScalarConstantError
(
"Bad user graph!"
)
return
ret
return
ret
except
NotScalarConstantError
:
except
NotScalarConstantError
:
pass
pass
elif
idx
.
ndim
==
1
and
isinstance
(
idx
,
T
.
Constant
):
elif
idx
.
ndim
==
1
and
isinstance
(
idx
,
T
.
Constant
):
values
=
list
(
map
(
int
,
list
(
idx
.
value
)))
values
=
list
(
map
(
int
,
list
(
idx
.
value
)))
ret
=
[
make_vector
(
*
[
x
.
owner
.
inputs
[
v
]
for
v
in
values
])]
ret
=
make_vector
(
*
[
x
.
owner
.
inputs
[
v
]
for
v
in
values
])
# Copy over stack trace from previous output to new output
# Copy over stack trace from previous output to new output
copy_stack_trace
(
node
.
outputs
[
0
],
ret
)
copy_stack_trace
(
node
.
outputs
[
0
],
ret
)
return
ret
ret
=
T
.
patternbroadcast
(
ret
,
node
.
outputs
[
0
]
.
broadcastable
)
return
[
ret
]
else
:
else
:
raise
TypeError
(
'case not expected'
)
raise
TypeError
(
'case not expected'
)
elif
isinstance
(
idx
,
slice
):
elif
isinstance
(
idx
,
slice
):
...
@@ -1925,6 +1925,7 @@ def local_subtensor_make_vector(node):
...
@@ -1925,6 +1925,7 @@ def local_subtensor_make_vector(node):
ret
=
make_vector
(
*
x
.
owner
.
inputs
[
const_slice
])
ret
=
make_vector
(
*
x
.
owner
.
inputs
[
const_slice
])
# Copy over stack trace from previous outputs to new output
# Copy over stack trace from previous outputs to new output
copy_stack_trace
(
node
.
outputs
,
ret
)
copy_stack_trace
(
node
.
outputs
,
ret
)
ret
=
T
.
patternbroadcast
(
ret
,
node
.
outputs
[
0
]
.
broadcastable
)
return
[
ret
]
return
[
ret
]
except
NotScalarConstantError
:
except
NotScalarConstantError
:
pass
pass
...
...
theano/tensor/tests/test_basic.py
浏览文件 @
3a890101
...
@@ -6332,6 +6332,15 @@ def test_var():
...
@@ -6332,6 +6332,15 @@ def test_var():
f
=
function
([
a
],
var
(
a
,
axis
=
2
))
f
=
function
([
a
],
var
(
a
,
axis
=
2
))
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
,
axis
=
0
,
ddof
=
0
))
assert
numpy
.
allclose
(
numpy
.
var
(
a_val
,
axis
=
0
,
ddof
=
0
),
f
(
a_val
))
f
=
function
([
a
],
var
(
a
,
axis
=
1
,
ddof
=
1
))
assert
numpy
.
allclose
(
numpy
.
var
(
a_val
,
axis
=
1
,
ddof
=
1
),
f
(
a_val
))
f
=
function
([
a
],
var
(
a
,
axis
=
2
,
ddof
=
1
))
assert
numpy
.
allclose
(
numpy
.
var
(
a_val
,
axis
=
2
,
ddof
=
1
),
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
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论