-
Notifications
You must be signed in to change notification settings - Fork 17
/
Omega.jl
227 lines (190 loc) · 4.19 KB
/
Omega.jl
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
"A Expressive Library for Probabilistic Programming"
module Omega
import ForwardDiff, Flux
# Zygote,
using Spec
using UnicodePlots
using DocStringExtensions: FIELDS, SIGNATURES, TYPEDEF
using Cassette
using Lens
import Random
import Random: GLOBAL_RNG, AbstractRNG
import Statistics: mean, var, quantile
# Util
include("util/Util.jl")
using .Util
export ntranspose
# Core
include("space/Space.jl") # UIDs
using .Space
export Ω, uid, @id, SimpleΩ, LinearΩ
# RandVar
include("randvar/randvar.jl" ) # Random variables
include("randvar/urandvar.jl") # Random variables
include("randvar/randvarapply.jl") # Random variable application to ω::Ω
include("randvar/ciid.jl") # Conditionally i.i.d. RandVars
include("randvar/elemtype.jl") # Infer Element Type
export RandVar, MaybeRV, ciid, isconstant, elemtype, params, constant
# Conditioning
include("cond.jl") # Conditioning
export cond
# Lifted random variable operatiosn
include("lift/r.jl")
export ᵣ
include("lift/containers.jl") # Array/Tuple primitives
export randarray, randtuple, ==ᵣ, tupleᵣ, arrayᵣ
# Lifting functions to RandVar domain
include("lift/lift.jl")
export @lift, lift, lift!
# Soft Inference
include("soft/soft.jl") # Soft Booleans / logic
using .Soft
export d,
SoftBool,
softeq,
softlt,
softgt,
>ₛ,
>=ₛ,
<=ₛ,
<ₛ,
==ₛ,
err,
logerr,
anyₛ,
allₛ,
# Kernels
kse,
kseα,
kf1,
kf1β,
withkernel,
atα,
@atα,
indomainₛ,
applynotrackerr,
applytrackerr
# Soft.logerr(x::RandVar) = 3
import .Soft: logerr, softeq, softgt, softlt, err, kf1β, kseα
Omega.lift!(:softeq, 2)
Omega.lift!(:softeq, 3)
Omega.lift!(:softgt, 2)
Omega.lift!(:softlt, 2)
Omega.lift!(:logerr, 1)
Omega.lift!(:err, 1)
Omega.lift!(:kf1β, 1)
Omega.lift!(:kseα, 1)
# Higher-Order Inference
include("higher/Higher.jl")
using .Higher
export rcd, rid, ∥, ∥ₛ
# Gradient
include("gradient/Gradient.jl")
using .Gradient
export back!, lineargradient, TrackerGrad, ZygoteGrad, ForwardDiffGrad
# Inference Algorithms
include("inference/Inference.jl")
using .Inference
export isapproximate,
RejectionSample,
SSMH,
# SGHMC,
HMCFAST,
Relandscape,
Replica,
RejectionSampleAlg,
SSMHAlg,
HMCAlg,
# SGHMCAlg,
HMCFASTAlg,
RelandscapeAlg,
ReplicaAlg,
NUTS,
NUTSAlg,
defalg,
defcb,
defΩ,
defΩProj,
plotrv,
plotscalar,
default_cbs,
HMCStep,
default_cbs_tpl,
default_cbs,
Loop,
SSMHLoop
# Causal Inference
include("causal/Causal.jl")
using .Causal
export replace,
iscausebf,
cf
# Library
include("primitive/Prim.jl")
using .Prim
export bernoulli,
betarv,
β,
categorical,
# dirichlet,
exponential,
gammarv,
Γ,
invgamma,
kumaraswamy,
logistic,
# mvnormal,
normal,
poisson,
rademacher,
uniform
export succprob,
failprob,
maximum,
minimum,
islowerbounded,
isupperbounded,
isbounded,
std,
median,
mode,
modes,
skewness,
kurtosis,
isplatykurtic,
ismesokurtic,
isleptokurtic,
entropy,
mean,
prob,
lprob,
samplemean,
samplemeanᵣ
# Lifted distributional functions
export lsuccprob,
lfailprob,
lmaximum,
lminimum,
lislowerbounded,
lisupperbounded,
lisbounded,
lstd,
lmedian,
lmode,
lmodes,
lskewness,
lkurtosis,
lisplatykurtic,
lismesokurtic,
lisleptokurtic,
lentropy,
lmean
# Neural Network Stuff
include("flux.jl")
using .OmegaFlux
export OmegaDense
# Memoize
include("memoize.jl")
# Scaling errors
include("scaling.jl")
end