Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
3eb2781b
提交
3eb2781b
authored
1月 14, 2008
作者:
Olivier Breuleux
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
bla
上级
51b37947
显示空白字符变更
内嵌
并排
正在显示
1 个修改的文件
包含
48 行增加
和
32 行删除
+48
-32
test.py
test.py
+48
-32
没有找到文件。
test.py
浏览文件 @
3eb2781b
...
@@ -131,53 +131,69 @@ import grad
...
@@ -131,53 +131,69 @@ import grad
############################
############################
#
def dataset_1hot(x, targ, n):
def
dataset_1hot
(
x
,
targ
,
n
):
#
"""Return an looping iterator over 1-hot vectors
"""Return an looping iterator over 1-hot vectors
#
This function is a generator for the integers range(n) that works by
This function is a generator for the integers range(n) that works by
#
side-effect on the numpy ndarray mat.
side-effect on the numpy ndarray mat.
#
On each iteration, mat is set (in-place) to the next element of an infinite
On each iteration, mat is set (in-place) to the next element of an infinite
#
sequence of 1-hot vectors.
sequence of 1-hot vectors.
#
"""
"""
#
assert targ.size == 1
assert
targ
.
size
==
1
#
for i in xrange(n):
for
i
in
xrange
(
n
):
#
idx = i % x.shape[1]
idx
=
i
%
x
.
shape
[
1
]
#
x[:] = 0
x
[:]
=
0
#
x[0,idx] = 1
x
[
0
,
idx
]
=
1
#
targ[0] = idx
targ
[
0
]
=
idx
#
yield i
yield
i
#
class sigmoid(core.omega_op):
class
sigmoid
(
core
.
omega_op
):
#
def impl(x):
def
impl
(
x
):
#
return 1.0 / (1.0 + numpy.exp(-x))
return
1.0
/
(
1.0
+
numpy
.
exp
(
-
x
))
#
def grad(x, gz):
def
grad
(
x
,
gz
):
#
return gz * sigmoid(x) * (1 - sigmoid(x))
return
gz
*
sigmoid
(
x
)
*
(
1
-
sigmoid
(
x
))
# x = core.zeros((1, 10))
# x = core.zeros((1, 10))
# w = core.input(numpy.random.rand(10, 15))
# w = core.input(numpy.random.rand(10, 15))
# #print x.data, w.data
x
=
numpy
.
zeros
((
1
,
10
))
w
=
numpy
.
random
.
rand
(
10
,
15
)
# def autoassociator(w, x):
#print x.data, w.data
# forward = sigmoid(core.dot(sigmoid(core.dot(x, w)), w.T))
# rec_error = core.sum(core.sqr(x - forward))
import
inspect
# w -= 0.1 * grad.grad(rec_error, w)
# return w, rec_error
def
omega_compile
(
f
):
args
,
varargs
,
kwargs
,
defaults
=
inspect
.
getargspec
(
f
)
assert
not
varargs
assert
not
kwargs
def
ret
(
*
args
):
outputs
=
core
.
build
(
f
,
*
args
)
return
compile
.
prog
(
args
,
outputs
)
return
ret
@omega_compile
def
autoassociator
(
w
,
x
):
forward
=
sigmoid
(
core
.
dot
(
sigmoid
(
core
.
dot
(
x
,
w
)),
w
.
T
))
rec_error
=
core
.
sum
(
core
.
sqr
(
x
-
forward
))
w
-=
0.1
*
grad
.
grad
(
rec_error
,
w
)
return
w
,
rec_error
# w2, rec_error = core.build(autoassociator, w, x)
# w2, rec_error = core.build(autoassociator, w, x)
# f = compile.to_func([w, x], [w2, rec_error])
# #f = compile.to_func([w, x], [w2, rec_error])
# f = compile.single(w2, rec_error)
#
for i in dataset_1hot(x.data, numpy.ndarray((1, )), 10000):
for
i
in
dataset_1hot
(
x
.
data
,
numpy
.
ndarray
((
1
,
)),
10000
):
# w2, rec_error = f(
w.data, x.data)
w2
,
rec_error
=
f
()
#
w.data, x.data)
#
if not(i % 1000):
if
not
(
i
%
1000
):
#
print rec_error
print
rec_error
#
print "done!"
print
"done!"
#
print w.data
print
w
.
data
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论