Skip to content
This repository was archived by the owner on Nov 6, 2023. It is now read-only.

Commit 2c2244c

Browse files
committed
Implement random thinning
1 parent c801f96 commit 2c2244c

File tree

1 file changed

+14
-1
lines changed

1 file changed

+14
-1
lines changed

src/thinning/random.jl

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,5 +30,18 @@ thin(p::PoissonProcess{<:Function}, t::RandomThinning{<:Real}) =
3030
# thinning point pattern
3131
# -----------------------
3232
function thin(pp::PointPattern{T,N}, t::RandomThinning{<:Real}) where {N,T}
33-
# TODO
33+
draws = rand(Bernoulli(t.p), npoints(pp))
34+
inds = findall(isequal(1), draws)
35+
PointPattern(coordinates(pp, inds))
36+
end
37+
38+
function thin(pp::PointPattern{T,N}, t::RandomThinning{<:Function}) where {N,T}
39+
inds = Vector{Int}()
40+
for j in 1:npoints(pp)
41+
x = coordinates(pp, j)
42+
if rand(Bernoulli(t.p(x)))
43+
push!(inds, j)
44+
end
45+
end
46+
PointPattern(coordinates(pp, inds))
3447
end

0 commit comments

Comments
 (0)