本文整理汇总了Python中theano.tensor.lt方法的典型用法代码示例。如果您正苦于以下问题:Python tensor.lt方法的具体用法?Python tensor.lt怎么用?Python tensor.lt使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类theano.tensor
的用法示例。
在下文中一共展示了tensor.lt方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_elemwise_comparaison_cast
# 需要导入模块: from theano import tensor [as 别名]
# 或者: from theano.tensor import lt [as 别名]
def test_elemwise_comparaison_cast():
"""
test if an elemwise comparaison followed by a cast to float32 are
pushed to gpu.
"""
a = tensor.fmatrix()
b = tensor.fmatrix()
av = theano._asarray(numpy.random.rand(4, 4), dtype='float32')
bv = numpy.ones((4, 4), dtype='float32')
for g, ans in [(tensor.lt, av < bv), (tensor.gt, av > bv),
(tensor.le, av <= bv), (tensor.ge, av >= bv)]:
f = pfunc([a, b], tensor.cast(g(a, b), 'float32'), mode=mode_with_gpu)
out = f(av, bv)
assert numpy.all(out == ans)
assert any([isinstance(node.op, cuda.GpuElemwise)
for node in f.maker.fgraph.toposort()])
示例2: rprop_core
# 需要导入模块: from theano import tensor [as 别名]
# 或者: from theano.tensor import lt [as 别名]
def rprop_core(params, gradients, rprop_increase=1.01, rprop_decrease=0.99, rprop_min_step=0, rprop_max_step=100,
learning_rate=0.01):
"""
Rprop optimizer.
See http://sci2s.ugr.es/keel/pdf/algorithm/articulo/2003-Neuro-Igel-IRprop+.pdf.
"""
for param, grad in zip(params, gradients):
grad_tm1 = theano.shared(np.zeros_like(param.get_value()), name=param.name + '_grad')
step_tm1 = theano.shared(np.zeros_like(param.get_value()) + learning_rate, name=param.name+ '_step')
test = grad * grad_tm1
same = T.gt(test, 0)
diff = T.lt(test, 0)
step = T.minimum(rprop_max_step, T.maximum(rprop_min_step, step_tm1 * (
T.eq(test, 0) +
same * rprop_increase +
diff * rprop_decrease)))
grad = grad - diff * grad
yield param, param - T.sgn(grad) * step
yield grad_tm1, grad
yield step_tm1, step
示例3: select_finite_faults
# 需要导入模块: from theano import tensor [as 别名]
# 或者: from theano.tensor import lt [as 别名]
def select_finite_faults(self):
fault_points = T.vertical_stack(T.stack([self.ref_layer_points[0]], axis=0), self.rest_layer_points).T
ctr = T.mean(fault_points, axis=1)
x = fault_points - ctr.reshape((-1, 1))
M = T.dot(x, x.T)
U = T.nlinalg.svd(M)[2]
rotated_x = T.dot(self.x_to_interpolate(), U)
rotated_fault_points = T.dot(fault_points.T, U)
rotated_ctr = T.mean(rotated_fault_points, axis=0)
a_radius = (rotated_fault_points[:, 0].max() - rotated_fault_points[:, 0].min()) / 2 + self.inf_factor[
self.n_surface_op[0] - 1]
b_radius = (rotated_fault_points[:, 1].max() - rotated_fault_points[:, 1].min()) / 2 + self.inf_factor[
self.n_surface_op[0] - 1]
sel = T.lt((rotated_x[:, 0] - rotated_ctr[0]) ** 2 / a_radius ** 2 + (
rotated_x[:, 1] - rotated_ctr[1]) ** 2 / b_radius ** 2,
1)
if "select_finite_faults" in self.verbose:
sel = theano.printing.Print("scalar_field_iter")(sel)
return sel
示例4: lesser
# 需要导入模块: from theano import tensor [as 别名]
# 或者: from theano.tensor import lt [as 别名]
def lesser(x, y):
return T.lt(x, y)
示例5: test_ifelse
# 需要导入模块: from theano import tensor [as 别名]
# 或者: from theano.tensor import lt [as 别名]
def test_ifelse(self):
config1 = theano.config.profile
config2 = theano.config.profile_memory
try:
theano.config.profile = True
theano.config.profile_memory = True
a, b = T.scalars('a', 'b')
x, y = T.scalars('x', 'y')
z = ifelse(T.lt(a, b), x * 2, y * 2)
p = theano.ProfileStats(False)
if theano.config.mode in ["DebugMode", "DEBUG_MODE", "FAST_COMPILE"]:
m = "FAST_RUN"
else:
m = None
f_ifelse = theano.function([a, b, x, y], z, profile=p, name="test_ifelse",
mode=m)
val1 = 0.
val2 = 1.
big_mat1 = 10
big_mat2 = 11
f_ifelse(val1, val2, big_mat1, big_mat2)
finally:
theano.config.profile = config1
theano.config.profile_memory = config2
示例6: test_elemwise_composite_float64
# 需要导入模块: from theano import tensor [as 别名]
# 或者: from theano.tensor import lt [as 别名]
def test_elemwise_composite_float64():
# test that we don't fuse composite elemwise with float64 somewhere inside
# nvcc by default downcast them to float32. We would need to tell him not
# to do so, but that possible only on some device.
a = tensor.fmatrix()
b = tensor.fmatrix()
av = theano._asarray(numpy.random.rand(4, 4), dtype='float32')
bv = numpy.ones((4, 4), dtype='float32')
def get_all_basic_scalar(composite_op):
l = []
for i in composite_op.fgraph.toposort():
if isinstance(i, theano.scalar.Composite):
l += get_all_basic_scalar(i)
else:
l.append(i)
return l
for mode in [mode_with_gpu, mode_with_gpu.excluding('gpu_after_fusion'),
mode_with_gpu.excluding('elemwise_fusion')]:
f = pfunc([a, b],
tensor.cast(tensor.lt(tensor.cast(a, 'float64') ** 2,
b),
'float32'), mode=mode)
out = f(av, bv)
assert numpy.all(out == ((av ** 2) < bv))
for node in f.maker.fgraph.toposort():
if isinstance(node.op, cuda.GpuElemwise):
if isinstance(node.op.scalar_op, theano.scalar.Composite):
scals = get_all_basic_scalar(node.op.scalar_op)
for s in scals:
assert not any([i.type.dtype == 'float64'
for i in s.inputs + s.outputs])
示例7: gradient_clipping
# 需要导入模块: from theano import tensor [as 别名]
# 或者: from theano.tensor import lt [as 别名]
def gradient_clipping(grads, tparams, clip_c=10):
g2 = 0.
for g in grads:
g2 += (g**2).sum()
g2 = tensor.sqrt(g2)
not_finite = tensor.or_(tensor.isnan(g2), tensor.isinf(g2))
new_grads = []
for p, g in zip(tparams.values(), grads):
new_grads.append(tensor.switch(g2 > clip_c,
g * (clip_c / g2),
g))
return new_grads, not_finite, tensor.lt(clip_c, g2)
示例8: less
# 需要导入模块: from theano import tensor [as 别名]
# 或者: from theano.tensor import lt [as 别名]
def less(x, y):
return T.lt(x, y)
示例9: add_exploration
# 需要导入模块: from theano import tensor [as 别名]
# 或者: from theano.tensor import lt [as 别名]
def add_exploration(recognizer, data, train_conf):
prediction = None
prediction_mask = None
explore_conf = train_conf.get('exploration', 'imitative')
if explore_conf in ['greedy', 'mixed']:
length_expand = 10
prediction = recognizer.get_generate_graph(
n_steps=recognizer.labels.shape[0] + length_expand)['outputs']
prediction_mask = tensor.lt(
tensor.cumsum(tensor.eq(prediction, data.eos_label), axis=0),
1).astype(floatX)
prediction_mask = tensor.roll(prediction_mask, 1, 0)
prediction_mask = tensor.set_subtensor(
prediction_mask[0, :], tensor.ones_like(prediction_mask[0, :]))
if explore_conf == 'mixed':
batch_size = recognizer.labels.shape[1]
targets = tensor.concatenate([
recognizer.labels,
tensor.zeros((length_expand, batch_size), dtype='int64')])
targets_mask = tensor.concatenate([
recognizer.labels_mask,
tensor.zeros((length_expand, batch_size), dtype=floatX)])
rng = MRG_RandomStreams()
generate = rng.binomial((batch_size,), p=0.5, dtype='int64')
prediction = (generate[None, :] * prediction +
(1 - generate[None, :]) * targets)
prediction_mask = (tensor.cast(generate[None, :] *
prediction_mask, floatX) +
tensor.cast((1 - generate[None, :]) *
targets_mask, floatX))
prediction_mask = theano.gradient.disconnected_grad(prediction_mask)
elif explore_conf != 'imitative':
raise ValueError
return prediction, prediction_mask
示例10: test_ifelse
# 需要导入模块: from theano import tensor [as 别名]
# 或者: from theano.tensor import lt [as 别名]
def test_ifelse(self):
config1 = theano.config.profile
config2 = theano.config.profile_memory
try:
theano.config.profile = True
theano.config.profile_memory = True
a, b = T.scalars('a', 'b')
x, y = T.scalars('x', 'y')
z = ifelse(T.lt(a, b), x * 2, y * 2)
p = theano.ProfileStats(False)
if theano.config.mode in ["DebugMode", "DEBUG_MODE", "FAST_COMPILE"]:
m = "FAST_RUN"
else:
m = None
f_ifelse = theano.function([a, b, x, y], z, profile=p, name="test_ifelse",
mode=m)
val1 = 0.
val2 = 1.
big_mat1 = 10
big_mat2 = 11
out = f_ifelse(val1, val2, big_mat1, big_mat2)
finally:
theano.config.profile = config1
theano.config.profile_memory = config2
示例11: __init__
# 需要导入模块: from theano import tensor [as 别名]
# 或者: from theano.tensor import lt [as 别名]
def __init__(self, inverse_scale=1.0):
"""Constructor.
Parameters
----------
* `inverse_scale` [float]:
The inverse scale.
"""
super(Exponential, self).__init__(inverse_scale=inverse_scale)
# pdf
self.pdf_ = T.switch(
T.lt(self.X, 0.),
0.,
self.inverse_scale * T.exp(-self.inverse_scale * self.X)).ravel()
self._make(self.pdf_, "pdf")
# -log pdf
self.nll_ = bound(
-T.log(self.inverse_scale) + self.inverse_scale * self.X,
np.inf,
self.inverse_scale > 0.).ravel()
self._make(self.nll_, "nll")
# cdf
self.cdf_ = (1. - T.exp(-self.inverse_scale * self.X)).ravel()
self._make(self.cdf_, "cdf")
# ppf
self.ppf_ = -T.log(1. - self.p) / self.inverse_scale
self._make(self.ppf_, "ppf", args=[self.p])
示例12: __init__
# 需要导入模块: from theano import tensor [as 别名]
# 或者: from theano.tensor import lt [as 别名]
def __init__(self, low=0.0, high=1.0):
"""Constructor.
Parameters
----------
* `low` [float]:
The lower bound.
* `high` [float]:
The upper bound
"""
super(Uniform, self).__init__(low=low, high=high)
# pdf
self.pdf_ = T.switch(
T.or_(T.lt(self.X, self.low), T.ge(self.X, self.high)),
0.,
1. / (self.high - self.low)).ravel()
self._make(self.pdf_, "pdf")
# -log pdf
self.nll_ = T.switch(
T.or_(T.lt(self.X, self.low), T.ge(self.X, self.high)),
np.inf,
T.log(self.high - self.low)).ravel()
self._make(self.nll_, "nll")
# cdf
self.cdf_ = T.switch(
T.lt(self.X, self.low),
0.,
T.switch(
T.lt(self.X, self.high),
(self.X - self.low) / (self.high - self.low),
1.)).ravel()
self._make(self.cdf_, "cdf")
# ppf
self.ppf_ = self.p * (self.high - self.low) + self.low
self._make(self.ppf_, "ppf", args=[self.p])
示例13: _get_updates_for
# 需要导入模块: from theano import tensor [as 别名]
# 或者: from theano.tensor import lt [as 别名]
def _get_updates_for(self, param, grad):
grad_tm1 = util.shared_like(param, 'grad')
step_tm1 = util.shared_like(param, 'step', self.learning_rate.eval())
test = grad * grad_tm1
diff = TT.lt(test, 0)
steps = step_tm1 * (TT.eq(test, 0) +
TT.gt(test, 0) * self.step_increase +
diff * self.step_decrease)
step = TT.minimum(self.max_step, TT.maximum(self.min_step, steps))
grad = grad - diff * grad
yield param, TT.sgn(grad) * step
yield grad_tm1, grad
yield step_tm1, step
示例14: get_output_for
# 需要导入模块: from theano import tensor [as 别名]
# 或者: from theano.tensor import lt [as 别名]
def get_output_for(self, input, deterministic=False, **kwargs):
if deterministic:
return self.p*input
else:
return theano.ifelse.ifelse(
T.lt(self._srng.uniform( (1,), 0, 1)[0], self.p),
input,
T.zeros(input.shape)
)
# def ResDrop(incoming, IB, p):
# return NL(ESL([IfElseDropLayer(IB,survival_p=p),incoming]),elu)
示例15: get_output_for
# 需要导入模块: from theano import tensor [as 别名]
# 或者: from theano.tensor import lt [as 别名]
def get_output_for(self, input, deterministic=False, **kwargs):
if deterministic:
return self.p*input
else:
return theano.ifelse.ifelse(
T.lt(self._srng.uniform( (1,), 0, 1)[0], self.p),
input,
T.zeros(input.shape)
)