Skip to content

Commit b32e8c8

Browse files
committed
Pass on plots
1 parent f5d0991 commit b32e8c8

16 files changed

+256
-236
lines changed

docs/plots/hard_core_graph.jl

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
1-
# const PRS = PartialRejectionSampling, Plots, GraphPlot, Colors, LS = LazySets, LG = LightGraphs
2-
includet("docs/plots/pedagogy_graph.jl")
1+
include(joinpath(@__DIR__, "pedagogy_graph.jl"))
2+
using Random
33

44
dims = [5, 5]
55
g = LG.grid(dims)
66
β = 1.0
77

88
hcg = PRS.HardCoreGraph(g, β)
99

10-
using Random
1110
rng = Random.MersenneTwister(123)
1211
@time sample = PRS.generate_sample_prs(rng, hcg)
1312

14-
p = plot(hcg, sample, dims, "docs/plots/output/hard_core_graph.pdf")
13+
path = joinpath(@__DIR__, "output", "hard_core_graph", "hard_core_graph.pdf")
14+
p = plot(hcg, sample, dims, path)
1515

16-
@time sample = PRS.generate_sample_prs(hcg)
16+
# @time sample = PRS.generate_sample_prs(hcg)
Lines changed: 2 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -1,67 +1,11 @@
1-
# const PRS = PartialRejectionSampling, Plots, GraphPlot, Colors, LS = LazySets, LG = LightGraphs
2-
includet("docs/plots/pedagogy_graph.jl")
1+
include(joinpath(@__DIR__, "pedagogy_graph.jl"))
32
using Random
43

54
dims = [5, 5]
65
g = LG.grid(dims)
76
β = 0.5
87

98
pp = PRS.HardCoreGraph(g, β)
10-
119
rng = Random.MersenneTwister(123)
1210

13-
path(i) = joinpath("docs/plots/output/hard_core_graph", join([lpad(i, 3, "0"), ".pdf"]))
14-
15-
c_node_normal = Colors.colorant"turquoise";
16-
17-
c_node_unccupied = Colors.colorant"white";
18-
c_node_occupied = Colors.colorant"gray";
19-
20-
c_node_update = Colors.colorant"orange";
21-
c_node_bad = Colors.colorant"red";
22-
23-
i = 0
24-
c_nodes = fill(c_node_normal, LG.nv(pp.graph))
25-
plot(pp.graph, dims, path(i); nodefillc=c_nodes)
26-
27-
proba = pp.β / (one(pp.β) + pp.β)
28-
29-
adj = LG.adjacency_matrix(pp.graph)
30-
occupied = Random.randsubseq(rng, LG.vertices(pp.graph), proba)
31-
32-
while true
33-
34-
i += 1
35-
c_nodes = fill(c_node_unccupied, LG.nv(pp.graph))
36-
c_nodes[occupied] .= c_node_occupied
37-
plot(pp.graph, dims, path(i); nodefillc=c_nodes)
38-
39-
# Check if occupied vertices form an independent set
40-
sub_graph = LG.SimpleGraph(adj[occupied, occupied])
41-
LG.ne(sub_graph) == 0 && break
42-
43-
bad = []
44-
independent, resample = [], Set()
45-
for cc in LG.connected_components(sub_graph)
46-
if length(cc) == 1 # Identify current independent vertices
47-
append!(independent, occupied[cc])
48-
else # Construct the resampling set of vertices
49-
union!(resample, occupied[cc])
50-
union!(bad, occupied[cc])
51-
for v in cc
52-
union!(resample, LG.neighbors(pp.graph, occupied[v]))
53-
end
54-
end
55-
end
56-
57-
i += 1
58-
c_nodes[bad] .= c_node_bad
59-
plot(pp.graph, dims, path(i); nodefillc=c_nodes)
60-
61-
Random.randsubseq!(rng, occupied, collect(resample), proba)
62-
append!(occupied, independent)
63-
64-
i += 1
65-
c_nodes[collect(resample)] .= c_node_update;
66-
plot(pp.graph, dims, path(i); nodefillc=c_nodes)
67-
end
11+
hard_core_graph_pedagogy(pp, dims, rng)

docs/plots/hard_core_spatial.jl

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
# const PRS = PartialRejectionSampling, Plots, GraphPlot, Colors, LS = LazySets, LG = LightGraphs
2-
includet("docs/plots/pedagogy_spatial.jl")
1+
include(joinpath(@__DIR__, "pedagogy_spatial.jl"))
2+
using Random
33

44
β₀ = 0.1
55
r = 0.05 # interaction range = 2*radius
@@ -10,7 +10,6 @@ win = PRS.SquareWindow(c, w)
1010

1111
hc = PRS.HardCorePointProcess(b, r, win)
1212

13-
using Random
1413
rng = Random.MersenneTwister(123)
1514
@time sample = PRS.generate_sample_prs(rng, hc)
1615
# @time sample = PRS.generate_sample_grid_prs(rng, hc)
Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
# const PRS = PartialRejectionSampling, Plots, GraphPlot, Colors, LS = LazySets, LG = LightGraphs
2-
includet("docs/plots/pedagogy_spatial.jl")
1+
include(joinpath(@__DIR__, "pedagogy_spatial.jl"))
2+
using Random
33

44
β₀ = 0.3
55
r = 0.1 # interaction range = 2*radius
@@ -10,6 +10,5 @@ win = PRS.SquareWindow(c, w)
1010

1111
hc = PRS.HardCorePointProcess(b, r, win)
1212

13-
using Random
1413
rng = Random.MersenneTwister(123)
15-
pedagogy_generate_sample_prs(hc; rng=rng)
14+
hard_core_spatial_pedagogy(hc; rng=rng)

docs/plots/ising_gibbs_perfect.jl

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,14 @@
1-
# const PRS = PartialRejectionSampling, Plots, GraphPlot, Colors, LS = LazySets, LG = LightGraphs
2-
includet("docs/plots/pedagogy_graph.jl")
1+
include(joinpath(@__DIR__, "pedagogy_graph.jl"))
2+
using Random
33

44
dims = [15, 15] # if > (14, 14) the display becomes all black, don't know why !
55
periodic = false
66
H, J = 0.0, 0.01
77

88
ising = PRS.Ising(dims, J, H; periodic=periodic)
99

10-
using Random
1110
rng = Random.MersenneTwister(123)
1211
@time sample = PRS.generate_sample_gibbs_perfect(rng, ising)
1312

14-
p = plot(ising, sample, dims, "docs/plots/output/ising_gibbs_perfect.pdf";
15-
nodelabel=nothing)
13+
path = joinpath(@__DIR__, "output", "ising", "ising_gibbs_perfect.pdf")
14+
p = plot(ising, sample, dims, path; nodelabel=nothing)

docs/plots/ising_grid_prs.jl

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
# const PRS = PartialRejectionSampling, Plots, GraphPlot, Colors, LS = LazySets, LG = LightGraphs
2-
includet("docs/plots/pedagogy_graph.jl")
1+
include(joinpath(@__DIR__, "pedagogy_graph.jl"))
2+
using Random
33

44
dims = [5, 5] # if > (14, 14) the display becomes all black, don't know why !
55
periodic = false
@@ -11,5 +11,5 @@ using Random
1111
rng = Random.MersenneTwister(123)
1212
@time sample = PRS.generate_sample_gibbs_perfect(rng, ising)
1313

14-
p = plot(ising, sample, dims, "docs/plots/output/ising/ising_grid_prs.pdf";
15-
nodelabel=nothing)
14+
path = joinpath(@__DIR__, "output", "ising", "ising_grid_prs.pdf")
15+
p = plot(ising, sample, dims, path; nodelabel=nothing)
Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
1+
using PartialRejectionSampling
2+
using Random
3+
14
n = 100
2-
alph = ["A", "C", "G", "T"]
5+
alphabet = ["A", "C", "G", "T"]
36
pattern = "ACAC"
4-
pfs = PRS.PatternFreeString(alph, pattern)
7+
pfs = PRS.PatternFreeString(pattern, alphabet)
58

6-
using Random
79
rng = Random.MersenneTwister(123)
810
@time PRS.generate_sample_prs(rng, pfs, n)

0 commit comments

Comments
 (0)