Stuck on addConstraint vs factor

28 views
Skip to first unread message

Brian Lonsdorf

unread,
May 25, 2022, 12:30:02 PM5/25/22
to webppl-dev
Hi!

I'm working on learning probabilistic programming via the book https://www.manning.com/books/practical-probabilistic-programming

It is my speed. I'm using webppl at work and would like to port these examples over to help my understanding of the language.

They say "addConstraint" is a "soft constraint" which multiplies the probability. From the book:    
                   goodMood.addConstraint((b: Boolean) => if (b) 0.5; else 1.0)                    

"This soft constraint is interpreted as saying that all else being equal, goodMood being true is half as likely as goodMood being false, because 0.5 is half of 1.0. The precise mathematics of this is discussed in chapter 4, but the short version is that the probabilty of a value of an element is multiplied by the constraint results for that value."

I can't find the analog in Webppl. I tried to use factor(goodMood ? 0.5 : 1) but that doesn't seem to result in the same numeric outcome in my ported examples.

Here are futher examples of usage:

https://github.com/charles-river-analytics/figaro/blob/master/FigaroExamples/src/main/scala/com/cra/figaro/example/Smokers.scala

https://github.com/charles-river-analytics/figaro/blob/master/FigaroExamples/src/main/scala/com/cra/figaro/example/Firms.scala

Thanks for any pointers in the right direction. I've run out ideas to try.
-Brian

Noah Goodman

unread,
May 25, 2022, 12:51:47 PM5/25/22
to Brian Lonsdorf, webppl-dev
in webppl `factor` takes the log-probability, so if you throw a log around those numbers you should get what you expect.

out of curiosity, what are you using webppl for 'at work'?

best,

-N

------
Noah D. Goodman
Associate Professor of Psychology and Computer Science
Stanford University


--
You received this message because you are subscribed to the Google Groups "webppl-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to webppl-dev+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/webppl-dev/35e0635b-981b-4186-9eb2-48af72b24265n%40googlegroups.com.

Brian Lonsdorf

unread,
May 25, 2022, 1:38:51 PM5/25/22
to webppl-dev
Thank you! That did the trick :)

I am using it at Salesforce UX R&D for a number of things:

- creating agents/bots for testing/simulation
- web: page segmentation / component classification
- generative models
- ...all the things!

I'm very, very into it, but I'm not a statistician so I'm learning via the books aimed at typical "app programmers".
Reply all
Reply to author
Forward
0 new messages