forked from mirkoklukas/CRP-mixtures-in-Gen
-
Notifications
You must be signed in to change notification settings - Fork 0
/
plotting.jl
69 lines (49 loc) · 1.61 KB
/
plotting.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
import PyPlot
plt = PyPlot;
function render_crp_trace(tr)
function cluster_sizes(c::Array{Int})
labels = Dict()
k = 1
n = Int[]
for i in c
if !haskey(labels, i)
labels[i] = k
push!(n, 1)
k += 1
else
n[labels[i]] += 1
end
end
n
end
T, α = get_args(tr)
c = get_retval(tr)
n = cluster_sizes(c)
fig, axs = plt.subplots(1,3, figsize=(10,1), sharey=true);
axs[1].scatter(1:T, c, s=1, marker=".", color="C0");
axs[1].plot(1:T, α*log.(1:T), color="C1", linewidth=1., linestyle=":");
axs[1].set_xlabel("time (\$t\$)"); axs[1].set_ylabel("cluster (\$c_t\$)");
axs[2].scatter(1:T, c, s=1, marker=".", color="C0");
axs[2].plot(1:T, α*log.(1:T), color="C1", linewidth=1., linestyle=":");
axs[2].set_xlabel("time (\$t\$)"); axs[1].set_ylabel("cluster (\$c_t\$)");
axs[2].set_xscale("log")
axs[3].barh(1:maximum(c), n[1:maximum(c)], color="green");
axs[3].set_xlabel("cluster size (\$n_t\$)");
end
function render_crp_mixture_tr(tr; bins=50)
fig, axs = plt.subplots(1,3, figsize=(10,0.5), sharex="col", gridspec_kw=Dict("width_ratios" => [3,3, 1]));
c, phi, x = get_retval(tr)
phi_vals = collect(values(phi))
k = length(phi)
n = zeros(k)
for i in c
n[i] += 1
end
perm = sortperm(n, rev=true)
axs[1].hist(x, bins=200)
for j=1:k
i = perm[j]
axs[2].scatter(x[c .== i], ones(sum(c .== i)).*i, alpha=1.,s=5, marker="o", zorder=1);
end
axs[3].hist(c, edgecolor="w");
end