Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
3679d8e6
提交
3679d8e6
authored
11月 15, 2008
作者:
James Bergstra
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
fixed a few thinsg to make the the test_Klass_Advanced_example run
上级
d420b6ef
显示空白字符变更
内嵌
并排
正在显示
1 个修改的文件
包含
13 行增加
和
9 行删除
+13
-9
test_wiki.py
examples/tests/test_wiki.py
+13
-9
没有找到文件。
examples/tests/test_wiki.py
浏览文件 @
3679d8e6
...
@@ -48,10 +48,11 @@ class RegressionLayer(M.Module):
...
@@ -48,10 +48,11 @@ class RegressionLayer(M.Module):
self
.
apply
=
M
.
Method
(
input
,
self
.
prediction
)
self
.
apply
=
M
.
Method
(
input
,
self
.
prediction
)
def
params
(
self
):
def
params
(
self
):
return
self
.
w
,
self
.
b
return
self
.
w
,
self
.
b
def
initialize
(
self
,
obj
,
input_size
=
None
,
target_size
=
None
,
**
init
):
def
_instance_
initialize
(
self
,
obj
,
input_size
=
None
,
target_size
=
None
,
**
init
):
# obj is an "instance" of this module holding values for each member and
# obj is an "instance" of this module holding values for each member and
# functions for each method
# functions for each method
super
(
RegressionLayer
,
self
)
.
initialize
(
obj
,
**
init
)
#super(RegressionLayer, self).initialize(obj, **init)
# here we call the superclass's initialize method, which takes all the name: value
# here we call the superclass's initialize method, which takes all the name: value
# pairs in init and sets the property with that name to the provided value
# pairs in init and sets the property with that name to the provided value
# this covers setting stepsize, l2_coef; w and b can be set that way too
# this covers setting stepsize, l2_coef; w and b can be set that way too
...
@@ -60,6 +61,7 @@ class RegressionLayer(M.Module):
...
@@ -60,6 +61,7 @@ class RegressionLayer(M.Module):
sz
=
(
input_size
,
target_size
)
sz
=
(
input_size
,
target_size
)
obj
.
w
=
N
.
random
.
uniform
(
size
=
sz
,
low
=
-
0.5
,
high
=
0.5
)
obj
.
w
=
N
.
random
.
uniform
(
size
=
sz
,
low
=
-
0.5
,
high
=
0.5
)
obj
.
b
=
N
.
zeros
(
target_size
)
obj
.
b
=
N
.
zeros
(
target_size
)
obj
.
stepsize
=
0.01
def
build_regularization
(
self
):
def
build_regularization
(
self
):
return
T
.
zero
()
# no regularization!
return
T
.
zero
()
# no regularization!
...
@@ -69,7 +71,8 @@ class SoftmaxXERegression(RegressionLayer):
...
@@ -69,7 +71,8 @@ class SoftmaxXERegression(RegressionLayer):
def
build_prediction
(
self
):
def
build_prediction
(
self
):
return
NN
.
softmax
(
self
.
activation
)
return
NN
.
softmax
(
self
.
activation
)
def
build_classification_cost
(
self
,
target
):
def
build_classification_cost
(
self
,
target
):
self
.
classification_cost_matrix
=
target
*
T
.
log
(
self
.
prediction
)
+
(
1
-
target
)
*
T
.
log
(
1
-
self
.
prediction
)
#self.classification_cost_matrix = target * T.log(self.prediction) + (1 - target) * T.log(1 - self.prediction)
self
.
classification_cost_matrix
=
(
target
-
self
.
prediction
)
**
2
self
.
classification_costs
=
-
T
.
sum
(
self
.
classification_cost_matrix
,
axis
=
1
)
self
.
classification_costs
=
-
T
.
sum
(
self
.
classification_cost_matrix
,
axis
=
1
)
return
T
.
sum
(
self
.
classification_costs
)
return
T
.
sum
(
self
.
classification_costs
)
def
build_regularization
(
self
):
def
build_regularization
(
self
):
...
@@ -145,27 +148,28 @@ class T_function_module(unittest.TestCase):
...
@@ -145,27 +148,28 @@ class T_function_module(unittest.TestCase):
def
test_Klass_Advanced_example
(
self
):
def
test_Klass_Advanced_example
(
self
):
model_module
=
SoftmaxXERegression
(
regularize
=
False
)
model_module
=
SoftmaxXERegression
(
regularize
=
False
)
model
=
model_module
.
make
(
input_size
=
4
,
model
=
model_module
.
make
(
input_size
=
10
,
target_size
=
1
,
target_size
=
1
,
stepsize
=
0.1
)
stepsize
=
0.1
)
data_x
=
N
.
random
.
randn
(
4
,
10
)
data_x
=
N
.
random
.
randn
(
4
,
10
)
data_y
=
[
[
x
]
for
x
in
N
.
random
.
randn
(
4
)
>
0
]
data_y
=
[
[
int
(
x
)
]
for
x
in
N
.
random
.
randn
(
4
)
>
0
]
print
data_x
print
data_x
print
print
print
data_y
print
data_y
for
i
in
xrange
(
1000
0
):
for
i
in
xrange
(
1000
):
xe
=
model
.
update
(
data_x
,
data_y
)
xe
=
model
.
update
(
data_x
,
data_y
)
if
i
%
100
==
0
:
if
i
%
100
==
0
:
print
i
,
xe
print
i
,
xe
for
inputs
,
targets
in
my_training_set
():
#
for inputs, targets in my_training_set():
print
"cost:"
,
model
.
update
(
inputs
,
targets
)
#
print "cost:", model.update(inputs, targets)
print
"final weights:"
,
model
.
w
print
"final weights:"
,
model
.
w
print
"final biases:"
,
model
.
b
print
"final biases:"
,
model
.
b
print
"some prediction:"
,
model
.
prediction
(
some_inputs
)
#
print "some prediction:", model.prediction(some_inputs)
def
test_Klass_extending_klass_methods
(
self
):
def
test_Klass_extending_klass_methods
(
self
):
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论