Python theano.foldl() Examples
The following are 12
code examples of theano.foldl().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
theano
, or try the search function
.
Example #1
Source File: theano_backend.py From Att-ChemdNER with Apache License 2.0 | 6 votes |
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]
Example #2
Source File: metrics.py From ntm-one-shot with MIT License | 6 votes |
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
Example #3
Source File: theano_backend.py From GraphicDesignPatternByPython with MIT License | 6 votes |
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]
Example #4
Source File: theano_backend.py From DeepLearning_Wavelet-LSTM with MIT License | 6 votes |
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]
Example #5
Source File: theano_backend.py From DeepLearning_Wavelet-LSTM with MIT License | 6 votes |
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]
Example #6
Source File: theano_backend.py From DeepLearning_Wavelet-LSTM with MIT License | 6 votes |
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]
Example #7
Source File: theano_backend.py From DeepLearning_Wavelet-LSTM with MIT License | 6 votes |
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]
Example #8
Source File: theano_backend.py From DeepLearning_Wavelet-LSTM with MIT License | 6 votes |
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]
Example #9
Source File: theano_backend.py From DeepLearning_Wavelet-LSTM with MIT License | 6 votes |
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]
Example #10
Source File: theano_backend.py From DeepLearning_Wavelet-LSTM with MIT License | 6 votes |
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]
Example #11
Source File: theano_backend.py From deepQuest with BSD 3-Clause "New" or "Revised" License | 6 votes |
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]
Example #12
Source File: theano_backend.py From keras-lambda with MIT License | 6 votes |
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]