Skip to content

Commit 4200f00

Browse files
committed
First local build of the docs
1 parent b910d57 commit 4200f00

File tree

11 files changed

+682
-8
lines changed

11 files changed

+682
-8
lines changed

docs/Project.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
[deps]
2+
Documenter = "e30172f5-a6a5-5a46-863b-614d45cd2de4"
3+
DocumenterCitations = "daee34ce-89f3-4625-b898-19384cb65244"

docs/make.jl

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,21 @@
11
using Documenter, PartialRejectionSampling
2+
using DocumenterCitations
3+
4+
bib = CitationBibliography(joinpath(@__DIR__, "src", "prs.bib"))
25

36
# DocMeta.setdocmeta!(PartialRejectionSampling, :DocTestSetup, :(using PartialRejectionSampling); recursive=true)
47

58
makedocs(
6-
sitename="My Documentation",
9+
bib,
10+
sitename="PartialRejectionSampling.jl",
11+
modules = [PartialRejectionSampling],
12+
pages=[
13+
"Home" => "index.md",
14+
"Sampling methods" => "sampling.md",
15+
"Graph point processes" => "graph.md",
16+
"Spatial point processes" => "spatial.md",
17+
"Misc" => "pattern_free_string.md",
18+
"References" => "references.md"
19+
]
720
# doctest=:fix # = false to skip doctests
821
)

docs/pedagogy.jl

Lines changed: 298 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,298 @@
1+
using Plots
2+
using GraphPlot, Colors
3+
4+
using LazySets
5+
const LS = LazySets
6+
7+
# Pedagogy
8+
function pedagogy_generate_sample_prs(
9+
hc::HardCorePointProcess{T};
10+
win::Union{Nothing,AbstractWindow}=nothing,
11+
path="",
12+
rng=-1
13+
)::Vector{T} where {T}
14+
15+
rng = getRNG(rng)
16+
window_ = win === nothing ? window(hc) : win
17+
18+
n = rand(rng, Distributions.Poisson(hc.β * volume(window_)))
19+
points = Matrix{Float64}(undef, dimension(hc), n)
20+
for x in eachcol(points)
21+
x .= rand(window_; rng=rng)
22+
end
23+
24+
i = 0
25+
while true
26+
27+
p = pedagogy_plot(points, true, 0.0, "white", hc.window)
28+
Plots.savefig(p, "$(path)/hard_core_$(i)_0.pdf")
29+
30+
p = pedagogy_plot(points, true, hc.r/2, "white", hc.window)
31+
Plots.savefig(p, "$(path)/hard_core_$(i)_1.pdf")
32+
33+
bad = vec(any(pairwise_distances(points) .< hc.r, dims=2))
34+
!any(bad) && break
35+
36+
pedagogy_plot!(p, points[:, bad], false, hc.r/2, "red", hc.window)
37+
Plots.savefig(p, "$(path)/hard_core_$(i)_1bad_region.pdf")
38+
39+
pedagogy_plot!(p, points[:, bad], false, hc.r, "orange", hc.window)
40+
Plots.savefig(p, "$(path)/hard_core_$(i)_2resample_region.pdf")
41+
42+
p = pedagogy_plot(points[:, .!bad], true, 0.0, "white", hc.window)
43+
pedagogy_plot!(p, points[:, bad], false, hc.r, "orange", hc.window)
44+
Plots.savefig(p, "$(path)/hard_core_$(i)_3resample_region.pdf")
45+
46+
resampled = generate_sample_poisson_union_balls(hc.β, points[:, bad], hc.r; win=window_, rng=rng)
47+
pedagogy_plot!(p, resampled, true, 0, "blue", hc.window)
48+
Plots.savefig(p, "$(path)/hard_core_$(i)_4resampled_points.pdf")
49+
50+
points = hcat(points[:, .!bad], resampled)
51+
i += 1
52+
53+
end
54+
return [points[:, i] for i in 1:size(points, 2)]
55+
end
56+
57+
function pedagogy_plot!(
58+
p,
59+
points,
60+
show_center=true,
61+
radius=0.0,
62+
color="white",
63+
window=SquareWindow(zeros(2), 1.0)
64+
)
65+
for x in (points isa Matrix ? eachcol(points) : points)
66+
if show_center
67+
Plots.scatter!(p, [x[1]], [x[2]], markersize=2, color=color)
68+
end
69+
if radius > 0
70+
Plots.plot!(p, LS.Ball2(vec(x), radius), color=color)
71+
end
72+
end
73+
74+
Plots.xlims!(window.c[1], window.c[1] + window.w)
75+
Plots.ylims!(window.c[2], window.c[2] + window.w)
76+
77+
return p
78+
end
79+
80+
function pedagogy_plot(
81+
points,
82+
show_center=true,
83+
radius=0.0,
84+
color="white",
85+
window=SquareWindow(zeros(2), 1.0)
86+
)
87+
88+
p = Plots.plot([0], [0],
89+
label="", legend=false,
90+
color="white",
91+
linewidth=0.0,
92+
aspect_ratio=:equal,
93+
grid=:none,
94+
title="")
95+
96+
pedagogy_plot!(p, points, show_center, radius, color, window)
97+
98+
return p
99+
end
100+
101+
function plot(
102+
pp::AbstractSpatialPointProcess,
103+
points;
104+
title=""
105+
)
106+
p = Plots.plot([0], [0],
107+
label="", legend=false,
108+
color="white",
109+
linewidth=0.0,
110+
aspect_ratio=:equal,
111+
grid=:none,
112+
title=title)
113+
114+
θ = collect(range(0, 2π, length=15))
115+
rad = pp.r / 2 # radius = interaction range / 2
116+
circ_x, circ_y = rad .* cos.(θ), rad .* sin.(θ)
117+
118+
for x in points
119+
Plots.plot!(x[1] .+ circ_x,
120+
x[2] .+ circ_y,
121+
color="black",
122+
linewidth=0.5)
123+
end
124+
125+
win = pp.window
126+
Plots.xlims!(win.c[1], win.c[1] + win.w[1])
127+
Plots.ylims!(win.c[2], win.c[2] + (win.w isa Number ? win.w[1] : win.w[2]))
128+
129+
return p
130+
end
131+
132+
function plot(
133+
ising::Ising,
134+
state,
135+
width::Int=0,
136+
height::Int=0
137+
)
138+
if width == 0 || height == 0
139+
p = GraphPlot.gplot(ising.graph,
140+
nodelabel=LG.vertices(ising.graph),
141+
nodefillc=col_nodes
142+
)
143+
return p
144+
else
145+
pos = collect(Iterators.product(1:height, 1:width))[:]
146+
locs_x, locs_y = map(x->x[1], pos), map(x->x[2], pos)
147+
148+
col_nodes = ifelse.(
149+
state .== 1,
150+
Colors.colorant"gray",
151+
Colors.colorant"white")
152+
153+
p = GraphPlot.gplot(
154+
ising.graph,
155+
locs_x,
156+
reverse(locs_y),
157+
nodefillc=col_nodes)
158+
return p
159+
end
160+
end
161+
162+
function plot(
163+
hcg::HardCoreGraph,
164+
state,
165+
width::Int=0,
166+
height::Int=0
167+
)
168+
col_nodes = [Colors.colorant"turquoise" for _ in 1:LG.nv(hcg.graph)]
169+
col_nodes[state] .= Colors.colorant"red"
170+
171+
if width == 0 || height == 0
172+
p = GraphPlot.gplot(hcg.graph,
173+
nodelabel=LG.vertices(hcg.graph),
174+
nodefillc=col_nodes
175+
)
176+
return p
177+
else
178+
pos = collect(Iterators.product(1:height, 1:width))[:]
179+
locs_x, locs_y = map(x->x[1], pos), map(x->x[2], pos)
180+
181+
p = GraphPlot.gplot(hcg.graph,
182+
locs_x,
183+
reverse(locs_y),
184+
nodelabel=LG.vertices(hcg.graph),
185+
nodefillc=col_nodes
186+
)
187+
return p
188+
end
189+
end
190+
191+
function plot(
192+
rsf::RootedSpanningForest,
193+
sample,
194+
width::Int=0,
195+
height::Int=0
196+
)
197+
col_nodes, col_edges = color_cycles(sample)
198+
col_nodes[collect(rsf.roots)] .= Colors.colorant"orange"
199+
200+
if width == 0 || height == 0
201+
p = GraphPlot.gplot(sample,
202+
nodelabel=LG.vertices(sample),
203+
nodefillc=col_nodes,
204+
edgestrokec=col_edges,
205+
arrowlengthfrac=0.05,
206+
)
207+
return p
208+
else
209+
pos = collect(Iterators.product(1:height, 1:width))[:]
210+
locs_x, locs_y = map(x->x[1], pos), map(x->x[2], pos)
211+
212+
p = GraphPlot.gplot(sample,
213+
locs_x,
214+
reverse(locs_y),
215+
nodelabel=LG.vertices(sample),
216+
nodefillc=col_nodes,
217+
edgestrokec=col_edges,
218+
arrowlengthfrac=0.05,
219+
)
220+
return p
221+
end
222+
end
223+
224+
function color_cycles(
225+
graph::LG.SimpleDiGraph{T}
226+
) where {T}
227+
228+
edge_map = edgemap(graph)
229+
edge_idx = T[]
230+
nodes = Set{T}()
231+
for cycle in LG.simplecycles(graph)
232+
union!(nodes, cycle)
233+
for (x, y) in zip(cycle, circshift(cycle, -1))
234+
push!(edge_idx, edge_map[LG.Edge(x, y)])
235+
end
236+
end
237+
238+
col_nodes = [colorant"turquoise" for _ in 1:LG.nv(graph)]
239+
col_nodes[collect(nodes)] .= colorant"red"
240+
241+
col_edges = [colorant"lightgray" for _ in 1:LG.ne(graph)]
242+
col_edges[edge_idx] .= colorant"red"
243+
244+
return col_nodes, col_edges
245+
end
246+
247+
function plot(
248+
sfg::SinkFreeGraph,
249+
sample,
250+
width::Int=0,
251+
height::Int=0
252+
)
253+
col_nodes = [LG.outdegree(sample, v) == 0 ? colorant"red" : colorant"turquoise"
254+
for v in LG.vertices(sample)]
255+
if width == 0 || height == 0
256+
p = GraphPlot.gplot(sample,
257+
nodelabel=LG.vertices(sample),
258+
nodefillc=col_nodes,
259+
arrowlengthfrac=0.05,
260+
)
261+
return p
262+
else
263+
pos = collect(Iterators.product(1:height, 1:width))[:]
264+
locs_x, locs_y = map(x->x[1], pos), map(x->x[2], pos)
265+
266+
p = GraphPlot.gplot(sample,
267+
locs_x,
268+
reverse(locs_y),
269+
nodelabel=LG.vertices(sample),
270+
nodefillc=col_nodes,
271+
arrowlengthfrac=0.05,
272+
)
273+
return p
274+
end
275+
end
276+
277+
function color_sinks(
278+
graph::LG.SimpleDiGraph{T}
279+
) where {T}
280+
281+
nodes = T[]
282+
edge_idx = T[]
283+
edge_map = edgemap(graph)
284+
for v in sink_nodes(graph)
285+
push!(nodes, v)
286+
for w in LG.inneighbors(graph, v)
287+
push!(edge_idx, edge_map[LG.Edge(w, v)])
288+
end
289+
end
290+
291+
col_nodes = [Colors.colorant"turquoise" for _ in 1:LG.nv(graph)]
292+
col_nodes[nodes] .= Colors.colorant"red"
293+
294+
col_edges = [Colors.colorant"lightgray" for _ in 1:LG.ne(graph)]
295+
col_edges[edge_idx] .= Colors.colorant"red"
296+
297+
return col_nodes, col_edges
298+
end

docs/src/graph.md

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
# Graph point processes
2+
3+
```@docs
4+
PRS.AbstractGraphPointProcess
5+
PRS.GraphNode
6+
```
7+
8+
## Hard core graph
9+
10+
```@autodocs
11+
Modules = [PartialRejectionSampling]
12+
Pages = ["graph/hard_core.jl"]
13+
Private = true
14+
Order = [:module, :constant, :type, :function, :macro]
15+
```
16+
17+
## Rooted spanning forests
18+
19+
```@autodocs
20+
Modules = [PartialRejectionSampling]
21+
Pages = ["graph/rooted_spanning_forest.jl"]
22+
Private = true
23+
Order = [:module, :constant, :type, :function, :macro]
24+
```
25+
26+
## Sink free graph
27+
28+
```@autodocs
29+
Modules = [PartialRejectionSampling]
30+
Pages = ["graph/sink_free_graph.jl"]
31+
Private = true
32+
Order = [:module, :constant, :type, :function, :macro]
33+
```
34+
35+
## Ising model
36+
37+
```@autodocs
38+
Modules = [PartialRejectionSampling]
39+
Pages = ["graph/window.jl",
40+
"graph/ising.jl",
41+
"graph/ising_sampling_gibbs_perfect.jl",
42+
"graph/ising_sampling_grid_prs"]
43+
Private = true
44+
Order = [:module, :constant, :type, :function, :macro]
45+
```

docs/src/index.md

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,5 @@
11
# PartialRejectionSampling.jl Documentation
22

3-
```@contents
4-
```
5-
6-
## Functions
7-
83
## Index
94

105
```@index

docs/src/pattern_free_string.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
## Pattern Free String
2+
3+
```@autodocs
4+
Modules = [PartialRejectionSampling]
5+
Pages = ["misc/pattern_free_string.jl"]
6+
Private = true
7+
Order = [:module, :constant, :type, :function, :macro]
8+
```

0 commit comments

Comments
 (0)