本文整理汇总了Python中theano.foldl方法的典型用法代码示例。如果您正苦于以下问题:Python theano.foldl方法的具体用法?Python theano.foldl怎么用?Python theano.foldl使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类theano
的用法示例。
在下文中一共展示了theano.foldl方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: foldl
# 需要导入模块: import theano [as 别名]
# 或者: from theano import foldl [as 别名]
def foldl(fn, elems, initializer=None, name=None):
'''Reduce elems using fn to combine them from left to right.
# Arguments
fn: Callable that will be called upon each element in elems and an
accumulator, for instance lambda acc, x: acc + x
elems: tensor
initializer: The first value used (elems[0] in case of None)
name: A string name for the foldl node in the graph
# Returns
Same type and shape as initializer
'''
if initializer is None:
initializer = elems[0]
elems = elems[1:]
# We need to change the order of the arguments because theano accepts x as
# first parameter and accumulator as second
fn2 = lambda x, acc: fn(acc, x)
return theano.foldl(fn2, elems, initializer, name=name)[0]
示例2: accuracy_instance
# 需要导入模块: import theano [as 别名]
# 或者: from theano import foldl [as 别名]
def accuracy_instance(predictions, targets, n=[1, 2, 3, 4, 5, 10], \
nb_classes=5, nb_samples_per_class=10, batch_size=1):
accuracy_0 = theano.shared(np.zeros((batch_size, nb_samples_per_class), \
dtype=theano.config.floatX))
indices_0 = theano.shared(np.zeros((batch_size, nb_classes), \
dtype=np.int32))
batch_range = T.arange(batch_size)
def step_(p, t, acc, idx):
acc = T.inc_subtensor(acc[batch_range, idx[batch_range, t]], T.eq(p, t))
idx = T.inc_subtensor(idx[batch_range, t], 1)
return (acc, idx)
(raw_accuracy, _), _ = theano.foldl(step_, sequences=[predictions.dimshuffle(1, 0), \
targets.dimshuffle(1, 0)], outputs_info=[accuracy_0, indices_0])
accuracy = T.mean(raw_accuracy / nb_classes, axis=0)
return accuracy
示例3: foldl
# 需要导入模块: import theano [as 别名]
# 或者: from theano import foldl [as 别名]
def foldl(fn, elems, initializer=None, name=None):
"""Reduce elems using fn to combine them from left to right.
# Arguments
fn: Callable that will be called upon each element in elems and an
accumulator, for instance lambda acc, x: acc + x
elems: tensor
initializer: The first value used (elems[0] in case of None)
name: A string name for the foldl node in the graph
# Returns
Same type and shape as initializer
"""
if initializer is None:
initializer = elems[0]
elems = elems[1:]
# We need to change the order of the arguments because theano accepts x as
# first parameter and accumulator as second
return theano.foldl(lambda x, acc: fn(acc, x),
elems, initializer, name=name)[0]
示例4: foldl
# 需要导入模块: import theano [as 别名]
# 或者: from theano import foldl [as 别名]
def foldl(fn, elems, initializer=None, name=None):
"""Reduce elems using fn to combine them from left to right.
# Arguments
fn: Callable that will be called upon each element in elems and an
accumulator, for instance lambda acc, x: acc + x
elems: tensor
initializer: The first value used (elems[0] in case of None)
name: A string name for the foldl node in the graph
# Returns
Same type and shape as initializer
"""
if initializer is None:
initializer = elems[0]
elems = elems[1:]
# We need to change the order of the arguments because theano accepts x as
# first parameter and accumulator as second
fn2 = lambda x, acc: fn(acc, x)
return theano.foldl(fn2, elems, initializer, name=name)[0]