-
Notifications
You must be signed in to change notification settings - Fork 0
/
test-nomh.js
318 lines (311 loc) · 8.49 KB
/
test-nomh.js
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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
__pr = require("./webchurch/probabilistic-js/probabilistic/index"); __pr.openModule(__pr);
__ch = require("./traced_builtins"); __pr.openModule(__ch);
__int = require("./trace_interface");
__sh = require("./shred");
function nfqp() {
__sh.reset_trace_state();
enterfn(0);
var call0 = _const(3.141592653589793);
leavefn();
var my_45pi = call0;
var glp = function (mean, ssq, smp) {
enterfn(14);
var call14 = minus(smp, mean);
leavefn();
enterfn(15);
var call15 = function (diff) {
enterfn(1);
var call1 = mult(diff, diff);
leavefn();
enterfn(2);
var call2 = _const(2);
leavefn();
enterfn(3);
var call3 = mult(call2, ssq);
leavefn();
enterfn(4);
var call4 = div(call1, call3);
leavefn();
enterfn(5);
var call5 = minus(call4);
leavefn();
enterfn(6);
var call6 = _const(0.5);
leavefn();
enterfn(7);
var call7 = _const(2);
leavefn();
enterfn(8);
var call8 = log(call7);
leavefn();
enterfn(9);
var call9 = log(my_45pi);
leavefn();
enterfn(10);
var call10 = log(ssq);
leavefn();
enterfn(11);
var call11 = plus(call8, call9, call10);
leavefn();
enterfn(12);
var call12 = mult(call6, call11);
leavefn();
enterfn(13);
var call13 = minus(call5, call12);
leavefn();
return call13;
}(call14);
leavefn();
return call15;
};
var randint = function (l, h) {
enterfn(16);
var call16 = _const(1);
leavefn();
enterfn(17);
var call17 = minus(h, l);
leavefn();
enterfn(18);
var call18 = plus(call16, call17);
leavefn();
enterfn(19);
var call19 = wrapped_random_integer(call18);
leavefn();
enterfn(20);
var call20 = plus(l, call19);
leavefn();
return call20;
};
var index_45in = function (x, xs) {
var loop = function (x, k, rst) {
enterfn(21);
var call21 = is_null(rst);
leavefn();
enterfn(29);
var call29 = _if(call21, function () {
return k;
}, function () {
enterfn(22);
var call22 = first(rst);
leavefn();
enterfn(23);
var call23 = is_equal(call22, x);
leavefn();
enterfn(28);
var call28 = _if(call23, function () {
return k;
}, function () {
enterfn(24);
var call24 = _const(1);
leavefn();
enterfn(25);
var call25 = plus(k, call24);
leavefn();
enterfn(26);
var call26 = rest(rst);
leavefn();
enterfn(27);
var call27 = loop(x, call25, call26);
leavefn();
return call27;
});
leavefn();
return call28;
});
leavefn();
return call29;
};
enterfn(30);
var call30 = _const(0);
leavefn();
enterfn(31);
var call31 = loop(x, call30, xs);
leavefn();
return call31;
};
var my_45length = function (xs) {
enterfn(32);
var call32 = is_null(xs);
leavefn();
enterfn(38);
var call38 = _if(call32, function () {
enterfn(33);
var call33 = _const(0);
leavefn();
return call33;
}, function () {
enterfn(34);
var call34 = _const(1);
leavefn();
enterfn(35);
var call35 = rest(xs);
leavefn();
enterfn(36);
var call36 = my_45length(call35);
leavefn();
enterfn(37);
var call37 = plus(call34, call36);
leavefn();
return call37;
});
leavefn();
return call38;
};
var data_45loop = function (n) {
enterfn(39);
var call39 = _const(3);
leavefn();
enterfn(40);
var call40 = eq(n, call39);
leavefn();
enterfn(47);
var call47 = _if(call40, function () {
enterfn(41);
var call41 = _const([null]);
leavefn();
return call41;
}, function () {
enterfn(42);
var call42 = list(n, n);
leavefn();
enterfn(43);
var call43 = _const(1);
leavefn();
enterfn(44);
var call44 = plus(n, call43);
leavefn();
enterfn(45);
var call45 = data_45loop(call44);
leavefn();
enterfn(46);
var call46 = pair(call42, call45);
leavefn();
return call46;
});
leavefn();
return call47;
};
enterfn(48);
var call48 = _const(0);
leavefn();
enterfn(49);
var call49 = data_45loop(call48);
leavefn();
var data = call49;
enterfn(50);
var call50 = map(first, data);
leavefn();
enterfn(51);
var call51 = sum(call50);
leavefn();
enterfn(52);
var call52 = my_45length(data);
leavefn();
enterfn(53);
var call53 = div(call51, call52);
leavefn();
var xbar = call53;
var make_45sample = function () {
enterfn(54);
var call54 = _const(0);
leavefn();
enterfn(55);
var call55 = _const(10000);
leavefn();
enterfn(56);
var call56 = wrapped_gaussian(call54, call55);
leavefn();
var alpha = call56;
enterfn(57);
var call57 = _const(0);
leavefn();
enterfn(58);
var call58 = _const(10000);
leavefn();
enterfn(59);
var call59 = wrapped_gaussian(call57, call58);
leavefn();
var wrapped_beta = call59;
enterfn(60);
var call60 = _const(0);
leavefn();
enterfn(61);
var call61 = _const(10000);
leavefn();
enterfn(62);
var call62 = wrapped_gaussian(call60, call61);
leavefn();
enterfn(63);
var call63 = abs(call62);
leavefn();
var tau = call63;
var gauss_45factor = function (m, v, x) {
enterfn(64);
var call64 = glp(m, v, x);
leavefn();
enterfn(65);
var call65 = wrapped_factor(call64);
leavefn();
return call65;
};
enterfn(74);
var call74 = map(function (xy) {
enterfn(66);
var call66 = first(xy);
leavefn();
enterfn(67);
var call67 = minus(call66, xbar);
leavefn();
enterfn(68);
var call68 = mult(wrapped_beta, call67);
leavefn();
enterfn(69);
var call69 = plus(alpha, call68);
leavefn();
enterfn(70);
var call70 = _const(1);
leavefn();
enterfn(71);
var call71 = div(call70, tau);
leavefn();
enterfn(72);
var call72 = second(xy);
leavefn();
enterfn(73);
var call73 = gauss_45factor(call69, call71, call72);
leavefn();
return call73;
}, data);
leavefn();
var y_45constrs = call74;
enterfn(75);
var call75 = _const(1);
leavefn();
enterfn(76);
var call76 = _const(0.5);
leavefn();
enterfn(77);
var call77 = expt(tau, call76);
leavefn();
enterfn(78);
var call78 = div(call75, call77);
leavefn();
enterfn(79);
var call79 = list(alpha, wrapped_beta, call78, tau);
leavefn();
var sample = call79;
return sample;
};
enterfn(80);
var call80 = make_45sample();
leavefn();
var sample = call80;
return sample;
}
var tr = newTrace(nfqp, "nothing");
__sh.trace_cell.trace = tr;
nfqp();
nfqp();
nfqp();
// tr.reset();
// console.log(__sh.dump_dssa());