Skip to content

Commit 7e6df24

Browse files
committed
Set warnings when using prs with non provable guaranty for hard core graph and spatial
1 parent 3e9ba97 commit 7e6df24

File tree

3 files changed

+19
-6
lines changed

3 files changed

+19
-6
lines changed

src/graph/hard_core.jl

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ function HardCoreGraph(
6262
β::Real
6363
) where {T<:Integer}
6464
@assert β >= 0
65-
return HardCoreGraph{T}(graph, float(β))
65+
return HardCoreGraph{T}(graph, β)
6666
end
6767

6868
# Sampling
@@ -114,6 +114,12 @@ function generate_sample_prs(
114114
pp::HardCoreGraph{T}
115115
)::Vector{T} where {T}
116116

117+
β_max = 1 / (2 * sqrt(exp(1)) * LG.Δ(pp.graph) - 1)
118+
if pp.β > β_max
119+
@warn "The arguments do not satisfy Theorem 35 of Guo, Jerrum and Liu (2019): partial rejection sampling may not be efficient.
120+
Given `graph`, consider choosing β ≤ $(β_max)"
121+
end
122+
117123
proba = pp.β / (one(pp.β) + pp.β)
118124

119125
adj = LG.adjacency_matrix(pp.graph)

src/grid_prs.jl

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -240,10 +240,10 @@ function weighted_interaction_graph(
240240
)::SWG.SimpleWeightedGraph
241241
window_ = window(spp)
242242
if allequal(window_.w)
243-
nb_cells_x = ceil(Int, window_.w[1] / spp.r)
243+
nb_cells_x = cld(window_.w[1], spp.r)
244244
return uniform_weighted_graph(rng, king_graph(nb_cells_x))
245245
else
246-
nb_cells_x, nb_cells_y = ceil.(Int, window_.w ./ spp.r)
246+
nb_cells_x, nb_cells_y = cld.(Int, window_.w, spp.r)
247247
return uniform_weighted_graph(rng, king_graph(nb_cells_x, nb_cells_y))
248248
end
249249
end
@@ -264,9 +264,9 @@ function initialize_cells(
264264
window_ = window(spp)
265265
nb_cells_x = nb_cells_y = 1
266266
if allequal(window_.w) # SquareWindow
267-
nb_cells_x = nb_cells_y = ceil(Int, window_.w[1] / spp.r)
267+
nb_cells_x = nb_cells_y = cld(window_.w[1], spp.r)
268268
else
269-
nb_cells_x, nb_cells_y = ceil.(Int, window_.w ./ spp.r)
269+
nb_cells_x, nb_cells_y = cld.(Int, window_.w, spp.r)
270270
end
271271

272272
cells = Vector{SpatialCellGridPRS{T}}(undef, nb_cells_x * nb_cells_y)

src/spatial/hard_core.jl

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -197,9 +197,16 @@ function generate_sample_prs(
197197
pp::HardCorePointProcess{T},
198198
win::Union{Nothing,AbstractWindow}=nothing
199199
)::Vector{T} where {T}
200-
win_ = win === nothing ? window(pp) : win
201200

202201
β, r = intensity(pp), interaction_range(pp)
202+
win_ = win === nothing ? window(pp) : win
203+
204+
β_max = 0.21027 / volume(BallWindow(zeros(dimension(win_)), r/2))
205+
if β > β_max
206+
@warn "The arguments do not satisfy Lemma 6 of Guo and Jerrum (2018): partial rejection sampling may not be efficient.
207+
Given the interaction range `pp.r`, consider choosing β ≤ $(β_max)"
208+
end
209+
203210
points = generate_sample(rng, HomogeneousPoissonPointProcess(β, win_))
204211
while true
205212
bad = vec(any(pairwise_distances(points) .<= r, dims=2))

0 commit comments

Comments
 (0)