本文整理汇总了Python中blocks.graph.ComputationGraph.values方法的典型用法代码示例。如果您正苦于以下问题:Python ComputationGraph.values方法的具体用法?Python ComputationGraph.values怎么用?Python ComputationGraph.values使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类blocks.graph.ComputationGraph
的用法示例。
在下文中一共展示了ComputationGraph.values方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: Pylearn2Cost
# 需要导入模块: from blocks.graph import ComputationGraph [as 别名]
# 或者: from blocks.graph.ComputationGraph import values [as 别名]
class Pylearn2Cost(pylearn2.costs.cost.Cost):
"""Wraps a Theano cost to support the PyLearn2 Cost interface.
Parameters
----------
cost : Theano variable
The Theano variable corresponding to the end of the cost
computation graph.
Notes
-----
The inputs of the computation graph must have names compatible with
names of the data sources. The is necessary in order to replace with
with the ones given by PyLearn2.
"""
def __init__(self, cost):
self.cost = cost
self.inputs = ComputationGraph(self.cost).dict_of_inputs()
def expr(self, model, data, **kwargs):
assert not model.supervised
data = pack(data)
data = [tensor.unbroadcast(var, *range(var.ndim))
for var in data]
return theano.clone(
self.cost, replace=dict(zip(self.inputs.values(), data)))
def get_gradients(self, model, data, **kwargs):
if not hasattr(self, "_grads"):
self._grads = [tensor.grad(self.expr(model, data), p)
for p in model.get_params()]
return OrderedDict(zip(model.get_params(), self._grads)), OrderedDict()
def get_monitoring_channels(self, model, data, **kwargs):
return OrderedDict()
def get_data_specs(self, model):
return model.data_specs