Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
47bd74da
提交
47bd74da
authored
10月 15, 2008
作者:
Olivier Breuleux
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
fixed elemwise bug and logistic_regression example
上级
d28f7c55
隐藏空白字符变更
内嵌
并排
正在显示
3 个修改的文件
包含
35 行增加
和
14 行删除
+35
-14
logistic_regression.py
examples/logistic_regression.py
+25
-13
module.py
theano/sandbox/module.py
+1
-1
elemwise.py
theano/tensor/elemwise.py
+9
-0
没有找到文件。
examples/logistic_regression.py
浏览文件 @
47bd74da
...
...
@@ -14,7 +14,7 @@ class LogisticRegressionN(module.FancyModule):
#self.component is the LogisticRegressionTemplate instance that built this guy.
self
.
w
=
N
.
random
.
randn
(
n_in
,
n_out
)
self
.
b
=
N
.
random
.
randn
(
n_out
)
self
.
b
=
N
.
random
.
randn
(
n_out
)
self
.
lr
=
0.01
def
__init__
(
self
,
x
=
None
,
targ
=
None
):
...
...
@@ -47,12 +47,13 @@ class LogisticRegression2(module.FancyModule):
self
.
w
=
N
.
random
.
randn
(
n_in
,
1
)
self
.
b
=
N
.
random
.
randn
(
1
)
self
.
lr
=
0.01
self
.
__hide__
=
[
'params'
]
def
__init__
(
self
,
x
=
None
,
targ
=
None
):
super
(
LogisticRegression2
,
self
)
.
__init__
()
#boilerplate
self
.
x
=
x
if
x
is
not
None
else
T
.
matrix
()
self
.
targ
=
targ
if
targ
is
not
None
else
T
.
l
vector
()
self
.
targ
=
targ
if
targ
is
not
None
else
T
.
l
col
()
self
.
w
=
module
.
Member
(
T
.
dmatrix
())
#automatically names
self
.
b
=
module
.
Member
(
T
.
dvector
())
#automatically names
...
...
@@ -62,27 +63,38 @@ class LogisticRegression2(module.FancyModule):
self
.
params
=
[
self
.
w
,
self
.
b
]
y
=
nnet_ops
.
sigmoid
(
T
.
dot
(
self
.
x
,
self
.
w
))
xent_elem
=
self
.
targ
*
T
.
log
(
y
)
-
(
1.0
-
self
.
targ
)
*
T
.
log
(
1.0
-
y
)
xent_elem
=
-
self
.
targ
*
T
.
log
(
y
)
-
(
1.0
-
self
.
targ
)
*
T
.
log
(
1.0
-
y
)
xent
=
T
.
sum
(
xent_elem
)
self
.
y
=
y
self
.
xent_elem
=
xent_elem
self
.
xent
=
xent
gparams
=
T
.
grad
(
xent
,
self
.
params
)
self
.
update
=
module
.
Method
([
self
.
x
,
self
.
targ
],
[
xent
,
self
.
w
,
gparams
[
0
]]
,
updates
=
dict
((
p
,
p
-
self
.
lr
*
g
)
for
p
,
g
in
zip
(
self
.
params
,
gparams
)))
self
.
update
=
module
.
Method
([
self
.
x
,
self
.
targ
],
xent
,
updates
=
dict
((
p
,
p
-
self
.
lr
*
g
)
for
p
,
g
in
zip
(
self
.
params
,
gparams
)))
self
.
apply
=
module
.
Method
([
self
.
x
],
T
.
argmax
(
T
.
dot
(
self
.
x
,
self
.
w
)
+
self
.
b
,
axis
=
1
))
if
__name__
==
'__main__'
:
lr
=
LogisticRegression2
()
.
make
(
10
,
mode
=
'FAST_COMPILE'
)
lr
c
=
LogisticRegression2
(
)
data_x
=
N
.
random
.
randn
(
10
,
10
)
data_y
=
(
N
.
random
.
randn
(
10
)
>
0
)
lr
=
lrc
.
make
(
10
,
mode
=
theano
.
Mode
(
'c|py'
,
'merge'
))
#'FAST_RUN')
data_x
=
N
.
random
.
randn
(
5
,
10
)
data_y
=
(
N
.
random
.
randn
(
5
,
1
)
>
0
)
print
lr
.
params
print
lr
.
w
.
shape
for
i
in
xrange
(
10
):
for
i
in
xrange
(
10000
):
xe
=
lr
.
update
(
data_x
,
data_y
)
print
N
.
sum
(
xe
),
lr
.
w
.
shape
if
i
%
100
==
0
:
print
i
,
xe
print
print
'TRAINED MODEL:'
print
lr
theano/sandbox/module.py
浏览文件 @
47bd74da
...
...
@@ -207,7 +207,7 @@ class Method(Component):
for
k
,
v
in
self
.
updates
.
iteritems
()]
outputs
=
self
.
outputs
_inputs
=
[
x
.
result
for
x
in
inputs
]
for
input
in
gof
.
graph
.
inputs
(
outputs
if
isinstance
(
outputs
,
(
list
,
tuple
))
else
[
outputs
]
for
input
in
gof
.
graph
.
inputs
(
(
list
(
outputs
)
if
isinstance
(
outputs
,
(
list
,
tuple
))
else
[
outputs
])
+
[
x
.
update
for
x
in
inputs
if
getattr
(
x
,
'update'
,
False
)],
blockers
=
_inputs
):
if
input
not
in
_inputs
and
not
isinstance
(
input
,
gof
.
Value
):
...
...
theano/tensor/elemwise.py
浏览文件 @
47bd74da
...
...
@@ -350,6 +350,15 @@ class Elemwise(Op):
return
ret
def
perform
(
self
,
node
,
inputs
,
output_storage
):
maxsize
=
max
(
len
(
input
.
shape
)
for
input
in
inputs
)
for
dims
in
zip
(
*
[[(
1
,
True
)]
*
(
maxsize
-
len
(
input
.
shape
))
+
zip
(
input
.
shape
,
sinput
.
type
.
broadcastable
)
for
input
,
sinput
in
zip
(
inputs
,
node
.
inputs
)]):
if
max
(
d
for
d
,
b
in
dims
)
!=
1
and
(
1
,
False
)
in
dims
:
raise
ValueError
(
'Dimension mismatch; shapes are
%
s'
%
', '
.
join
(
'(
%
s)'
%
', '
.
join
(
'*'
if
b
else
str
(
d
)
for
d
,
b
in
zip
(
input
.
shape
,
sinput
.
type
.
broadcastable
))
for
input
,
sinput
in
zip
(
inputs
,
node
.
inputs
)))
# Other mismatches will be caught by the ufunc
if
not
self
.
inplace_pattern
:
for
output
,
storage
in
zip
(
node
.
outputs
,
output_storage
):
odat
=
storage
[
0
]
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论