Access CDT

18 views
Skip to first unread message

Anna Pan

unread,
Feb 16, 2024, 12:07:53 PM2/16/24
to webppl-dev
Dear all, 

I wonder how can I access the CDT to get specific conditional probability with the CDT returned by the inference engine?

For example, we have such CDT called 'dist' after the inference:
//Marginal:
//    [false,0] : 0.23545668285031618
//    [false,9] : 0.22692551754453993
//    [false,1] : 0.10529766747355232
//    [false,8] : 0.10341959637031478
//    [false,2] : 0.059348236395820736
//    [false,7] : 0.057979813050466365
//    [false,3] : 0.03852614417652475
//    [false,6] : 0.03802425917899331
//    [false,4] : 0.031239584088303955
//    [false,5] : 0.03061726524571446
//    [true,0] : 0.0201963346898075
//    [true,9] : 0.019268338665080032
//    [true,1] : 0.008556333595552952
//    [true,8] : 0.008426759038107046
//    [true,7] : 0.0045025022828104715
//    [true,2] : 0.00430280144089583
//    [true,6] : 0.00243327667988088
//    [true,3] : 0.0023400025682024706
//    [true,5] : 0.0016296952207360278
//    [true,4] : 0.0015091894443803797

Is there any access method for getting "[true,3] : 0.0023400025682024706" from this CDT? 

Thank you for help!

Kind regards,
Jingwen


null-a

unread,
Feb 16, 2024, 1:02:09 PM2/16/24
to webppl-dev
The `score` method on a distribution returns the log probability (/density) of a particular value, so i think what you're looking for is `Math.exp(dist.score([true, 3]))`.

Best,

Paul

Anna Pan

unread,
Feb 19, 2024, 9:02:04 AM2/19/24
to webppl-dev

Hi,

Thank you so much! It works as expected. 

I wonder if WebPPL has any built-in function that can return the inferred probability as an array. 

For example, assuming we have:
print(dist); // {"probs":[0.9970065507586945,0.0029934492413055476],"support":[false,true]}

and I would expect a possible access like: dist.probs, which will return [0.9970065507586945,0.0029934492413055476].

Kind regards,
Jingwen

null-a

unread,
Feb 19, 2024, 11:55:51 AM2/19/24
to webppl-dev
You can compute that yourself, something like this:

`map(function(x) { return Math.exp(d.score(x)) }, d.support());`

Best,

Paul

Anna Pan

unread,
Feb 23, 2024, 5:27:59 PM2/23/24
to webppl-dev
Sorry for the late reply. 

Problem is resolved. Thank you so much for help.

Kind regards,
Jingwen

Reply all
Reply to author
Forward
0 new messages