Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
a3d94ccd
提交
a3d94ccd
authored
5月 25, 2009
作者:
James Bergstra
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
added xlogy0 op
上级
546cf660
隐藏空白字符变更
内嵌
并排
正在显示
2 个修改的文件
包含
38 行增加
和
1 行删除
+38
-1
test_xlogx.py
theano/tensor/tests/test_xlogx.py
+14
-1
xlogx.py
theano/tensor/xlogx.py
+24
-0
没有找到文件。
theano/tensor/tests/test_xlogx.py
浏览文件 @
a3d94ccd
from
theano.tensor.xlogx
import
xlogx
from
theano.tensor.xlogx
import
xlogx
,
xlogy0
import
unittest
...
...
@@ -25,6 +25,19 @@ class T_XlogX(unittest.TestCase):
# return [xlogx(a)[:,2]]
utt
.
verify_grad
(
xlogx
,
[
numpy
.
random
.
rand
(
3
,
4
)])
class
T_XlogY0
(
unittest
.
TestCase
):
def
setUp
(
self
):
utt
.
seed_rng
()
def
test2
(
self
):
utt
.
verify_grad
(
xlogy0
,
[
numpy
.
random
.
rand
(
3
,
4
),
numpy
.
random
.
rand
(
3
,
4
)])
def
test3
(
self
):
x
=
as_tensor_variable
([
1
,
0
])
y
=
as_tensor_variable
([
1
,
0
])
z
=
xlogy0
(
x
,
y
)
f
=
theano
.
function
([],
z
)
self
.
failUnless
(
numpy
.
all
(
f
()
==
numpy
.
asarray
([
0
,
0.
])))
if
__name__
==
'__main__'
:
unittest
.
main
()
theano/tensor/xlogx.py
浏览文件 @
a3d94ccd
...
...
@@ -26,3 +26,27 @@ class XlogX(scalar.UnaryScalarOp):
scalar_xlogx
=
XlogX
(
scalar
.
upgrade_to_float
,
name
=
'scalar_xlogx'
)
xlogx
=
tensor
.
Elemwise
(
scalar_xlogx
,
name
=
'xlogx'
)
class
XlogY0
(
scalar
.
BinaryScalarOp
):
"""
Compute X * log(Y), with special case 0 log(0) = 0.
"""
@staticmethod
def
st_impl
(
x
,
y
):
if
x
==
0.0
:
return
0.0
return
x
*
numpy
.
log
(
y
)
def
impl
(
self
,
x
,
y
):
return
XlogY0
.
st_impl
(
x
,
y
)
def
grad
(
self
,
(
x
,
y
),
(
gz
,)):
return
[
gz
*
scalar
.
log
(
y
),
gz
*
x
/
y
]
def
c_code
(
self
,
node
,
name
,
(
x
,
y
),
(
z
,),
sub
):
if
node
.
inputs
[
0
]
.
type
in
[
scalar
.
float32
,
scalar
.
float64
]:
return
"""
%(z)
s =
%(x)
s == 0.0
? 0.0
:
%(x)
s * log(
%(y)
s);"""
%
locals
()
raise
NotImplementedError
(
'only floatingpoint is implemented'
)
scalar_xlogy0
=
XlogY0
(
scalar
.
upgrade_to_float
,
name
=
'scalar_xlogy0'
)
xlogy0
=
tensor
.
Elemwise
(
scalar_xlogy0
,
name
=
'xlogy0'
)
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论