Skip to content

Commit

Permalink
Merge pull request probmods#403 from null-a/add-bernoulli
Browse files Browse the repository at this point in the history
Add bernoulli helper
  • Loading branch information
stuhlmueller committed Apr 28, 2016
2 parents 9044d2c + 77bdb0b commit 0c3863f
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
9 changes: 7 additions & 2 deletions src/header.wppl
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,11 @@ defineErpConstructors(

// Helpers to sample from ERPs.

var bernoulli = function(arg) {
var params = erp.isParams(arg) ? arg : {p: arg};
return sample(bernoulliERP(params));
};

var randomInteger = function(arg) {
var params = erp.isParams(arg) ? arg : {n: arg};
return sample(randomIntegerERP(params));
Expand Down Expand Up @@ -90,8 +95,8 @@ var gamma = function(arg1, arg2) {

// Other ERP helpers

var flip = function(arg) {
var params = erp.isParams(arg) ? arg : {p: (arg !== undefined) ? arg : .5};
var flip = function(p) {
var params = {p: (p !== undefined) ? p : .5};
return sample(bernoulliERP(params));
};

Expand Down
2 changes: 1 addition & 1 deletion tests/test-data/stochastic/models/flips.wppl
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
var model = function() {
return flip() & flip(.2);
return flip() & bernoulli(.2);
};

0 comments on commit 0c3863f

Please sign in to comment.