[Chicago] ReLU's pythonic?
Michael Tamillow
mikaeltamillow96 at gmail.com
Sat Feb 18 22:42:24 EST 2017
Well, turns out I was wrong, which is surprisingly common. This is more
like the case of enjoying doing what's good for you instead of making a
decision between what's good and what's enjoyable.
https://github.com/MikeTam1021/ReLU/blob/master/ReLU%20performance%20python.
ipynb
after some of the comments I looked into broadcasting with the built in max
function which is much faster than any other way to run the ReLU.
Thanks!
On Sat, Feb 18, 2017 at 4:39 AM, Jason Wirth <wirth.jason at gmail.com> wrote:
> The ternary operator is easier to understand for me in this context.
> Relu's take values less than zero and set them to zero. That's the
> important part and the ternary operator captures the less than part, the
> max is irrelevant. It's not that you care about the maximum value, you just
> don't want any negative values. Where as when I see max it makes me think
> of two numbers (often positive) and you want the larger of the two because
> you care about magnitude. E.g.
>
> salary = max(job1, job2)
>
> Also as a general point, beware the ternary operator. Your case is simple
> but t can get really long and really messy, becoming an unreadable pile of
> garbage.
>
> result = obj.process().result if obj.name in found_names and obj.settings
> or obj.user_settings else obj.process(defaults).get_result()
>
>
>
> On Fri, Feb 17, 2017 at 4:37 PM Anish Krishnan <
> anish.krishnan.1216 at gmail.com> wrote:
>
>> If you know you're only going to be working with two elements, you could
>> write your own function that contains the second line of code. In that case
>> it's readable as well as fast. But it might be overkill, depending on how
>> often you call out.
>>
>> On Feb 17, 2017 1:19 PM, "Michael Tamillow" <mikaeltamillow96 at gmail.com>
>> wrote:
>>
>> Hey groupies!
>>
>>
>> I am curious about what people consider more pythonic.
>>
>> The zen of python says:
>>
>>
>> "There should be one-- and preferably only one --obvious way to do it."
>>
>> And so, I've been reading about ReLUs recently in Neural Networks (Rectified Linear Units), which all give the equation:
>>
>> f(x) = max(0, x)
>>
>> But, whenever I see this I think:
>>
>> f(x) = 0 if x < 0 else x
>>
>> So I am wondering if there are any thoughts on what is more pythonic. The second way ran 4x as fast for me in python using the built in max function over 10,000 iterations. Which makes sense since the max function must do at least one comparison operation.
>>
>> Thoughts? Is speed the ultimate measure of what's pythonic? Or something else?
>>
>>
>> _______________________________________________
>> Chicago mailing list
>> Chicago at python.org
>> https://mail.python.org/mailman/listinfo/chicago
>>
>> _______________________________________________
>> Chicago mailing list
>> Chicago at python.org
>> https://mail.python.org/mailman/listinfo/chicago
>>
>
> _______________________________________________
> Chicago mailing list
> Chicago at python.org
> https://mail.python.org/mailman/listinfo/chicago
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/chicago/attachments/20170218/6b9e5e11/attachment.html>
More information about the Chicago
mailing list