Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
00023926
提交
00023926
authored
3月 19, 2009
作者:
James Bergstra
浏览文件
操作
浏览文件
下载
差异文件
merge
上级
d158b168
02ee0d7a
隐藏空白字符变更
内嵌
并排
正在显示
1 个修改的文件
包含
13 行增加
和
8 行删除
+13
-8
module.txt
doc/sandbox/module.txt
+13
-8
没有找到文件。
doc/sandbox/module.txt
浏览文件 @
00023926
...
...
@@ -224,6 +224,7 @@ Complex models can be implemented by subclassing ``Module`` (though that is not
.. code-block:: python
class RegressionLayer(M.Module):
def __init__(self, input = None, target = None, regularize = True):
super(RegressionLayer, self).__init__() #boilerplate
# MODEL CONFIGURATION
...
...
@@ -253,13 +254,15 @@ Complex models can be implemented by subclassing ``Module`` (though that is not
self.grad_w, self.grad_b = T.grad(self.cost, [self.w, self.b])
# INTERFACE METHODS
self.update = M.Method([input, target],
self.cost,
w =
self.w - self.stepsize * self.grad_w,
b = self.b - self.stepsize * self.grad_b
)
self.cost,
updates={self.w:
self.w - self.stepsize * self.grad_w,
self.b: self.b - self.stepsize * self.grad_b}
)
self.apply = M.Method(input, self.prediction)
def params(self):
return self.w, self.b
def _instance_initialize(self, obj, input_size = None, target_size = None,
def _instance_initialize(self, obj, input_size = None, target_size = None,
seed = 1827, **init):
# obj is an "instance" of this module holding values for each member and
# functions for each method
...
...
@@ -275,21 +278,23 @@ Complex models can be implemented by subclassing ``Module`` (though that is not
# this covers setting stepsize, l2_coef; w and b can be set that way too
# we call it after as we want the parameter to superseed the default value.
M.default_initialize(obj,**init)
def build_regularization(self):
return T.zero() # no regularization!
class SoftmaxXERegression(RegressionLayer):
""" XE mean cross entropy"""
""" XE mean
s
cross entropy"""
def build_prediction(self):
return NN.softmax(self.activation)
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 - self.prediction)**2
self.classification_costs = -T.sum(self.classification_cost_matrix, axis=1)
return T.sum(self.classification_costs)
def build_regularization(self):
self.l2_coef =
M.Member(T.scalar()
) # we can add a hyper parameter if we need to
self.l2_coef =
T.scalar(
) # we can add a hyper parameter if we need to
return self.l2_coef * T.sum(self.w * self.w)
Here is how we use the model:
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论