Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #98778 > unrolled thread
| Started by | fl <rxjwg98@gmail.com> |
|---|---|
| First post | 2015-11-13 15:04 -0800 |
| Last post | 2015-11-14 09:14 +0000 |
| Articles | 5 — 5 participants |
Back to article view | Back to comp.lang.python
What is '@' for fl <rxjwg98@gmail.com> - 2015-11-13 15:04 -0800
Re: What is '@' for Chris Angelico <rosuav@gmail.com> - 2015-11-14 10:14 +1100
Re: What is '@' for Tim Daneliuk <tundraBOGUS@tundraware.com> - 2015-11-13 17:43 -0600
Re: What is '@' for Terry Reedy <tjreedy@udel.edu> - 2015-11-13 18:43 -0500
Re: What is '@' for Dave Farrance <df@see.replyto.invalid> - 2015-11-14 09:14 +0000
| From | fl <rxjwg98@gmail.com> |
|---|---|
| Date | 2015-11-13 15:04 -0800 |
| Subject | What is '@' for |
| Message-ID | <b4254670-28c9-4e2c-a221-a27c0d6f62e9@googlegroups.com> |
Hi,
I read the following code snippet. A question is here about '@'.
I don't find the answer online yet.
What function is it here?
BTW, below is for printing out?
"""theta = logit^{-1}(a+b)"""
but I don't see it is printed when the following could have been called.
Are you sure it would be printed out?
Thanks,
.................
import pymc
import numpy as np
n = 5*np.ones(4,dtype=int)
x = np.array([-.86,-.3,-.05,.73])
alpha = pymc.Normal('alpha',mu=0,tau=.01)
beta = pymc.Normal('beta',mu=0,tau=.01)
@pymc.deterministic
def theta(a=alpha, b=beta):
"""theta = logit^{-1}(a+b)"""
return pymc.invlogit(a+b*x)
d = pymc.Binomial('d', n=n, p=theta, value=np.array([0.,1.,3.,5.]),\
observed=True)
[toc] | [next] | [standalone]
| From | Chris Angelico <rosuav@gmail.com> |
|---|---|
| Date | 2015-11-14 10:14 +1100 |
| Message-ID | <mailman.311.1447456460.16136.python-list@python.org> |
| In reply to | #98778 |
On Sat, Nov 14, 2015 at 10:04 AM, fl <rxjwg98@gmail.com> wrote:
> I read the following code snippet. A question is here about '@'.
> I don't find the answer online yet.
>
> What function is it here?
>
>
> @pymc.deterministic
> def theta(a=alpha, b=beta):
> """theta = logit^{-1}(a+b)"""
> return pymc.invlogit(a+b*x)
That's called a "function decorator". And now that you know the name,
you'll be able to find what it is online; as well as the Python docs,
there are a number of blog posts and other articles about it.
ChrisA
[toc] | [prev] | [next] | [standalone]
| From | Tim Daneliuk <tundraBOGUS@tundraware.com> |
|---|---|
| Date | 2015-11-13 17:43 -0600 |
| Message-ID | <56467593.9060304@tundraware.com> |
| In reply to | #98779 |
On 11/13/2015 05:14 PM, Chris Angelico wrote:
> On Sat, Nov 14, 2015 at 10:04 AM, fl <rxjwg98@gmail.com> wrote:
>> I read the following code snippet. A question is here about '@'.
>> I don't find the answer online yet.
>>
>> What function is it here?
>>
>>
>> @pymc.deterministic
>> def theta(a=alpha, b=beta):
>> """theta = logit^{-1}(a+b)"""
>> return pymc.invlogit(a+b*x)
>
> That's called a "function decorator". And now that you know the name,
> you'll be able to find what it is online; as well as the Python docs,
> there are a number of blog posts and other articles about it.
>
> ChrisA
>
One small point of order ... if you want to be precise, "@pymc.deterministic" is a *function decoration*. The "decorator" is the function pymc.deterministic().
I know this is a fussy point, but this distinction is helpful when first learning the concept.
[toc] | [prev] | [next] | [standalone]
| From | Terry Reedy <tjreedy@udel.edu> |
|---|---|
| Date | 2015-11-13 18:43 -0500 |
| Message-ID | <mailman.312.1447458240.16136.python-list@python.org> |
| In reply to | #98778 |
On 11/13/2015 6:04 PM, fl wrote: > I read the following code snippet. A question is here about '@'. > I don't find the answer online yet. Start with the index of the fine docs, which includes symbols. https://docs.python.org/3/genindex-Symbols.html '@' is near the end of the page. > @pymc.deterministic > def theta(a=alpha, b=beta): -- Terry Jan Reedy
[toc] | [prev] | [next] | [standalone]
| From | Dave Farrance <df@see.replyto.invalid> |
|---|---|
| Date | 2015-11-14 09:14 +0000 |
| Message-ID | <snud4bpm6d7cf6lg20q1a5675uc25av1kg@4ax.com> |
| In reply to | #98778 |
fl <rxjwg98@gmail.com> wrote: >I read the following code snippet. A question is here about '@'. >I don't find the answer online yet. I recommend this: "Understanding Python Decorators in 12 Easy Steps!" http://simeonfranklin.com/blog/2012/jul/1/python-decorators-in-12-steps/
[toc] | [prev] | [standalone]
Back to top | Article view | comp.lang.python
csiph-web