-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGenQuantExamples.hs
More file actions
214 lines (153 loc) · 3.21 KB
/
GenQuantExamples.hs
File metadata and controls
214 lines (153 loc) · 3.21 KB
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
module GenQuantExamples where
import Lib
import Control.Monad
import Prelude hiding (or,and)
ex1 :: P (Expr Bool)
ex1 = do
car <- newPred
red <- newPred
observe (most car red)
return (some car red)
-- >>> run ex1
-- Marginal:
-- true : 0.999
-- false : 0.001
ex2 :: P (Expr Bool)
ex2 = do
car <- newPred
red <- newPred
observe (every car red)
return (most car red)
-- >>> run ex2
-- Marginal:
-- true : 0.991
-- false : 0.009
ex3a :: P (Expr Bool)
ex3a = do
chair <- newPred
fourlegs <- newPred
observe (many chair fourlegs)
x <- newIndSuch [fourlegs]
return (chair x)
-- >>> run ex3a
-- Marginal:
-- true : 0.653
-- false : 0.347
ex3b :: P (Expr Bool)
ex3b = do
chair <- newPred
fourlegs <- newPred
observe (many chair fourlegs)
x <- newIndSuch [chair]
return (fourlegs x)
-- >>> run ex3b
-- Marginal:
-- true : 0.821
-- false : 0.179
ex3c :: P (Expr Bool)
ex3c = do
chair <- newPred
fourlegs <- newPred
comfy <- newPred
observe (most chair fourlegs)
observe (most chair comfy)
x <- newIndSuch [chair]
return (fourlegs x)
-- >>> run ex3c
-- Success!
-- Marginal:
-- true : 0.925
-- false : 0.075
ex3d :: P (Expr Bool)
ex3d = do
chair <- newPred
fourlegs <- newPred
observe (many chair fourlegs)
observe (most anything (not' . chair))
x <- newIndSuch [fourlegs]
return (chair x)
-- Marginal:
-- false : 0.779
-- true : 0.221
ex4a :: P (Expr Bool)
ex4a = do
animal <- newPred
bird <- newPred
fly <- newPred
observe (most bird fly)
observe (some animal bird)
x <- newIndSuch [animal]
return (fly x)
-- >>> run ex4a
-- Creating model...
-- Running webppl...
-- Success!
-- Marginal:
-- true : 0.778
-- false : 0.222
ex4c :: P (Expr Bool)
ex4c = do
fly <- newPred
observe (most anything (\x -> not' (fly x)))
bird <- newPred
observe (most anything (\x -> not' (bird x)))
observe (most bird fly)
x <- newIndSuch [bird]
return (fly x)
-- >>> run ex4c
-- Success!
-- Marginal:
-- true : 0.78
-- false : 0.22
ex4d :: P (Expr Bool)
ex4d = do
animal <- newPred
bird <- newPred
fly <- newPred
observe (most animal (\x -> not' (fly x)))
observe (most bird fly)
observe (most animal (not' . bird))
observe (every bird animal)
x <- newIndSuch [bird]
return (fly x)
-- Marginal:
-- true : 0.9
-- false : 0.1
ex4e :: P (Expr Bool)
ex4e = do
animal <- newPred
bird <- newPred
fly <- newPred
observe (most animal (\x -> not' (fly x)))
observe (most bird fly)
observe (most animal (not' . bird))
observe (every bird animal)
x <- newIndSuch [animal]
return (fly x)
-- Marginal:
-- false : 0.807
-- true : 0.193
ex4f :: P (Expr Bool)
ex4f = do
animal <- newPred
bird <- newPred
fly <- newPred
observe (most animal (\x -> not' (fly x)))
observe (most bird fly)
observe (every bird animal)
x <- newIndSuch [animal]
return (bird x)
-- Marginal:
-- false : 0.743
-- true : 0.257
ex4g :: P (Expr Bool)
ex4g = do
animal <- newPred
bird <- newPred
fly <- newPred
observe (most animal (not' . fly))
observe (most bird fly)
observe (every bird animal)
return (most animal (not' . bird))
main :: IO ()
main = run ex4g