Skip to content

Commit 7cbfd6f

Browse files
committed
Generate examples in test folder
1 parent 50d30c9 commit 7cbfd6f

10 files changed

+176
-31
lines changed

test/hard_core_graph.jl

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
using PartialRejectionSampling
2+
const PRS = PartialRejectionSampling
3+
4+
using LightGraphs
5+
const LG = LightGraphs
6+
7+
width, height = 5, 5
8+
g = LG.grid([width, height])
9+
β = 1.0
10+
11+
hcg = PRS.HardCoreGraph(g, β)
12+
seed = -1
13+
@time sample = PRS.generate_sample_prs(hcg; rng=seed)
14+
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)

test/hard_core_spatial.jl

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
using PartialRejectionSampling
2+
const PRS = PartialRejectionSampling
3+
4+
β₀ = 0.1
5+
r = 0.01 # interaction range = 2*radius
6+
b = β₀ /* (r/2)^2)
7+
8+
c, w = [0.0, 0.0], 1.0
9+
win = PRS.SquareWindow(c, w)
10+
11+
hc = PRS.HardCorePointProcess(b, r, win)
12+
13+
@time sample = PRS.generate_sample_prs(hc; rng=-1)
14+
# Todo @time sample = PRS.generate_sample_grid_prs(hc; rng=-1)
15+
16+
p = PRS.plot(hc, sample; title="")

test/ising.jl

Lines changed: 0 additions & 31 deletions
This file was deleted.

test/ising_gibbs_perfect.jl

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import PartialRejectionSampling
2+
const PRS = PartialRejectionSampling
3+
4+
dims = [15, 15] # if > (14, 14) the display becomes all black, don't know why !
5+
periodic = false
6+
H, J = 0.0, 0.01
7+
8+
seed = -1
9+
10+
ising = PRS.Ising(dims, periodic, H, J)
11+
12+
@time sample = PRS.generate_sample_gibbs_perfect(ising; rng=seed)
13+
14+
PRS.plot(ising, sample)

test/ising_grid_prs.jl

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
using PartialRejectionSampling
2+
const PRS = PartialRejectionSampling
3+
4+
dims = [15, 15] # if > (14, 14) the display becomes all black, don't know why !
5+
periodic = false
6+
H, J = 0.0, 0.01
7+
8+
ising = PRS.Ising(dims, periodic, H, J)
9+
10+
println("\nPartial Rejection Sampling\n")
11+
12+
seed = -1
13+
@time sample = PRS.generate_sample_grid_prs(ising; rng=seed)
14+
15+
PRS.plot(ising, sample)

test/pattern_free_string_prs.jl

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
using PartialRejectionSampling
2+
const PRS = PartialRejectionSampling
3+
4+
n = 1000
5+
alph = ["A", "C", "G", "T"]
6+
pattern = "ACAC"
7+
8+
seed = -1
9+
@time PRS.generate_pattern_free_string(n, alph, pattern; rng=seed)

test/rooted_spanning_forest_prs.jl

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
using PartialRejectionSampling
2+
const PRS = PartialRejectionSampling
3+
4+
using LightGraphs
5+
const LG = LightGraphs
6+
7+
width, height = 5, 5
8+
g = LG.grid([width, height])
9+
roots = [1, 5]
10+
11+
rsf = PRS.RootedSpanningForest(g, roots)
12+
seed = -1
13+
@time sample = PRS.generate_sample_prs(rsf; rng=seed)
14+
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)

test/sink_free_graph.jl

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
using PartialRejectionSampling
2+
const PRS = PartialRejectionSampling
3+
4+
using LightGraphs
5+
const LG = LightGraphs
6+
7+
width, height = 5, 5
8+
g = LG.grid([width, height])
9+
10+
sfg = PRS.SinkFreeGraph(g)
11+
seed = -1
12+
@time sample = PRS.generate_sample_prs(sfg; rng=seed)
13+
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)

test/strauss_dcftp.jl

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
using PartialRejectionSampling
2+
const PRS = PartialRejectionSampling
3+
4+
# Experimental setup refers to slide 9 of [E. Rubak](https://www-ljk.imag.fr/membres/Jean-Francois.Coeurjolly/documents/lecture4.pdf)
5+
β, γ, r = 2.0, 0.2, 0.7 # γ = 0 ≡ Hard core
6+
7+
c, w = [0.0, 0.0], 10.0
8+
win = PRS.SquareWindow(c, w)
9+
10+
strauss = PRS.StraussPointProcess(β, γ, r, win)
11+
12+
@time sample = PRS.generate_sample_dcftp(strauss; rng=-1)
13+
14+
p = PRS.plot(strauss, sample; title="")

test/strauss_grid_prs.jl

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
using PartialRejectionSampling
2+
const PRS = PartialRejectionSampling
3+
4+
β₀ = 0.1
5+
r = 0.01 # interaction range = 2*radius
6+
β, γ = β₀ /* (r/2)^2), 0.1 # γ = 0 ≡ Hard core
7+
8+
c, w = [0.0, 0.0], 1.0
9+
win = PRS.SquareWindow(c, w)
10+
11+
strauss = PRS.StraussPointProcess(β, γ, r, win)
12+
13+
@time sample = PRS.generate_sample_grid_prs(strauss; rng=-1)
14+
15+
p = PRS.plot(strauss, sample)

0 commit comments

Comments
 (0)