本文整理汇总了Python中quagga.connector.Connector.add_dot方法的典型用法代码示例。如果您正苦于以下问题:Python Connector.add_dot方法的具体用法?Python Connector.add_dot怎么用?Python Connector.add_dot使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类quagga.connector.Connector
的用法示例。
在下文中一共展示了Connector.add_dot方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: MeanPoolingBlock
# 需要导入模块: from quagga.connector import Connector [as 别名]
# 或者: from quagga.connector.Connector import add_dot [as 别名]
class MeanPoolingBlock(object):
"""
MeanPoolingBlock pools matrix along the specified axis. Can handle matrix with
varying number of columns. Number of rows is fixed.
Parameters
----------
matrix : Matrix (GpuMatrix or CpuMatrix)
axis : int
device_id : int
Defines the device's id on which the computation will take place
Returns
-------
"""
def __init__(self, matrix, axis=1, device_id=None):
self.context = Context(device_id)
self._ctype = matrix.c_dtype
self._zero = self._ctype(0.0)
if axis == 0:
self._ones = Matrix.empty(1, matrix.nrows, matrix.dtype, device_id)
self.output = Matrix.empty(1, matrix.ncols, matrix.dtype, device_id)
self.alpha = self._ctype(1.0 / matrix.nrows)
elif axis == 1:
self._ones = Matrix.empty(matrix.ncols, 1, matrix.dtype, device_id)
self.output = Matrix.empty(matrix.nrows, 1, matrix.dtype, device_id)
self.alpha = None
else:
raise ValueError('Invalid axis!')
self._ones.sync_fill(1.0)
self.axis = axis
if matrix.bpropagable:
self.matrix, self.dL_dmatrix = matrix.register_usage(self.context, self.context)
self.output = Connector(self.output, self.context, self.context)
else:
self.matrix = matrix.register_usage(self.context)
self.output = Connector(self.output, self.context)
def fprop(self):
if self.axis == 0:
self.output.ncols = self.matrix.ncols
self.output.add_dot(self.context, self._ones, self.matrix, alpha=self.alpha, beta=self._zero)
else:
self._ones.nrows = self.matrix.ncols
self.alpha = self._ctype(1.0 / self.matrix.ncols)
self.output.add_dot(self.context, self.matrix, self._ones, alpha=self.alpha, beta=self._zero)
self.output.fprop()
def bprop(self):
dL_doutput = self.output.backward_matrix
dL_doutput.scale(self.context, self.alpha)
if hasattr(self, 'dL_dmatrix'):
self.dL_dmatrix.tile(self.context, self.axis, dL_doutput)