forked from probmods/webppl
-
Notifications
You must be signed in to change notification settings - Fork 1
/
structure.wppl
96 lines (61 loc) · 2.96 KB
/
structure.wppl
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
var data = [];
var model = function() {
//We may want to just do mean field on the global model.
// Make the sampleDAIPP helper do mean field as default if context is not initialized?
//If we do want neural guides (to capture correlations) we init here, but probably with
// either a zero vector or some compact summary of the data.
initContext(dataSummary);
// The section of the program outside of mapData is what we're calling the 'global model'.
// Global choices | begin
var theta = sampleDaipp(erp);
// ...
// Global choices | end
// During sleep: global choices are sampled from the guide. (No
// importance weighting.)
//store the "global context" if we're using it:
var globalContext = globalStore.context;
mapData(data, function(datum) {
// This is the 'observation function'
// At this point, we reinstall the context in which
// mapData is called and then incorporate the datum:
globalStore.context = globalContext;
updateContext(datum);
// If there's no intsresting action in the global guide, then we could just
// initContext(datum) here.
// The 'recognition model' is the part of the guide that goes from
// a datum (above) to guide params for the following local
// choices.
// (Note that the global and recognition models share
// lots of parameters. We may want to correct that?)
// Local choices | start
var z = sampleDaipp(erp);
// ...
// Local choices | end
// During sleep: local choices are sampled from the target.
// Observe data
d = observe(erp,datum)
// During wake (VI) observe(erp, datum) is
// factor(erp.score(datum)) as usual (but returns value datum).
// During sleep observe(erp, datum) is sample(erp).
//NOTE: during sleep we'll need to get the datum in the same format that it is passed
// in during wake. If there are multiple observe calls we may need an observeData(...) helper
// to register the sampled data in the right format.
return z; //or whatever.
});
return somethingInterestingAboutThetaOrZ;
};
// For sleep:
//Each sleep step samples a "fantacy trace" of global+local as described above.
//It then uses the fantasy trace plus the fantasy datum to optimized the (local) guide with TT.
// To make this work we need to:
// 1. Capture the fantasy data. (As the value returned by `observe` or `observeData`.)
// 2. Pass the fantasy data into `Optimize` (along with the
// fantasy trace) and arrange things such that mapData calls the
// observation function with the fantasy data, rather than the
// training data (so that the recognition model is trained on
// fantasies).
// So sleep encourages the recognition model to be a good model of the
// 'conditional prior' (aka the posterior for fantasy data). (And the global model
// to keep doing what it's doing.)
// There's some book keeping to do if we have multiple (perhaps
// nested) calls to mapData? Let's assume for now that this doesn't happen!