Skip to content

Commit 238d8b9

Browse files
committed
Work on displays
1 parent f2f5cc0 commit 238d8b9

11 files changed

+115
-74
lines changed

src/display.jl

Lines changed: 89 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,9 +46,94 @@ function plot(
4646
locs_x,
4747
reverse(locs_y),
4848
nodefillc=col_nodes)
49-
# nodelabel=LG.vertices(g),
50-
# arrowlengthfrac=0.05
51-
# edgestrokec=col_edges
52-
5349
return p
5450
end
51+
52+
function plot(
53+
hcg::HardCoreGraph,
54+
state,
55+
width::Int=0,
56+
height::Int=0
57+
)
58+
col_nodes = [Colors.colorant"turquoise" for _ in 1:LG.nv(hcg.g)]
59+
col_nodes[state] .= Colors.colorant"red"
60+
61+
if width == 0 || height == 0
62+
p = GraphPlot.gplot(hcg.g,
63+
nodelabel=LG.vertices(hcg.g),
64+
nodefillc=col_nodes
65+
)
66+
return p
67+
else
68+
pos = collect(Iterators.product(1:height, 1:width))[:]
69+
locs_x, locs_y = map(x->x[1], pos), map(x->x[2], pos)
70+
71+
p = GraphPlot.gplot(hcg.g,
72+
locs_x, locs_y,
73+
nodelabel=LG.vertices(hcg.g),
74+
nodefillc=col_nodes
75+
)
76+
return p
77+
end
78+
end
79+
80+
function plot(
81+
rsf::RootedSpanningForest,
82+
sample,
83+
width::Int=0,
84+
height::Int=0
85+
)
86+
col_nodes, col_edges = color_cycles(sample)
87+
col_nodes[collect(rsf.roots)] .= Colors.colorant"orange"
88+
89+
if width == 0 || height == 0
90+
p = GraphPlot.gplot(sample,
91+
nodelabel=LG.vertices(sample),
92+
nodefillc=col_nodes,
93+
edgestrokec=col_edges,
94+
arrowlengthfrac=0.05,
95+
)
96+
return p
97+
else
98+
pos = collect(Iterators.product(1:height, 1:width))[:]
99+
locs_x, locs_y = map(x->x[1], pos), map(x->x[2], pos)
100+
101+
p = GraphPlot.gplot(sample,
102+
locs_x, locs_y,
103+
nodelabel=LG.vertices(sample),
104+
nodefillc=col_nodes,
105+
edgestrokec=col_edges,
106+
arrowlengthfrac=0.05,
107+
)
108+
return p
109+
end
110+
end
111+
112+
function plot(
113+
sfg::SinkFreeGraph,
114+
sample,
115+
width::Int=0,
116+
height::Int=0
117+
)
118+
col_nodes = [LG.outdegree(sample, v) == 0 ? colorant"red" : colorant"turquoise"
119+
for v in LG.vertices(sample)]
120+
if width == 0 || height == 0
121+
p = GraphPlot.gplot(sample,
122+
nodelabel=LG.vertices(sample),
123+
nodefillc=col_nodes,
124+
arrowlengthfrac=0.05,
125+
)
126+
return p
127+
else
128+
pos = collect(Iterators.product(1:height, 1:width))[:]
129+
locs_x, locs_y = map(x->x[1], pos), map(x->x[2], pos)
130+
131+
p = GraphPlot.gplot(sample,
132+
locs_x, locs_y,
133+
nodelabel=LG.vertices(sample),
134+
nodefillc=col_nodes,
135+
arrowlengthfrac=0.05,
136+
)
137+
return p
138+
end
139+
end

src/grid_prs.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ function initialize_cells(
151151
for i in eachindex(cells)
152152
c_y, c_x = divrem(i-1, k)
153153
c = spp.window.c + spp.r .* [c_x, c_y]
154-
win_i = spatial_window(c, @. min(spp.r, spp.window.w - c))
154+
win_i = rectangle_square_window(c, min.(spp.r, spp.window.w .- c))
155155
cells[i] = SpatialCellGridPRS(win_i, T[])
156156
end
157157
return cells

src/ising.jl

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,28 +4,30 @@ struct Ising{T<:Integer} <: AbstractGraphPointProcess{T}
44
"Grid graph"
55
g::LG.SimpleGraph{T}
66
"Magnetization"
7-
h::Union{Float64, Vector{Float64}}
7+
h::Union{Float64,Vector{Float64}}
88
"Interaction"
99
J::Float64
1010
end
1111

1212
function Ising(
1313
dims::Vector{T},
1414
periodic::Bool,
15-
h::Union{Real, Vector{Real}},
16-
J::Real
15+
J::Real,
16+
h::Real=0,
1717
) where {T<:Integer}
18-
h isa AbstractVector && @assert length(h) == prod(dims)
1918
g = LG.grid(dims; periodic=periodic)
20-
return Ising(dims, g, float.(h), float(J))
19+
return Ising{T}(dims, g, float(h), J)
2120
end
2221

2322
function Ising(
2423
dims::Vector{T},
2524
periodic::Bool,
26-
J::Real
25+
J::Real,
26+
h::Vector{Real},
2727
) where {T<:Integer}
28-
return Ising(dims, periodic, 0, J)
28+
@assert length(h) == prod(dims)
29+
g = LG.grid(dims; periodic=periodic)
30+
return Ising{T}(dims, g, float.(h), J)
2931
end
3032

3133
## Sampling

test/hard_core_graph.jl

Lines changed: 2 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -9,23 +9,8 @@ g = LG.grid([width, height])
99
β = 1.0
1010

1111
hcg = PRS.HardCoreGraph(g, β)
12+
1213
seed = -1
1314
@time sample = PRS.generate_sample_prs(hcg; rng=seed)
1415

15-
using GraphPlot
16-
using Colors
17-
18-
pos = collect(Iterators.product(1:height, 1:width))[:]
19-
locs_x, locs_y = map(x->x[1], pos), map(x->x[2], pos)
20-
21-
col_nodes = [Colors.colorant"turquoise" for _ in 1:LG.nv(g)]
22-
col_nodes[sample] .= Colors.colorant"red"
23-
24-
p = gplot(g,
25-
locs_x, locs_y,
26-
nodelabel=LG.vertices(g),
27-
nodefillc=col_nodes,
28-
# arrowlengthfrac=0.05
29-
# edgestrokec=col_edges
30-
)
31-
display(p)
16+
p = PRS.plot(hcg, sample, width, height)

test/hard_core_spatial.jl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@ win = PRS.SquareWindow(c, w)
1010

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

13-
@time sample = PRS.generate_sample_prs(hc; rng=-1)
13+
seed = -1
14+
@time sample = PRS.generate_sample_prs(hc; rng=seed)
1415
# @time sample = PRS.generate_sample_grid_prs(hc; rng=-1)
1516

1617
p = PRS.plot(hc, sample; title="")

test/ising_gibbs_perfect.jl

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,9 @@ 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

8-
seed = -1
9-
108
ising = PRS.Ising(dims, periodic, H, J)
119

10+
seed = -1
1211
@time sample = PRS.generate_sample_gibbs_perfect(ising; rng=seed)
1312

14-
PRS.plot(ising, sample)
13+
p = PRS.plot(ising, sample)

test/ising_grid_prs.jl

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,7 @@ H, J = 0.0, 0.01
77

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

10-
println("\nPartial Rejection Sampling\n")
11-
1210
seed = -1
1311
@time sample = PRS.generate_sample_grid_prs(ising; rng=seed)
1412

15-
PRS.plot(ising, sample)
13+
p = PRS.plot(ising, sample)

test/rooted_spanning_forest_prs.jl

Lines changed: 2 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -9,25 +9,8 @@ g = LG.grid([width, height])
99
roots = [1, 5]
1010

1111
rsf = PRS.RootedSpanningForest(g, roots)
12+
1213
seed = -1
1314
@time sample = PRS.generate_sample_prs(rsf; rng=seed)
1415

15-
# Display
16-
17-
using GraphPlot
18-
using Colors
19-
20-
pos = collect(Iterators.product(1:height, 1:width))[:]
21-
locs_x, locs_y = map(x->x[1], pos), map(x->x[2], pos)
22-
23-
col_nodes, col_edges = PRS.color_cycles(sample)
24-
col_nodes[roots] .= Colors.colorant"orange"
25-
26-
p = GraphPlot.gplot(sample,
27-
locs_x, locs_y,
28-
nodelabel=LG.vertices(sample),
29-
nodefillc=col_nodes,
30-
edgestrokec=col_edges,
31-
arrowlengthfrac=0.05,
32-
)
33-
display(p)
16+
p = PRS.plot(rsf, sample, width, height)

test/sink_free_graph.jl

Lines changed: 2 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -8,22 +8,8 @@ width, height = 5, 5
88
g = LG.grid([width, height])
99

1010
sfg = PRS.SinkFreeGraph(g)
11+
1112
seed = -1
1213
@time sample = PRS.generate_sample_prs(sfg; rng=seed)
1314

14-
using GraphPlot
15-
using Colors
16-
17-
pos = collect(Iterators.product(1:height, 1:width))[:]
18-
locs_x, locs_y = map(x->x[1], pos), map(x->x[2], pos)
19-
20-
sample = PRS.generate_sample_prs(sfg; rng=seed)
21-
cols = [LG.outdegree(sample, v) == 0 ? colorant"red" : colorant"turquoise"
22-
for v in LG.vertices(sample)]
23-
p = GraphPlot.gplot(sample,
24-
locs_x, locs_y,
25-
nodelabel=LG.vertices(sample),
26-
nodefillc=cols,
27-
arrowlengthfrac=0.05
28-
)
29-
display(p)
15+
p = PRS.plot(sfg, sample, width, height)

test/strauss_dcftp.jl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ win = PRS.SquareWindow(c, w)
99

1010
strauss = PRS.StraussPointProcess(β, γ, r, win)
1111

12-
@time sample = PRS.generate_sample_dcftp(strauss; rng=-1)
12+
seed = -1
13+
@time sample = PRS.generate_sample_dcftp(strauss; rng=seed)
1314

1415
p = PRS.plot(strauss, sample; title="")

0 commit comments

Comments
 (0)