-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRTS.wppl
More file actions
45 lines (37 loc) · 890 Bytes
/
RTS.wppl
File metadata and controls
45 lines (37 loc) · 890 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
// -*- mode:javascript -*-
var loop = function(f,n) {
if (n == 0)
return;
else {
f(n);
loop(f,n-1);
}
};
var hyp = function(prop) {
if (!prop) {
factor(-Infinity)
// if the property is not satisfied, discard this run.
}
}
var sampleAndShow = function(d,n) {
var iter = function(i) {
console.log(sample(d));
}
loop(iter,n);
};
var display = function(d,lo,hi,step) {
if (lo < hi) {
console.log(lo + ": " + Math.exp(d.score(lo)));
display(d,lo+step,hi,step);
}
}
var expectedPortion = function(p) {
return Math.exp(Infer({method: 'MCMC', samples: 100}, p).score(true));
}
var mainDiscrete = function(model) {
Infer({method: 'MCMC', samples: 1000}, model);
}
var mainContinuous = function(model) {
var d = Infer({method: 'MCMC', samples: 100000}, model);
sampleAndShow(d,100000);
}