本文整理汇总了Python中theano.tensor.Variable方法的典型用法代码示例。如果您正苦于以下问题:Python tensor.Variable方法的具体用法?Python tensor.Variable怎么用?Python tensor.Variable使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类theano.tensor
的用法示例。
在下文中一共展示了tensor.Variable方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: cost
# 需要导入模块: from theano import tensor [as 别名]
# 或者: from theano.tensor import Variable [as 别名]
def cost(self, readouts, outputs):
"""Compute generation cost of outputs given readouts.
Parameters
----------
readouts : :class:`~theano.Variable`
Readouts produced by the :meth:`readout` method
of a `(..., readout dim)` shape.
outputs : :class:`~theano.Variable`
Outputs whose cost should be computed. Should have as many
or one less dimensions compared to `readout`. If readout has
`n` dimensions, first `n - 1` dimensions of `outputs` should
match with those of `readouts`.
"""
pass
示例2: encode
# 需要导入模块: from theano import tensor [as 别名]
# 或者: from theano.tensor import Variable [as 别名]
def encode(self, inputs):
"""
Map inputs through the encoder function.
Parameters
----------
inputs : tensor_like or list of tensor_likes
Theano symbolic (or list thereof) representing the input
minibatch(es) to be encoded. Assumed to be 2-tensors, with the
first dimension indexing training examples and the second
indexing data dimensions.
Returns
-------
encoded : tensor_like or list of tensor_like
Theano symbolic (or list thereof) representing the corresponding
minibatch(es) after encoding.
"""
if isinstance(inputs, tensor.Variable):
return self._hidden_activation(inputs)
else:
return [self.encode(v) for v in inputs]
示例3: input_to_h_from_v
# 需要导入模块: from theano import tensor [as 别名]
# 或者: from theano.tensor import Variable [as 别名]
def input_to_h_from_v(self, v):
"""
Compute the affine function (linear map plus bias) that serves as
input to the hidden layer in an RBM.
Parameters
----------
v : tensor_like or list of tensor_likes
Theano symbolic (or list thereof) representing the one or several
minibatches on the visible units, with the first dimension
indexing training examples and the second indexing data dimensions.
Returns
-------
a : tensor_like or list of tensor_likes
Theano symbolic (or list thereof) representing the input to each
hidden unit for each training example.
"""
if isinstance(v, tensor.Variable):
return self.bias_hid + self.transformer.lmul(v)
else:
return [self.input_to_h_from_v(vis) for vis in v]
示例4: input_to_v_from_h
# 需要导入模块: from theano import tensor [as 别名]
# 或者: from theano.tensor import Variable [as 别名]
def input_to_v_from_h(self, h):
"""
Compute the affine function (linear map plus bias) that serves as
input to the visible layer in an RBM.
Parameters
----------
h : tensor_like or list of tensor_likes
Theano symbolic (or list thereof) representing the one or several
minibatches on the hidden units, with the first dimension
indexing training examples and the second indexing data dimensions.
Returns
-------
a : tensor_like or list of tensor_likes
Theano symbolic (or list thereof) representing the input to each
visible unit for each row of h.
"""
if isinstance(h, tensor.Variable):
return self.bias_vis + self.transformer.lmul_T(h)
else:
return [self.input_to_v_from_h(hid) for hid in h]
示例5: mean_h_given_v
# 需要导入模块: from theano import tensor [as 别名]
# 或者: from theano.tensor import Variable [as 别名]
def mean_h_given_v(self, v):
"""
Compute the mean activation of the hidden units given visible unit
configurations for a set of training examples.
Parameters
----------
v : tensor_like or list of tensor_likes
Theano symbolic (or list thereof) representing the hidden unit
states for a batch (or several) of training examples, with the
first dimension indexing training examples and the second
indexing data dimensions.
Returns
-------
h : tensor_like or list of tensor_likes
Theano symbolic (or list thereof) representing the mean
(deterministic) hidden unit activations given the visible units.
"""
if isinstance(v, tensor.Variable):
return nnet.sigmoid(self.input_to_h_from_v(v))
else:
return [self.mean_h_given_v(vis) for vis in v]
示例6: sgd_updates
# 需要导入模块: from theano import tensor [as 别名]
# 或者: from theano.tensor import Variable [as 别名]
def sgd_updates(self, params, grads, stepsizes):
"""
Return a list of (pairs) that can be used
as updates in theano.function to
implement stochastic gradient descent.
Parameters
----------
params : list of Variable
variables to adjust in order to minimize some cost
grads : list of Variable
the gradient on each param (with respect to some cost)
stepsizes : symbolic scalar or list of one symbolic scalar per param
step by this amount times the negative gradient on each iteration
"""
try:
iter(stepsizes)
except Exception:
stepsizes = [stepsizes for p in params]
if len(params) != len(grads):
raise ValueError('params and grads have different lens')
updates = [(p, p - step * gp) for (step, p, gp)
in zip(stepsizes, params, grads)]
return updates
示例7: __call__
# 需要导入模块: from theano import tensor [as 别名]
# 或者: from theano.tensor import Variable [as 别名]
def __call__(self, inputs):
"""
(Symbolically) corrupt the inputs with a noise process.
Parameters
----------
inputs : tensor_like, or list of tensor_likes
Theano symbolic(s) representing a (list of) (mini)batch of
inputs to be corrupted, with the first dimension indexing
training examples and the second indexing data dimensions.
Returns
-------
corrupted : tensor_like, or list of tensor_likes
Theano symbolic(s) representing the corresponding corrupted
inputs.
"""
if isinstance(inputs, tensor.Variable):
return self._corrupt(inputs)
else:
return [self._corrupt(inp) for inp in inputs]
示例8: theano_function
# 需要导入模块: from theano import tensor [as 别名]
# 或者: from theano.tensor import Variable [as 别名]
def theano_function(*vars_by_pos, **kwargs):
'''theano function decorator'''
mode = kwargs.pop('mode', 'FAST_RUN')
check_valid = kwargs.pop('check_valid', False)
checks = kwargs.pop('checks', ())
vars_by_name = kwargs
def compile_func(f):
argnames = f.func_code.co_varnames[:f.func_code.co_argcount]
if any([a in vars_by_name for a in argnames[:len(vars_by_pos)]]):
raise ValueError('Argument supplied twice to %s' % f.func_name)
varspec = dict(vars_by_name)
varspec.update(zip(argnames[:len(vars_by_pos)], vars_by_pos))
argvars = []
for name in argnames:
spec = varspec[name]
if isinstance(spec, (tuple, list)):
(var, test_val) = spec
else:
var = spec
test_val = None
assert isinstance(var, T.Variable)
var.name = name
if test_val is not None:
var.tag.test_value = test_val
argvars.append(var)
return function(argvars, f(*argvars),
check_valid=check_valid,
checks=checks,
mode=mode)
return compile_func
示例9: check_theano_variable
# 需要导入模块: from theano import tensor [as 别名]
# 或者: from theano.tensor import Variable [as 别名]
def check_theano_variable(variable, n_dim, dtype_prefix):
"""Check number of dimensions and dtype of a Theano variable.
If the input is not a Theano variable, it is converted to one. `None`
input is handled as a special case: no checks are done.
Parameters
----------
variable : :class:`~tensor.TensorVariable` or convertible to one
A variable to check.
n_dim : int
Expected number of dimensions or None. If None, no check is
performed.
dtype : str
Expected dtype prefix or None. If None, no check is performed.
"""
if variable is None:
return
if not isinstance(variable, tensor.Variable):
variable = tensor.as_tensor_variable(variable)
if n_dim and variable.ndim != n_dim:
raise ValueError("Wrong number of dimensions:"
"\n\texpected {}, got {}".format(
n_dim, variable.ndim))
if dtype_prefix and not variable.dtype.startswith(dtype_prefix):
raise ValueError("Wrong dtype prefix:"
"\n\texpected starting with {}, got {}".format(
dtype_prefix, variable.dtype))
示例10: emit
# 需要导入模块: from theano import tensor [as 别名]
# 或者: from theano.tensor import Variable [as 别名]
def emit(self, readouts):
"""Produce outputs from readouts.
Parameters
----------
readouts : :class:`~theano.Variable`
Readouts produced by the :meth:`readout` method of
a `(batch_size, readout_dim)` shape.
"""
pass
示例11: _setitem
# 需要导入模块: from theano import tensor [as 别名]
# 或者: from theano.tensor import Variable [as 别名]
def _setitem(self, key, value):
if isinstance(value, Variable):
add_role(value, PARAMETER)
add_annotation(value, self.brick)
示例12: decode
# 需要导入模块: from theano import tensor [as 别名]
# 或者: from theano.tensor import Variable [as 别名]
def decode(self, hiddens):
"""
Map inputs through the encoder function.
Parameters
----------
hiddens : tensor_like or list of tensor_likes
Theano symbolic (or list thereof) representing the input
minibatch(es) to be encoded. Assumed to be 2-tensors, with the
first dimension indexing training examples and the second
indexing data dimensions.
Returns
-------
decoded : tensor_like or list of tensor_like
Theano symbolic (or list thereof) representing the corresponding
minibatch(es) after decoding.
"""
if self.act_dec is None:
act_dec = lambda x: x
else:
act_dec = self.act_dec
if isinstance(hiddens, tensor.Variable):
return act_dec(self.visbias + tensor.dot(hiddens, self.w_prime))
else:
return [self.decode(v) for v in hiddens]