Skip to content

Commit

Permalink
Merge pull request probmods#393 from null-a/erp-new-sample-interface
Browse files Browse the repository at this point in the history
New ERP Interface
  • Loading branch information
stuhlmueller committed Apr 27, 2016
2 parents 373efb6 + 9bfc3bc commit 619a14e
Show file tree
Hide file tree
Showing 46 changed files with 709 additions and 658 deletions.
2 changes: 1 addition & 1 deletion examples/hmmSampleWithFactor.wppl
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ var trueObs = [false, false, false]

var hmmRecur = function(n, states, observations) {
var newState = transition(states[states.length - 1])
var newObs = sampleWithFactor(observe(newState), [],
var newObs = sampleWithFactor(observe(newState),
function(v) {return v == trueObs[observations.length] ? 0 : -Infinity})
var newStates = states.concat([newState])
var newObservations = observations.concat([newObs])
Expand Down
4 changes: 2 additions & 2 deletions examples/ldaCollapsed.wppl
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,13 @@ var makeDirichletDiscrete = function(pseudocounts) {
globalStore[ddname] = pseudocounts;
var ddSample = function() {
var pc = globalStore[ddname]; // get current sufficient stats
var val = sample(discreteERP, [pc]); // sample from predictive. (doesn't need to be normalized.)
var val = sample(discreteERP({ps: pc})); // sample from predictive. (doesn't need to be normalized.)
globalStore[ddname] = addCount(pc, val); // update sufficient stats
return val;
};
var ddObserve = function(val) {
var pc = globalStore[ddname]; // get current sufficient stats
factor(discreteERP.score([normalize(pc)], val));
factor(discreteERP({ps: normalize(pc)}).score(val));
// score based on predictive distribution (normalize counts)
globalStore[ddname] = addCount(pc, val); // update sufficient stats
};
Expand Down
4 changes: 2 additions & 2 deletions examples/linearRegression.wppl
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@ var ys = [0, 1, 4, 6]
var model = function() {
var m = gaussian(0, 2)
var b = gaussian(0, 2)
var sigmaSquared = gamma(1, 1)
var sigma = gamma(1, 1)

var f = function(x) {
return m * x + b
}

map2(
function(x, y) {
factor(gaussianERP.score([(f(x)), sigmaSquared], y))
factor(gaussianERP({mu: f(x), sigma: sigma}).score(y))
},
xs,
ys)
Expand Down
6 changes: 3 additions & 3 deletions examples/logisticRegression.wppl
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,18 @@ var labels = [false, false, true, true, true]
var model = function() {
var m = gaussian(0, 1)
var b = gaussian(0, 1)
var sigmaSquared = gamma(1, 1)
var sigma = gamma(1, 1)

var y = function(x) {
return gaussian(m * x + b, sigmaSquared)
return gaussian(m * x + b, sigma)
}
var sigmoid = function(x) {
return 1 / (1 + Math.exp(-1 * y(x)))
}

map2(
function(x, label) {
factor(bernoulliERP.score([sigmoid(x)], label))
factor(bernoulliERP({p: sigmoid(x)}).score(label))
},
xs,
labels)
Expand Down
9 changes: 0 additions & 9 deletions examples/multiplex.wppl

This file was deleted.

4 changes: 2 additions & 2 deletions examples/multivariateRegression.wppl
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,15 @@ var model = function() {
var cov = numeric.diag([1, 1])
var m = multivariateGaussian([0, 0], cov)
var e = gaussian(0, 2)
var sigmaSquared = gamma(1, 1)
var sigma = gamma(1, 1)

var f = function(x) {
return numeric.dot(m, x) + e
}

map2(
function(x, y) {
factor(gaussianERP.score([(f(x)), sigmaSquared], y))
factor(gaussianERP({mu: f(x), sigma: sigma}).score(y))
},
xs,
ys)
Expand Down
4 changes: 2 additions & 2 deletions examples/pragmaticsWithSemanticParsing.wppl
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ var speaker = cache(function(world) {
Enumerate(function() {
var utterance = utterancePrior()
var L = literalListener(utterance)
factor(L.score([], world))
factor(L.score(world))
return utterance
}, 100)
})
Expand All @@ -170,7 +170,7 @@ var listener = function(utterance) {
var world = worldPrior(2, function(w) {return 1}) //use vacuous meaning to avoid any guide...
// var world = worldPrior(2, meaning(utterance)) //guide by literal meaning
var S = speaker(world)
factor(S.score([], utterance))
factor(S.score(utterance))
return isall(world)
}, 100)
}
Expand Down
4 changes: 2 additions & 2 deletions examples/scalarImplicature.wppl
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ var speaker = cache(function(world) {
Enumerate(function() {
var utterance = utterancePrior()
var L = literalListener(utterance)
factor(L.score([], world))
factor(L.score(world))
return utterance
})
})
Expand All @@ -40,7 +40,7 @@ var listener = function(utterance) {
Enumerate(function() {
var world = worldPrior()
var S = speaker(world)
factor(S.score([], utterance))
factor(S.score(utterance))
return world
})
}
Expand Down
2 changes: 1 addition & 1 deletion examples/semiMarkovRandomWalkConstrained.wppl
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ var transition = function(lastPos, secondLastPos) {

var observeConstrained = function(pos, trueObs) {
return map2(
function(x, obs) { factor(gaussianERP.score([x, 5], obs)); },
function(x, obs) { factor(gaussianERP({mu: x, sigma: 5}).score(obs)); },
pos,
trueObs
);
Expand Down
2 changes: 1 addition & 1 deletion src/aggregation/distribution.ad.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ function normalize(dist) {
}

Distribution.prototype.toERP = function() {
return erp.makeMarginalERP(normalize(this.dist));
return new erp.marginal({dist: normalize(this.dist)});
};

module.exports = Distribution;
2 changes: 1 addition & 1 deletion src/aggregation/histogram.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ function normalize(hist) {
}

Histogram.prototype.toERP = function() {
return erp.makeMarginalERP(normalize(this.hist));
return new erp.marginal({dist: normalize(this.hist)});
};

module.exports = Histogram;
Loading

0 comments on commit 619a14e

Please sign in to comment.