Re: [theano-users] And operator doesn't work with theano logical operators

2017-07-04 Thread Sym
I clearly haven't searched enough for theano.tensor.and_ ! 

Thank you for the correction, everything is clear now :)

-- 

--- 
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 theano-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [theano-users] And operator doesn't work with theano logical operators

2017-06-30 Thread Pascal Lamblin
On Thursday, June 29, 2017 at 10:17:26 AM UTC-4, Sym wrote:
>
> I am using theano 0.9.0 and this function does not exist.. I can't find it 
> in the documentation either !
>

That would be theano.tensor.and_ with a trailing underscore.
 

> And in the theano docs it says that :
> __{abs,neg,lt,le,gt,ge,invert,and,or,add,sub,mul,div,truediv,floordiv}__
> Those elemwise operation are supported via Python syntax.
>

This is true, but the Python syntax that will call `__and__` is actually `a 
&& b`, not `a and b`.

So you can use `a && b`, `and_(a, b)`, or `a * b` if you prefer.
 

>
> Le mercredi 28 juin 2017 21:15:37 UTC-4, nouiz a écrit :
>>
>> Don't use the Python "and" operation. Use theano.tensor.and(a,b) instead. 
>> I think it will fix your problem.
>>
>> Le mer. 28 juin 2017 10:26, Sym  a écrit :
>>
>>>
>>> I want to build a piecewise function with theano, for instance a 
>>> function that is nonzero only in the interval [2,3].
>>>
>>> Here is the minimal code reproducing the error : 
>>>
>>>
>>> import theano
>>> import theano.tensor as T
>>> import numpy as np
>>> import matplotlib.pyplot as plt
>>>
>>> r = T.scalar()
>>> gate = T.switch( T.ge(r,2.) and T.le(r,3.) , 1., 0.)
>>> f = theano.function([r],gate)
>>> x = np.arange(0.,4.,0.05,dtype='float32')
>>> y = [f(i) for i in x]
>>> plt.plot(x,y)
>>>
>>>  
>>>
>>> The result is the following : https://i.stack.imgur.com/XMQme.png 
>>>
>>> Which is clearly not correct : only one condition is satisfied here.
>>>
>>>
>>> If I replace T.switch by theano.ifelse.ifelse the result is the same...
>>>
>>> Is it a known bug, or am I missing something here?
>>>
>>>
>>> Thanks a lot !
>>>
>>> -- 
>>>
>>> --- 
>>> 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 theano-users...@googlegroups.com.
>>> For more options, visit https://groups.google.com/d/optout.
>>>
>>

-- 

--- 
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 theano-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [theano-users] And operator doesn't work with theano logical operators

2017-06-29 Thread Sym
I found a solution :

The and operator should be implemented with * and the or operator with +, 
as the python operators do no work properly with theano (as opposed to what 
they say in the docs).

For further readers, the corrected code is :

import theano
import theano.tensor as T
import numpy as np
import matplotlib.pyplot as plt

r = T.scalar()
gate = T.switch( T.ge(r,2.) * T.le(r,3.) , 1., 0.)
f = theano.function([r],gate)
x = np.arange(0.,4.,0.05,dtype='float32')
y = [f(i) for i in x]
plt.plot(x,y)

Which indeed gives the correct output.

-- 

--- 
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 theano-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [theano-users] And operator doesn't work with theano logical operators

2017-06-29 Thread Sym
I am using theano 0.9.0 and this function does not exist.. I can't find it 
in the documentation either !

And in the theano docs it says that :
__{abs,neg,lt,le,gt,ge,invert,and,or,add,sub,mul,div,truediv,floordiv}__
Those elemwise operation are supported via Python syntax.

Le mercredi 28 juin 2017 21:15:37 UTC-4, nouiz a écrit :
>
> Don't use the Python "and" operation. Use theano.tensor.and(a,b) instead. 
> I think it will fix your problem.
>
> Le mer. 28 juin 2017 10:26, Sym  a 
> écrit :
>
>>
>> I want to build a piecewise function with theano, for instance a function 
>> that is nonzero only in the interval [2,3].
>>
>> Here is the minimal code reproducing the error : 
>>
>>
>> import theano
>> import theano.tensor as T
>> import numpy as np
>> import matplotlib.pyplot as plt
>>
>> r = T.scalar()
>> gate = T.switch( T.ge(r,2.) and T.le(r,3.) , 1., 0.)
>> f = theano.function([r],gate)
>> x = np.arange(0.,4.,0.05,dtype='float32')
>> y = [f(i) for i in x]
>> plt.plot(x,y)
>>
>>  
>>
>> The result is the following : https://i.stack.imgur.com/XMQme.png 
>>
>> Which is clearly not correct : only one condition is satisfied here.
>>
>>
>> If I replace T.switch by theano.ifelse.ifelse the result is the same...
>>
>> Is it a known bug, or am I missing something here?
>>
>>
>> Thanks a lot !
>>
>> -- 
>>
>> --- 
>> 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 theano-users...@googlegroups.com .
>> For more options, visit https://groups.google.com/d/optout.
>>
>

-- 

--- 
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 theano-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [theano-users] And operator doesn't work with theano logical operators

2017-06-28 Thread Frédéric Bastien
Don't use the Python "and" operation. Use theano.tensor.and(a,b) instead. I
think it will fix your problem.

Le mer. 28 juin 2017 10:26, Sym  a écrit :

>
> I want to build a piecewise function with theano, for instance a function
> that is nonzero only in the interval [2,3].
>
> Here is the minimal code reproducing the error :
>
>
> import theano
> import theano.tensor as T
> import numpy as np
> import matplotlib.pyplot as plt
>
> r = T.scalar()
> gate = T.switch( T.ge(r,2.) and T.le(r,3.) , 1., 0.)
> f = theano.function([r],gate)
> x = np.arange(0.,4.,0.05,dtype='float32')
> y = [f(i) for i in x]
> plt.plot(x,y)
>
>
>
> The result is the following : https://i.stack.imgur.com/XMQme.png
>
> Which is clearly not correct : only one condition is satisfied here.
>
>
> If I replace T.switch by theano.ifelse.ifelse the result is the same...
>
> Is it a known bug, or am I missing something here?
>
>
> Thanks a lot !
>
> --
>
> ---
> 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 theano-users+unsubscr...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.
>

-- 

--- 
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 theano-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.