Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
b34a04b9
提交
b34a04b9
authored
1月 15, 2010
作者:
James Bergstra
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
moving solve to sandbox
上级
0d8780b9
隐藏空白字符变更
内嵌
并排
正在显示
3 个修改的文件
包含
44 行增加
和
41 行删除
+44
-41
solve.py
theano/sandbox/solve.py
+44
-0
nnet.py
theano/tensor/nnet.py
+0
-26
test_nnet.py
theano/tensor/tests/test_nnet.py
+0
-15
没有找到文件。
theano/sandbox/solve.py
0 → 100644
浏览文件 @
b34a04b9
import
numpy
from
theano
import
gof
,
tensor
import
unittest
class
Solve
(
gof
.
Op
):
"""
Find the solution to the linear equation Ax=b,
where A is a 2d matrix and b is a 1d or 2d matrix.
It use numpy.solve to find the solution.
"""
def
make_node
(
self
,
A
,
b
):
if
not
isinstance
(
A
,
gof
.
Variable
)
or
not
A
.
type
==
tensor
.
matrix
()
.
type
:
raise
TypeError
(
"We expected that A had a matrix type"
)
if
not
isinstance
(
B
,
gof
.
Variable
)
or
not
B
.
type
==
tensor
.
matrix
()
.
type
:
raise
TypeError
(
"We expected that B had a matrix type"
)
node
=
gof
.
Apply
(
op
=
self
,
inputs
=
[
A
,
B
],
outputs
=
[
tensor
.
matrix
()])
return
node
def
perform
(
self
,
node
,
(
A
,
B
),
(
output
,
)):
ret
=
numpy
.
solve
(
A
,
B
)
output
[
0
]
=
ret
def
grad
(
self
,
(
theta
,
A
,
B
),
(
gtheta
,)):
raise
NotImplementedError
()
solve
=
Solve
()
class
T_solve
(
unittest
.
TestCase
):
def
setUp
(
self
):
self
.
rng
=
numpy
.
random
.
RandomState
(
utt
.
fetch_seed
(
666
))
def
test0
(
self
):
A
=
self
.
rng
.
randn
(
5
,
5
)
b
=
numpy
.
array
(
range
(
5
),
dtype
=
float
)
x
=
numpy
.
linalg
.
solve
(
A
,
b
)
Ax
=
numpy
.
dot
(
A
,
x
)
are
=
tensor
.
numeric_grad
.
abs_rel_err
(
Ax
,
b
)
self
.
failUnless
(
numpy
.
all
(
are
<
1.0e-5
),
(
are
,
Ax
,
b
))
#print A,b
#print numpy.dot(A,x)
theano/tensor/nnet.py
浏览文件 @
b34a04b9
...
...
@@ -1272,32 +1272,6 @@ prepend_scalar_to_each_row = Prepend_scalar_to_each_row()
prepend_0_to_each_row
=
Prepend_scalar_constant_to_each_row
(
0.
)
prepend_1_to_each_row
=
Prepend_scalar_constant_to_each_row
(
1.
)
class
solve
(
gof
.
Op
):
"""
Find the solution to the linear equation Ax=b,
where A is a 2d matrix and b is a 1d or 2d matrix.
It use numpy.solve to find the solution.
"""
def
make_node
(
self
,
A
,
b
):
if
not
isinstance
(
A
,
gof
.
Variable
)
or
not
A
.
type
==
tensor
.
matrix
()
.
type
:
raise
TypeError
(
"We expected that A had a matrix type"
)
if
not
isinstance
(
B
,
gof
.
Variable
)
or
not
B
.
type
==
tensor
.
matrix
()
.
type
:
raise
TypeError
(
"We expected that B had a matrix type"
)
node
=
gof
.
Apply
(
op
=
self
,
inputs
=
[
A
,
B
],
outputs
=
[
tensor
.
matrix
()])
return
node
def
perform
(
self
,
node
,
(
A
,
B
),
(
output
,
)):
ret
=
numpy
.
solve
(
A
,
B
)
output
[
0
]
=
ret
def
grad
(
self
,
(
theta
,
A
,
B
),
(
gtheta
,)):
raise
NotImplementedError
()
logsigm_to_softplus
=
gof
.
PatternSub
(
(
tensor
.
log
,
(
sigmoid
,
'x'
)),
(
tensor
.
neg
,
(
softplus
,
(
tensor
.
neg
,
'x'
))),
...
...
theano/tensor/tests/test_nnet.py
浏览文件 @
b34a04b9
...
...
@@ -108,21 +108,6 @@ class T_prepend(unittest.TestCase):
self
.
failUnless
(
my
.
shape
==
(
3
,
6
))
self
.
failUnless
(
numpy
.
all
(
my
[:,
0
]
==
5.0
))
class
T_solve
(
unittest
.
TestCase
):
def
setUp
(
self
):
self
.
rng
=
numpy
.
random
.
RandomState
(
utt
.
fetch_seed
(
666
))
def
test0
(
self
):
A
=
self
.
rng
.
randn
(
5
,
5
)
b
=
numpy
.
array
(
range
(
5
),
dtype
=
float
)
x
=
numpy
.
linalg
.
solve
(
A
,
b
)
Ax
=
numpy
.
dot
(
A
,
x
)
are
=
T
.
numeric_grad
.
abs_rel_err
(
Ax
,
b
)
self
.
failUnless
(
numpy
.
all
(
are
<
1.0e-5
),
(
are
,
Ax
,
b
))
#print A,b
#print numpy.dot(A,x)
class
T_CrossentropyCategorical1Hot
(
unittest
.
TestCase
):
def
setUp
(
self
):
utt
.
seed_rng
()
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论