probmods / webppl

Probabilistic programming for the web
http://webppl.org
Other
613 stars 89 forks source link

Add `score` helper #414

Open null-a opened 8 years ago

null-a commented 8 years ago

It’s probably confusing that sometimes the correct way to interact with a distribution is to call a method on it (e.g. dist.score(x)), and sometimes it’s to call a top-level function (e.g. sample(dist)). Perhaps we should add score(dist, x) for consistency, and promote its use.

Note that we already have entropy and MAP helpers that serve a similar purpose to the proposed score function.

@stuhlmueller pointed out that a minor consideration here is that people commonly use score as a variable name.

longouyang commented 8 years ago

We could alias it to scorer.

ngoodman commented 8 years ago

i have mixed feelings about this. on the one hand, we do need to clean up the confusion about dist.score(val) vs sample(dist). introducing score(dist, val) is the most straightforward solution.

on the other hand, it is much more idiomatic in js to use method calls, and i like dist.score(val). the other solution would be to make dist.sample() alias to the co-routine sampler within webppl. this might be tricky to do, and kind of ugly while #358 is open...

stuhlmueller commented 8 years ago

If we're planning to address #358 before 1.0 (which would be desirable, as it would help a lot with making bigger models more modular), I'd just keep sample/score as they are for now, and then introduce dist.sample() as the canonical way to sample from distributions. If we don't expect that we'll get to #358 for 1.0, I'm in favor of introducing the score helper.