Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
b18e0432
提交
b18e0432
authored
6月 08, 2012
作者:
jsalvatier
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
added new scipy functions
上级
c0d9f466
显示空白字符变更
内嵌
并排
正在显示
4 个修改的文件
包含
150 行增加
和
0 行删除
+150
-0
basic_scipy.py
theano/scalar/basic_scipy.py
+99
-0
basic.py
theano/tensor/basic.py
+8
-0
inplace.py
theano/tensor/inplace.py
+8
-0
test_basic.py
theano/tensor/tests/test_basic.py
+35
-0
没有找到文件。
theano/scalar/basic_scipy.py
浏览文件 @
b18e0432
...
@@ -61,3 +61,101 @@ class Erfc(UnaryScalarOp):
...
@@ -61,3 +61,101 @@ class Erfc(UnaryScalarOp):
# scipy.special.erfc don't support complex. Why?
# scipy.special.erfc don't support complex. Why?
erfc
=
Erfc
(
upgrade_to_float_no_complex
,
name
=
'erfc'
)
erfc
=
Erfc
(
upgrade_to_float_no_complex
,
name
=
'erfc'
)
class
GammaLn
(
UnaryScalarOp
):
"""
Log gamma function.
"""
@staticmethod
def
st_impl
(
x
):
return
special
.
gammaln
(
x
)
def
impl
(
self
,
x
):
return
GammaLn
.
st_impl
(
x
)
def
grad
(
self
,
inp
,
grads
):
x
,
=
inp
gz
,
=
grads
return
[
gz
*
scalar_psi
(
x
)]
def
c_code
(
self
,
node
,
name
,
inp
,
out
,
sub
):
x
,
=
inp
z
,
=
out
if
node
.
inputs
[
0
]
.
type
in
[
scalar
.
float32
,
scalar
.
float64
]:
return
"""
%(z)
s =
lgamma(
%(x)
s);"""
%
locals
()
raise
NotImplementedError
(
'only floatingpoint is implemented'
)
def
__eq__
(
self
,
other
):
return
type
(
self
)
==
type
(
other
)
def
__hash__
(
self
):
return
hash
(
type
(
self
))
gammaln
=
GammaLn
(
upgrade_to_float
,
name
=
'gammaln'
)
class
Psi
(
UnaryScalarOp
):
"""
Derivative of log gamma function.
"""
@staticmethod
def
st_impl
(
x
):
return
special
.
psi
(
x
)
def
impl
(
self
,
x
):
return
Psi
.
st_impl
(
x
)
#def grad() no gradient now
def
c_support_code
(
self
):
return
(
"""
#ifndef _PSIFUNCDEFINED
#define _PSIFUNCDEFINED
double _psi(double x){
/*taken from
Bernardo, J. M. (1976). Algorithm AS 103: Psi (Digamma) Function. Applied Statistics. 25 (3), 315-317.
http://www.uv.es/~bernardo/1976AppStatist.pdf */
double y, R, psi_ = 0;
double S = 1.0e-5;
double C = 8.5;
double S3 = 8.333333333e-2;
double S4 = 8.333333333e-3;
double S5 = 3.968253968e-3;
double D1 = -0.5772156649 ;
y = x;
if (y <= 0.0)
return psi_;
if (y <= S )
return D1 - 1.0/y;
while (y < C){
psi_ = psi_ - 1.0 / y;
y = y + 1;}
R = 1.0 / y;
psi_ = psi_ + log(y) - .5 * R ;
R= R*R;
psi_ = psi_ - R * (S3 - R * (S4 - R * S5));
return psi_;}
#endif
"""
)
def
c_code
(
self
,
node
,
name
,
inp
,
out
,
sub
):
x
,
=
inp
z
,
=
out
if
node
.
inputs
[
0
]
.
type
in
[
scalar
.
float32
,
scalar
.
float64
]:
return
"""
%(z)
s =
_psi(
%(x)
s);"""
%
locals
()
raise
NotImplementedError
(
'only floatingpoint is implemented'
)
def
__eq__
(
self
,
other
):
return
type
(
self
)
==
type
(
other
)
def
__hash__
(
self
):
return
hash
(
type
(
self
))
psi
=
Psi
(
upgrade_to_float
,
name
=
'psi'
)
ar
\ No newline at end of file
theano/tensor/basic.py
浏览文件 @
b18e0432
...
@@ -2639,6 +2639,14 @@ def erf(a):
...
@@ -2639,6 +2639,14 @@ def erf(a):
def
erfc
(
a
):
def
erfc
(
a
):
"""complementary error function"""
"""complementary error function"""
@_scal_elemwise
def
gammaln
(
a
):
"""log gamma function"""
@_scal_elemwise
def
psi
(
a
):
"""derivative of log gamma function"""
@_scal_elemwise_with_nfunc
(
'real'
,
1
,
-
1
)
@_scal_elemwise_with_nfunc
(
'real'
,
1
,
-
1
)
def
real
(
z
):
def
real
(
z
):
...
...
theano/tensor/inplace.py
浏览文件 @
b18e0432
...
@@ -203,6 +203,14 @@ def erf_inplace(a):
...
@@ -203,6 +203,14 @@ def erf_inplace(a):
def
erfc_inplace
(
a
):
def
erfc_inplace
(
a
):
"""complementary error function"""
"""complementary error function"""
@_scal_inplace
def
gammaln_inplace
(
a
):
"""log gamma function"""
@_scal_inplace
def
psi_inplace
(
a
):
"""derivative of log gamma function"""
@_scal_inplace
@_scal_inplace
def
second_inplace
(
a
):
def
second_inplace
(
a
):
"""Fill `a` with `b`"""
"""Fill `a` with `b`"""
...
...
theano/tensor/tests/test_basic.py
浏览文件 @
b18e0432
...
@@ -1234,6 +1234,9 @@ del _good_broadcast_unary_normal_no_int['integers']
...
@@ -1234,6 +1234,9 @@ del _good_broadcast_unary_normal_no_int['integers']
if
imported_scipy_special
:
if
imported_scipy_special
:
expected_erf
=
scipy
.
special
.
erf
expected_erf
=
scipy
.
special
.
erf
expected_erfc
=
scipy
.
special
.
erfc
expected_erfc
=
scipy
.
special
.
erfc
expected_gammaln
=
scipy
.
special
.
gammaln
expected_psi
=
scipy
.
special
.
psi
skip_scipy
=
False
skip_scipy
=
False
else
:
else
:
expected_erf
=
[]
expected_erf
=
[]
...
@@ -1272,6 +1275,38 @@ ErfcInplaceTester = makeBroadcastTester(op = inplace.erfc_inplace,
...
@@ -1272,6 +1275,38 @@ ErfcInplaceTester = makeBroadcastTester(op = inplace.erfc_inplace,
inplace
=
True
,
inplace
=
True
,
skip
=
skip_scipy
)
skip
=
skip_scipy
)
GammaLnTester
=
makeBroadcastTester
(
op
=
tensor
.
gammaln
,
expected
=
expected_gammaln
,
good
=
_good_broadcast_unary_normal_no_int_no_complex
,
grad
=
_grad_broadcast_unary_normal
,
eps
=
2e-10
,
mode
=
mode_no_scipy
,
skip
=
skip_scipy
)
GammaLnInplaceTester
=
makeBroadcastTester
(
op
=
inplace
.
gammaln_inplace
,
expected
=
expected_erfc
,
good
=
_good_broadcast_unary_normal_no_int_no_complex
,
grad
=
_grad_broadcast_unary_normal
,
eps
=
2e-10
,
mode
=
mode_no_scipy
,
inplace
=
True
,
skip
=
skip_scipy
)
PsiTester
=
makeBroadcastTester
(
op
=
tensor
.
psi
,
expected
=
expected_psi
,
good
=
_good_broadcast_unary_normal_no_int_no_complex
,
grad
=
_grad_broadcast_unary_normal
,
eps
=
2e-10
,
mode
=
mode_no_scipy
,
skip
=
skip_scipy
)
PsiInplaceTester
=
makeBroadcastTester
(
op
=
inplace
.
psi_inplace
,
expected
=
expected_psi
,
good
=
_good_broadcast_unary_normal_no_int_no_complex
,
grad
=
_grad_broadcast_unary_normal
,
eps
=
2e-10
,
mode
=
mode_no_scipy
,
inplace
=
True
,
skip
=
skip_scipy
)
ZerosLikeTester
=
makeBroadcastTester
(
ZerosLikeTester
=
makeBroadcastTester
(
op
=
tensor
.
zeros_like
,
op
=
tensor
.
zeros_like
,
expected
=
numpy
.
zeros_like
,
expected
=
numpy
.
zeros_like
,
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论