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

Commit 947df5f

Browse files
authored
Refactoring and docstrings
1 parent 925425d commit 947df5f

File tree

2 files changed

+22
-20
lines changed

2 files changed

+22
-20
lines changed

src/processes.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ ishomogeneous(p::PointProcess) = false
2020
rand([rng], p, g, n=1; [algo])
2121
2222
Generate `n` realizations of spatial point process `p`
23-
inside geometry `g`. Optionally specify sampling
23+
inside geometry or domain `g`. Optionally specify sampling
2424
algorithm `algo` and random number generator `rng`.
2525
"""
2626
Base.rand(rng::Random.AbstractRNG, p::PointProcess, g, n::Int; algo=default_sampling_algorithm(p, g)) =
@@ -39,7 +39,7 @@ Base.rand(p::PointProcess, g; algo=default_sampling_algorithm(p, g)) =
3939
rand_single(rng, p, g, algo)
4040
4141
Generate a single realization of spatial point process
42-
`p` inside geometry `g` with sampling `algo`.
42+
`p` inside geometry or domain `g` with sampling `algo`.
4343
"""
4444
function rand_single end
4545

src/processes/poisson.jl

Lines changed: 20 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ define `λ` as a function or vector of values. If `λ` is a vector, it is
1111
assumed that the process is associated with a `Domain` with the same
1212
number of elements as `λ`.
1313
"""
14-
1514
struct PoissonProcess{L<:Union{Real,Function,AbstractVector}} <: PointProcess
1615
λ::L
1716
end
@@ -27,10 +26,13 @@ Base.union(p₁::PoissonProcess{<:Function}, p₂::PoissonProcess{<:Real}) = Poi
2726
Base.union(p₁::PoissonProcess{<:AbstractVector}, p₂::PoissonProcess{<:AbstractVector}) = PoissonProcess(x -> p₁.λ + p₂.λ)
2827

2928
ishomogeneous(p::PoissonProcess{<:Real}) = true
29+
3030
ishomogeneous(p::PoissonProcess{<:Function}) = false
31+
3132
ishomogeneous(p::PoissonProcess{<:AbstractVector}) = false
3233

3334
default_sampling_algorithm(::PoissonProcess, ::Any) = DiscretizedSampling()
35+
3436
default_sampling_algorithm(p::PoissonProcess{<:Function}, g) = ThinnedSampling(default_lambda_max(p, g))
3537

3638
function default_lambda_max(p::PoissonProcess{<:Function}, g)
@@ -65,6 +67,23 @@ end
6567
# INHOMOGENEOUS CASE
6668
#--------------------
6769

70+
function rand_single(rng::Random.AbstractRNG, p::PoissonProcess{<:Function}, g, algo::ThinnedSampling)
71+
# simulate a homogeneous process
72+
pp = rand_single(rng, PoissonProcess(algo.λmax), g, DiscretizedSampling())
73+
74+
# thin point pattern
75+
thin(pp, RandomThinning(x -> p.λ(x) / algo.λmax))
76+
end
77+
78+
function rand_single(rng::Random.AbstractRNG, p::PoissonProcess{<:Function}, d::Domain, algo::DiscretizedSampling)
79+
# compute intensity on centroids
80+
c = centroid.(d)
81+
λvec = p.λ.(c)
82+
83+
# simulate inhomogeneous process
84+
rand_single(rng, PoissonProcess(λvec), d, algo)
85+
end
86+
6887
function rand_single(rng::Random.AbstractRNG, p::PoissonProcess{<:AbstractVector}, d::Domain, algo::DiscretizedSampling)
6988
# simulate number of points
7089
λ = p.λ
@@ -86,20 +105,3 @@ function rand_single(rng::Random.AbstractRNG, p::PoissonProcess{<:AbstractVector
86105
PointSet(points)
87106
end
88107
end
89-
90-
function rand_single(rng::Random.AbstractRNG, p::PoissonProcess{<:Function}, g, algo::ThinnedSampling)
91-
# simulate a homogeneous process
92-
pp = rand_single(rng, PoissonProcess(algo.λmax), g, DiscretizedSampling())
93-
94-
# thin point pattern
95-
thin(pp, RandomThinning(x -> p.λ(x) / algo.λmax))
96-
end
97-
98-
function rand_single(rng::Random.AbstractRNG, p::PoissonProcess{<:Function}, d::Domain, algo::DiscretizedSampling)
99-
# compute intensity on centroids
100-
c = centroid.(d)
101-
λvec = p.λ.(c)
102-
103-
# simulate inhomogeneous process
104-
rand_single(rng, PoissonProcess(λvec), d, algo)
105-
end

0 commit comments

Comments
 (0)