Comments (2)
I think the answer may be that the broken Inference about Inference examples should use cache instead of mem. This seems to produce the right behaviour (second example):
///fold:
var getProbs = function(vector) {
return map(function(i) {return T.get(vector,i)}, _.range(vector.length))
}
var chooseAction = function(goalSatisfied, transition, state) {
return Infer({method: 'rejection', samples: 1}, function() {
var action = actionPrior()
condition(goalSatisfied(transition(state, action)))
return action;
})
}
///
var actionPrior = function() {
return flip(.7) ? ['a'] : ['a'].concat(actionPrior());
}
var goalPosterior = Infer({method: 'rejection', samples: 5000}, function() {
var buttonsToOutcomeProbs = cache(function(buttons) {return getProbs(dirichlet(ones([2,1])))})
var vendingMachine = function(state, action) {
return categorical({vs: ['bagel', 'cookie'], ps: buttonsToOutcomeProbs(action)});
}
var goal = categorical({vs: ['bagel', 'cookie'], ps: [.5, .5]})
var goalSatisfied = function(outcome) {return outcome == goal};
var actionDist = chooseAction(goalSatisfied, vendingMachine, 'state');
var chosenAction = sample(chooseAction(goalSatisfied, vendingMachine, 'state'));
//corrected condition
condition(vendingMachine('state', ['a', 'a']) == 'cookie' &&
_.isEqual(chosenAction, ['a', 'a']))
return {goal: goal,
once: buttonsToOutcomeProbs(['a'])[1],
twice: buttonsToOutcomeProbs(['a', 'a'])[1]}
})
print("probability of actions giving a cookie")
viz.marginals(goalPosterior);
from probmods2.
thanks for all of these suggestions! most were incorporated long ago (forgot to close the issue), but i've also just cleaned this up, and all seem to be working!
from probmods2.
Related Issues (20)
- Typos all over
- Readings page link seems broken HOT 1
- Unexpected use of `let` in WebPPL code box
- Migration to Gen? HOT 1
- Clarify LICENSE HOT 1
- Clarify model criticism section in bayesian data analysis chapter HOT 1
- chapter 9 / learning as Inference / de Finetti representation of Polya's urn
- Katex vs mathjax
- Make exercise pages nicer for working HW
- link on github repo is broken
- Marr's vision link is not found
- add exercise for process models chapter
- fix inference algorithms questions
- add additional scaffolding to distribution appendix
- flesh out rational process models chapter HOT 1
- clarify arithmetic generator in LoT chapter HOT 1
- updates to process model exercises
- updates to Occam's exercises
- Fix Occam's razor exercises
- fix mixture model exercises
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from probmods2.