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

Commit 08921ac

Browse files
committed
Add UnionProcess
1 parent 14bb529 commit 08921ac

File tree

3 files changed

+41
-1
lines changed

3 files changed

+41
-1
lines changed

src/PointPatterns.jl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ export
2424
# point processes
2525
PointProcess,
2626
BinomialProcess,
27-
PoissonProcess
27+
PoissonProcess,
28+
UnionProcess
2829

2930
end # module

src/processes.jl

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,24 @@ Base.rand(p::PointProcess, r::AbstractRegion, n::Int) =
2020

2121
Base.rand(p::PointProcess, r::AbstractRegion) = rand_single(p, r)
2222

23+
"""
24+
rand_single(p, r)
25+
26+
Generate a single realization of spatial point process
27+
`p` inside spatial region `r`.
28+
"""
29+
rand_single(p::PointProcess, r::AbstractRegion) = @error "not implemented"
30+
31+
"""
32+
p₁ ∪ p₂
33+
34+
Union (or superposition) of spatial point processes `p₁` and `p₂`.
35+
"""
36+
Base.union(p₁::PointProcess, p₂::PointProcess) = UnionProcess(p₁, p₂)
37+
2338
#-----------------
2439
# IMPLEMENTATIONS
2540
#-----------------
2641
include("processes/binomial.jl")
2742
include("processes/poisson.jl")
43+
include("processes/union.jl")

src/processes/union.jl

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# ------------------------------------------------------------------
2+
# Licensed under the ISC License. See LICENSE in the project root.
3+
# ------------------------------------------------------------------
4+
5+
"""
6+
UnionProcess(p₁, p₂)
7+
8+
Union (or superposition) of spatial point processes `p₁` and `p₂`.
9+
"""
10+
struct UnionProcess{P₁<:PointProcess,P₂<:PointProcess} <: PointProcess
11+
p₁::P₁
12+
p₂::P₂
13+
end
14+
15+
function rand_single(p::UnionProcess, r::AbstractRegion)
16+
pp₁ = rand(p.p₁, r)
17+
pp₂ = rand(p.p₂, r)
18+
19+
X = coordinates(pp₁)
20+
Y = coordinates(pp₂)
21+
22+
PointPattern(hcat(X, Y))
23+
end

0 commit comments

Comments
 (0)