Joint probability of Bayesian Network

24 views
Skip to first unread message

Anna Pan

unread,
Feb 11, 2024, 8:28:17 PM2/11/24
to webppl-dev
Hi,

I am new to Webppl. I wonder how can I infer the joint probability over a Bayesian Network (BN) with some observations as a single number? Assuming I have such a BN as below:
/**
var bn = function() {
    var Cloudy = sample(Discrete({ps:[0.5, 0.5]}));
    var Sprinkler = Cloudy ? sample(Discrete({ps: [0.9, 0.1]})) : sample(Discrete({ps: [0.5, 0.5]}));
    var Rain = Cloudy ? sample(Discrete({ps: [0.2, 0.8]})) : sample(Discrete({ps: [0.8, 0.2]}));
    var WetGrass = Sprinkler ? (Rain ? sample(Discrete({ps: [0.01, 0.99]})): sample(Discrete({ps: [0.1, 0.9]})))
                                                : (Rain ? sample(Discrete({ps: [0.1, 0.9]})): sample(Discrete({ps: [1.0, 0.0]})));
    condition(WetGrass,1);
    //return [Cloudy, Rain, Sprinkler, WetGrass];
    //return sum([Cloudy, Rain, Sprinkler, WetGrass]);
    return {"WetGrass": WetGrass, "Rain": Rain, "Sprinkler": Sprinkler, "Cloudy": Cloudy};
}

var dist = Infer(
  {method: 'enumerate', maxExecutions: 1000000},
  bn);

print(dist);
viz.table(dist);
**/

Also, although this returns me a distribution table, this distribution table seems to be normalized. I wonder how should I do if I want a unnormalized one? 

Thank you so much for help!

Kind regards,
Jingwen

Tom Lieber

unread,
Feb 12, 2024, 10:47:56 AM2/12/24
to webppl-dev, Anna Pan
For your first question, I wonder if you're looking for distributions' score method?

dist.score({'WetGrass': 1, 'Rain': 1, 'Sprinkler': 1, 'Cloudy': 1});
// => -2.7936717238027855

 --
 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/a35bc934-7b94-4195-9574-13448b77e544n%40googlegroups.com.

null-a

unread,
Feb 13, 2024, 5:00:03 AM2/13/24
to webppl-dev
> how can I infer the joint probability over a Bayesian Network (BN) with some observations as a single number?

I might be able to help, but I'm not sure I understand the question, in particular the "with some observations as a single number" bit.

One guess is you're imagining a scenario in which you have multiple random variables (sample statements), and you'd like to condition on the result of combining these in some way. Here's an example of that kind of thing:

```
var xor = function(a,b) { return a != b; };
var myflip = function() { return flip(0.1); };
var model = function() {
  var xs = repeat(3, myflip);
  var parity = reduce(xor, false, xs)
  condition(parity == true)
  return xs;
};
var d = Infer(model);
viz.table(d);
```

If that doesn't help, maybe try asking the question in another way, and I'll try again.

Best,

Paul

Anna Pan

unread,
Feb 16, 2024, 12:02:27 PM2/16/24
to webppl-dev
Thank you for all the replies.

I have now resolved this issue now.
Reply all
Reply to author
Forward
0 new messages