-
Notifications
You must be signed in to change notification settings - Fork 3
/
ex.jl
90 lines (69 loc) · 1.46 KB
/
ex.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
using OnlineSampling
clear() = (_ = Base.run(`clear`))
reload() = (clear(); include("ex.jl"))
@node function counter()
@init x = 0
x = @prev(x) + 1
@show x
end
# @node T = 10 counter()
@node function incr(x)
return x + 1
end
@node function intricate_counter()
@init x = 0
x = @node incr(@prev(y))
y = x
@show x
end
# @node T = 10 intricate_counter()
function side_effect(arr, a, b)
push!(arr, a)
return b
end
function side_effect_int(arr, a, b::Integer)
push!(arr, a)
return b
end
@node function pathological_prev(arr)
@init x = 0
@init y = 0
y = @prev x
x = side_effect_int(arr, y, (@prev y) + 1)
@show x
end
arr = []
# @node T = 5 f(arr)
# arr == [0, 0, 1, 1, 2]
@node function ret_counter()
@init x = 0
x = @prev(x) + 1
return x
end
@node function test()
det = @node ret_counter()
smc = @node particles = 100 ret_counter()
@assert smc isa Cloud
@assert length(smc) == 100
@assert all(v -> v == det, smc)
end
# @node T = 5 test()
using LinearAlgebra, PDMats
using PDMats: ScalMat
Σ = ScalMat(1, 1.0)
@node function model()
@init x = rand(MvNormal([0.0], Σ))
x = rand(MvNormal(@prev(x), Σ))
y = rand(MvNormal(x, Σ))
return x, y
end
@node function hmm(obs)
x, y = @node model()
@observe(y, obs)
return x
end
@node function main(obs)
x = @node particles = 1000 hmm(obs)
end
obs = Vector{Float64}(1:5)
# @test_broken (@node T=5 main(obs))