>From theano scan
documentation:
http://deeplearning.net/software/theano/library/scan.html#conditional-ending-of-scan
In their example of computing all powers of two smaller than some value.
def power_of_2(previous_power, max_value):
return previous_power*2, theano.scan_module.until(previous_power*2 >
max_value)
max_value = T.scalar()
values, _ = theano.scan(power_of_2,
outputs_info = T.constant(1.),
non_sequences = max_value,
n_steps = 1024)
f = theano.function([max_value], values)
print(f(45))
The output is
[ 2. 4. 8. 16. 32. 64.]
So the max_value = 45, but the last output is 64. So I expect the scan
function will also take the last value in the iteration that breaks the
condition in theano.scan_module.util( ).
Next, I test the theano.scan_module.util( ) for consecutive subtraction
problems. For example, start with a number 50, subtract 10 each time, but
subtract until the result is not lower than 0.
Turn this into code. It will be like:
def subtraction(X):
return (X - 10), theano.scan_module.until(X <= 0)
X_init = T.scalar('X_init')
X_sqn, _ = theano.scan(
fn = subtraction,
outputs_info = [X_init],
n_steps = 10,
)
Y = theano.function(
inputs = [Mem_init],
outputs = Mem_sqn,
)
print Y(50), Y(66)
The output is:
[ 40. 30. 20. 10. 0. -10.]
[ 56. 46. 36. 26. 16. 6. -4. -14.]
which is strange for me for Y(66). For Y(50), I understand that it still
calculate -10 since it's the first time that X <= 0 and then it stops
looping.
But for Y(66), when it calculates X= -4 and check -4<=0. It should output
-4 as the last output and stop looping. But from the actual output, it
still continues to calculate X=-14, and then stop the loop. I don't
understand why it didn't stop at -4 in the first place since -4 already
breaks the given condition.
Could someone please explain this strange behavior of
theano.scan_module.util(condition)?
Thanks.
--
---
You received this message because you are subscribed to the Google Groups
"theano-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/d/optout.