Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
a7f6171c
提交
a7f6171c
authored
11月 05, 2014
作者:
Pascal Lamblin
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #2225 from caglar/fix_grad_clip
Fixes #633
上级
01232098
5a134160
显示空白字符变更
内嵌
并排
正在显示
2 个修改的文件
包含
41 行增加
和
3 行删除
+41
-3
basic.py
theano/scalar/basic.py
+1
-1
test_basic.py
theano/scalar/tests/test_basic.py
+40
-2
没有找到文件。
theano/scalar/basic.py
浏览文件 @
a7f6171c
...
@@ -1792,7 +1792,7 @@ class Clip(ScalarOp):
...
@@ -1792,7 +1792,7 @@ class Clip(ScalarOp):
def
grad
(
self
,
(
x
,
mn
,
mx
),
(
gz
,
)):
def
grad
(
self
,
(
x
,
mn
,
mx
),
(
gz
,
)):
assert
gz
.
type
not
in
complex_types
assert
gz
.
type
not
in
complex_types
gx
=
((
x
>
mn
)
&
(
x
<
mx
))
*
gz
gx
=
((
x
>
=
mn
)
&
(
x
<=
mx
))
*
gz
gmn
=
(
x
<
mn
)
*
gz
gmn
=
(
x
<
mn
)
*
gz
gmx
=
(
x
>
mx
)
*
gz
gmx
=
(
x
>
mx
)
*
gz
...
...
theano/scalar/tests/test_basic.py
浏览文件 @
a7f6171c
...
@@ -14,13 +14,14 @@ import unittest
...
@@ -14,13 +14,14 @@ import unittest
import
theano
import
theano
from
theano.gof
import
FunctionGraph
from
theano.gof
import
FunctionGraph
from
theano
import
gof
from
theano
import
gof
from
theano.tests
import
unittest_tools
as
utt
from
theano.scalar.basic
import
(
floats
,
float32
,
float64
,
from
theano.scalar.basic
import
(
floats
,
float32
,
float64
,
ints
,
int8
,
int32
,
complex64
,
ints
,
int8
,
int32
,
complex64
,
ComplexError
,
IntDiv
,
TrueDiv
,
ComplexError
,
IntDiv
,
TrueDiv
,
Composite
,
add
,
div_proxy
,
Composite
,
add
,
div_proxy
,
clip
,
and_
,
eq
,
neq
,
invert
,
mul
)
and_
,
eq
,
neq
,
invert
,
mul
)
import
numpy
def
inputs
():
def
inputs
():
return
floats
(
'xyz'
)
return
floats
(
'xyz'
)
...
@@ -56,6 +57,43 @@ class test_ScalarOps(unittest.TestCase):
...
@@ -56,6 +57,43 @@ class test_ScalarOps(unittest.TestCase):
):
):
self
.
assertTrue
(
fn
(
a
,
b
)
==
a
%
b
,
(
a
,))
self
.
assertTrue
(
fn
(
a
,
b
)
==
a
%
b
,
(
a
,))
def
test_clip_grad
(
self
):
#This is testing for the issue #633
x
,
y
=
floats
(
'xy'
)
a
=
theano
.
tensor
.
clip
(
x
,
y
,
x
)
g
=
theano
.
gradient
.
grad
(
a
,
x
)
fn
=
gof
.
DualLinker
()
.
accept
(
FunctionGraph
([
x
,
y
],
[
g
]))
.
make_function
()
# Test the other way around as well
a2
=
theano
.
tensor
.
clip
(
x
,
x
,
y
)
g2
=
theano
.
gradient
.
grad
(
a2
,
x
)
fn2
=
gof
.
DualLinker
()
.
accept
(
FunctionGraph
([
x
,
y
],
[
g2
]))
.
make_function
()
# Test for the equal case too .
a3
=
theano
.
tensor
.
clip
(
x
,
x
,
x
)
g3
=
theano
.
gradient
.
grad
(
a3
,
x
)
fn3
=
gof
.
DualLinker
()
.
accept
(
FunctionGraph
([
x
],
[
g3
]))
.
make_function
()
rng
=
numpy
.
random
.
RandomState
(
utt
.
fetch_seed
())
ntests
=
50
for
i
in
xrange
(
ntests
):
xval
=
rng
.
rand
(
1
)
#To ensure that the min < x .
yval_mn
=
rng
.
rand
(
1
)
-
1.0
#To ensure that the max > x.
yval_mx
=
rng
.
rand
(
1
)
+
1.0
aval
=
fn
(
xval
,
yval_mn
)
aval2
=
fn2
(
xval
,
yval_mx
)
aval3
=
fn3
(
xval
)
self
.
assertTrue
(
aval
==
1.
)
self
.
assertTrue
(
aval2
==
1.
)
self
.
assertTrue
(
aval3
==
1.
)
class
test_composite
(
unittest
.
TestCase
):
class
test_composite
(
unittest
.
TestCase
):
def
test_straightforward
(
self
):
def
test_straightforward
(
self
):
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论