charlesfrye / psych101d-demo

Subset of demonstration materials for PSYCH101-D, "Data Science for Research Psychology"
0 stars 0 forks source link

Suggestion: avoid confusion about the 'name' argument #7

Closed ANaka closed 5 years ago

ANaka commented 5 years ago

Speaking from experience - one thing that is a little weird about pymc3 and counterintuitive at first is that the first argument into a distribution has to be a string naming it. Especially if your students are new-ish at python, this is sort of a weird thing- the distribution creates a variable that has a name in the workspace, but the object linked to that variable also has a name as an attribute. I think pymc3 does this bc the name attribute is used as a prefix in naming variables that are subsumed by that object but I'm actually not totally sure what the logic was.

In any event, it's something that tripped me up when I started working w/ pymc3 and did again just now since it had been a little while. Name is not what you'd intuitively expect to be the first argument to a function defining a distribution, plus for whatever reason pymc3's docstrings for their distributions are really focused on the math of the distribution and don't say much about how to use them. So I'd recommend the following

1) explicitly use named arguments when defining distributions in your example code. so rather than

with coin_toss_model:
    coin_toss = pm.Categorical("coin_toss", [1 / 2, 1 / 2])

I'd recommend

with coin_toss_model:
    coin_toss = pm.Categorical(name = "coin_toss", vars = [1 / 2, 1 / 2])

2) Maybe stick a line somewhere that suggests a best practice of always making the name argument to a distribution/model the same as its name in the workplace

charlesfrye commented 5 years ago

These are great suggestions! Will incorporate.

charlesfrye commented 5 years ago

fixed in demo_issues branch of private repo