本文整理汇总了Python中theano.tensor.ge方法的典型用法代码示例。如果您正苦于以下问题:Python tensor.ge方法的具体用法?Python tensor.ge怎么用?Python tensor.ge使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类theano.tensor
的用法示例。
在下文中一共展示了tensor.ge方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_elemwise_comparaison_cast
# 需要导入模块: from theano import tensor [as 别名]
# 或者: from theano.tensor import ge [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: errors4one
# 需要导入模块: from theano import tensor [as 别名]
# 或者: from theano.tensor import ge [as 别名]
def errors4one(self, z, out, weight=None, distLabelType='12C'):
distBins = config.distCutoffs[distLabelType]
label8 = DistanceUtils.LabelsOfOneDistance(config.ContactDefinition, distBins)
label15 = DistanceUtils.LabelsOfOneDistance(config.InteractionLimit, distBins)
z3C = T.cast( T.ge(z, label8), 'int32') + T.cast( T.ge(z, label15), 'int32')
o3C = T.cast( T.ge(out, label8), 'int32') + T.cast( T.ge(out, label15), 'int32')
if weight is not None:
err = T.sum( T.mul(weight, T.neq(o3C, z3C) ) )*1./T.sum(weight)
else:
err = T.mean( T.neq(o3C , z3C) )
## err is s scalar, convert it to a tensor with ndim=1
return T.stack([err] )
## this function returns a vector of errors, the size of this vector is equal to the sum of ValueDims for all the responses
示例3: SGD
# 需要导入模块: from theano import tensor [as 别名]
# 或者: from theano.tensor import ge [as 别名]
def SGD(tparams, cost, inps, lr,clip_norm=5):
""" default: lr=0.01 """
grads = tensor.grad(cost, tparams.values())
norm = tensor.sqrt(sum([tensor.sum(g**2) for g in grads]))
if tensor.ge(norm, clip_norm):
grads = [g*clip_norm/norm for g in grads]
gshared = [theano.shared(p.get_value() * 0., name='%s_grad'%k)
for k, p in tparams.iteritems()]
gsup = [(gs, g) for gs, g in zip(gshared, grads)]
f_grad_shared = theano.function(inps, cost, updates=gsup)
updates = []
for p, g in zip(tparams.values(), gshared):
updated_p = p - lr * g
updates.append((p, updated_p))
f_update = theano.function([lr], [], updates=updates)
return f_grad_shared, f_update
示例4: Adagrad
# 需要导入模块: from theano import tensor [as 别名]
# 或者: from theano.tensor import ge [as 别名]
def Adagrad(tparams, cost, inps, lr, epsilon=1e-6,clip_norm=5):
""" default: lr=0.01 """
grads = tensor.grad(cost, tparams.values())
norm = tensor.sqrt(sum([tensor.sum(g**2) for g in grads]))
if tensor.ge(norm, clip_norm):
grads = [g*clip_norm/norm for g in grads]
gshared = [theano.shared(p.get_value() * 0., name='%s_grad'%k)
for k, p in tparams.iteritems()]
gsup = [(gs, g) for gs, g in zip(gshared, grads)]
f_grad_shared = theano.function(inps, cost, updates=gsup)
updates = []
for p, g in zip(tparams.values(), gshared):
acc = theano.shared(p.get_value() * 0.)
acc_t = acc + g ** 2
updates.append((acc, acc_t))
p_t = p - (lr / tensor.sqrt(acc_t + epsilon)) * g
updates.append((p, p_t))
f_update = theano.function([lr], [], updates=updates)
return f_grad_shared, f_update
示例5: apply
# 需要导入模块: from theano import tensor [as 别名]
# 或者: from theano.tensor import ge [as 别名]
def apply(self, y, y_hat):
# Support checkpoints that predate self.top_k
top_k = getattr(self, 'top_k', 1)
if top_k == 1:
mistakes = tensor.neq(y, y_hat.argmax(axis=1))
else:
row_offsets = theano.tensor.arange(0, y_hat.flatten().shape[0],
y_hat.shape[1])
truth_score = y_hat.flatten()[row_offsets + y]
# We use greater than _or equals_ here so that the model
# _must_ have its guess in the top k, and cannot extend
# its effective "list of predictions" by tying lots of things
# for k-th place.
higher_scoring = tensor.ge(y_hat, truth_score.dimshuffle(0, 'x'))
# Because we used greater-than-or-equal we have to correct for
# counting the true label.
num_higher = higher_scoring.sum(axis=1) - 1
mistakes = tensor.ge(num_higher, top_k)
return mistakes.mean(dtype=theano.config.floatX)
示例6: get_gradients
# 需要导入模块: from theano import tensor [as 别名]
# 或者: from theano.tensor import ge [as 别名]
def get_gradients(self, model, data, **kwargs):
gradients, updates = self.cost.get_gradients(model, data, **kwargs)
norm = tensor.sqrt(tensor.sum(
[tensor.sum(param_gradient ** 2) for param, param_gradient
in six.iteritems(gradients)
if param.name not in self.exclude_params]
))
clipped_gradients = OrderedDict()
for param, param_gradient in six.iteritems(gradients):
if param.name not in self.exclude_params:
clipped_gradients[param] = tensor.switch(
tensor.ge(norm, self.clipping_value),
param_gradient / norm * self.clipping_value,
param_gradient
)
gradients.update(clipped_gradients)
return gradients, updates
示例7: flux
# 需要导入模块: from theano import tensor [as 别名]
# 或者: from theano.tensor import ge [as 别名]
def flux(self, xo, yo, zo, ro, u):
"""Compute the light curve."""
# Initialize flat light curve
flux = tt.ones_like(xo)
# Compute the occultation mask
b = tt.sqrt(xo ** 2 + yo ** 2)
b_occ = tt.invert(tt.ge(b, 1.0 + ro) | tt.le(zo, 0.0) | tt.eq(ro, 0.0))
i_occ = tt.arange(b.size)[b_occ]
# Get the Agol `c` coefficients
c = self._get_cl(u)
if self.udeg == 0:
c_norm = c / (np.pi * c[0])
else:
c_norm = c / (np.pi * (c[0] + 2 * c[1] / 3))
# Compute the occultation flux
los = zo[i_occ]
r = ro * tt.ones_like(los)
flux = tt.set_subtensor(
flux[i_occ], self._limbdark(c_norm, b[i_occ], r, los)[0]
)
return flux
示例8: greater_equal
# 需要导入模块: from theano import tensor [as 别名]
# 或者: from theano.tensor import ge [as 别名]
def greater_equal(x, y):
return T.ge(x, y)
示例9: error
# 需要导入模块: from theano import tensor [as 别名]
# 或者: from theano.tensor import ge [as 别名]
def error(self, y, threshold=0.5):
return tensor.mean(tensor.eq(tensor.ge(self.prediction(), threshold), y))
示例10: __call__
# 需要导入模块: from theano import tensor [as 别名]
# 或者: from theano.tensor import ge [as 别名]
def __call__(self, p):
p *= T.ge(p, 0)
return p
示例11: Momentum
# 需要导入模块: from theano import tensor [as 别名]
# 或者: from theano.tensor import ge [as 别名]
def Momentum(tparams, cost, inps, lr, momentum=0.9,clip_norm=5):
""" default: lr=0.01 """
grads = tensor.grad(cost, tparams.values())
norm = tensor.sqrt(sum([tensor.sum(g**2) for g in grads]))
if tensor.ge(norm, clip_norm):
grads = [g*clip_norm/norm for g in grads]
gshared = [theano.shared(p.get_value() * 0., name='%s_grad'%k)
for k, p in tparams.iteritems()]
gsup = [(gs, g) for gs, g in zip(gshared, grads)]
f_grad_shared = theano.function(inps, cost, updates=gsup)
updates = []
for p, g in zip(tparams.values(), gshared):
m = theano.shared(p.get_value() * 0.)
m_new = momentum * m - lr * g
updates.append((m, m_new))
updated_p = p + m_new
updates.append((p, updated_p))
f_update = theano.function([lr], [], updates=updates)
return f_grad_shared, f_update
示例12: NAG
# 需要导入模块: from theano import tensor [as 别名]
# 或者: from theano.tensor import ge [as 别名]
def NAG(tparams, cost, inps, lr, momentum=0.9,clip_norm=5):
""" default: lr=0.01 """
grads = tensor.grad(cost, tparams.values())
norm = tensor.sqrt(sum([tensor.sum(g**2) for g in grads]))
if tensor.ge(norm, clip_norm):
grads = [g*clip_norm/norm for g in grads]
gshared = [theano.shared(p.get_value() * 0., name='%s_grad'%k)
for k, p in tparams.iteritems()]
gsup = [(gs, g) for gs, g in zip(gshared, grads)]
f_grad_shared = theano.function(inps, cost, updates=gsup)
updates = []
for p, g in zip(tparams.values(), gshared):
m = theano.shared(p.get_value() * 0.)
m_new = momentum * m - lr * g
updates.append((m, m_new))
updated_p = p + momentum * m_new - lr * g
updates.append((p, updated_p))
f_update = theano.function([lr], [], updates=updates)
return f_grad_shared, f_update
示例13: Adadelta
# 需要导入模块: from theano import tensor [as 别名]
# 或者: from theano.tensor import ge [as 别名]
def Adadelta(tparams, cost, inps, lr, rho=0.95, epsilon=1e-6,clip_norm=5):
""" default: lr=0.5 """
grads = tensor.grad(cost, tparams.values())
norm = tensor.sqrt(sum([tensor.sum(g**2) for g in grads]))
if tensor.ge(norm, clip_norm):
grads = [g*clip_norm/norm for g in grads]
gshared = [theano.shared(p.get_value() * 0., name='%s_grad'%k)
for k, p in tparams.iteritems()]
gsup = [(gs, g) for gs, g in zip(gshared, grads)]
f_grad_shared = theano.function(inps, cost, updates=gsup)
updates = []
for p, g in zip(tparams.values(), gshared):
acc = theano.shared(p.get_value() * 0.)
acc_delta = theano.shared(p.get_value() * 0.)
acc_new = rho * acc + (1 - rho) * g ** 2
updates.append((acc,acc_new))
update = g * tensor.sqrt(acc_delta + epsilon) / tensor.sqrt(acc_new + epsilon)
updated_p = p - lr * update
updates.append((p, updated_p))
acc_delta_new = rho * acc_delta + (1 - rho) * update ** 2
updates.append((acc_delta,acc_delta_new))
f_update = theano.function([lr], [], updates=updates)
return f_grad_shared, f_update
示例14: RMSprop_v2
# 需要导入模块: from theano import tensor [as 别名]
# 或者: from theano.tensor import ge [as 别名]
def RMSprop_v2(tparams, cost, inps, lr, rho=0.95, momentum=0.9, epsilon=1e-4, clip_norm=5):
""" default: lr=0.0001
This is the implementation of the RMSprop algorithm used in
http://arxiv.org/pdf/1308.0850v5.pdf
"""
grads = tensor.grad(cost, tparams.values())
norm = tensor.sqrt(sum([tensor.sum(g**2) for g in grads]))
if tensor.ge(norm, clip_norm):
grads = [g*clip_norm/norm for g in grads]
gshared = [theano.shared(p.get_value() * 0., name='%s_grad'%k)
for k, p in tparams.iteritems()]
gsup = [(gs, g) for gs, g in zip(gshared, grads)]
f_grad_shared = theano.function(inps, cost, updates=gsup)
updates = []
for p, g in zip(tparams.values(), gshared):
acc = theano.shared(p.get_value() * 0.)
acc2 = theano.shared(p.get_value() * 0.)
acc_new = rho * acc + (1.-rho) * g
acc2_new = rho * acc + (1.-rho) * (g ** 2)
updates.append((acc, acc_new))
updates.append((acc2, acc2_new))
updir = theano.shared(p.get_value() * 0.)
updir_new = momentum * updir - lr * g / tensor.sqrt(acc2_new -acc_new ** 2 + epsilon)
updates.append((updir, updir_new))
updated_p = p + updir_new
updates.append((p, updated_p))
f_update = theano.function([lr], [], updates=updates)
return f_grad_shared, f_update
示例15: Adam
# 需要导入模块: from theano import tensor [as 别名]
# 或者: from theano.tensor import ge [as 别名]
def Adam(tparams, cost, inps, lr, b1=0.1, b2=0.001, e=1e-8, clip_norm=5):
""" default: lr=0.0002
This is the implementation of the Adam algorithm
Reference: http://arxiv.org/pdf/1412.6980v8.pdf
"""
grads = tensor.grad(cost, tparams.values())
norm = tensor.sqrt(sum([tensor.sum(g**2) for g in grads]))
if tensor.ge(norm, clip_norm):
grads = [g*clip_norm/norm for g in grads]
gshared = [theano.shared(p.get_value() * 0., name='%s_grad'%k)
for k, p in tparams.iteritems()]
gsup = [(gs, g) for gs, g in zip(gshared, grads)]
f_grad_shared = theano.function(inps, cost, updates=gsup)
updates = []
i = theano.shared(numpy_floatX(0.))
i_t = i + 1.
fix1 = 1. - b1**(i_t)
fix2 = 1. - b2**(i_t)
lr_t = lr * (tensor.sqrt(fix2) / fix1)
for p, g in zip(tparams.values(), gshared):
m = theano.shared(p.get_value() * 0.)
v = theano.shared(p.get_value() * 0.)
m_t = (b1 * g) + ((1. - b1) * m)
v_t = (b2 * tensor.sqr(g)) + ((1. - b2) * v)
g_t = m_t / (tensor.sqrt(v_t) + e)
p_t = p - (lr_t * g_t)
updates.append((m, m_t))
updates.append((v, v_t))
updates.append((p, p_t))
updates.append((i, i_t))
f_update = theano.function([lr], [], updates=updates)
return f_grad_shared, f_update