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

Commit 0ac50f7

Browse files
ErickChaconjuliohm
andauthored
ClusterProcess (#36)
* start with PoissonClusterProcess * Update src/processes/clustered.jl Co-authored-by: Júlio Hoffimann <[email protected]> * Apply suggestions from code review Co-authored-by: Júlio Hoffimann <[email protected]> * Update src/processes/clustered.jl * Update src/processes/clustered.jl * Rename to ClusterProcess * Update src/processes/cluster.jl * more general cluster process * sampling algorithm * fix pointset * Apply suggestions from code review * Update src/processes/cluster.jl * Update src/processes/cluster.jl * Update src/processes/cluster.jl * Refactor cluster.jl --------- Co-authored-by: Júlio Hoffimann <[email protected]>
1 parent f7d1dac commit 0ac50f7

File tree

4 files changed

+56
-2
lines changed

4 files changed

+56
-2
lines changed

src/PointPatterns.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ export
1919
PointProcess,
2020
BinomialProcess,
2121
PoissonProcess,
22+
ClusterProcess,
2223
UnionProcess,
2324
ishomogeneous,
2425

src/processes.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ struct ConstantIntensity <: PointPatternAlgo end
8585

8686
include("processes/binomial.jl")
8787
include("processes/poisson.jl")
88+
include("processes/cluster.jl")
8889

8990
# ----------------
9091
# UNION PROCESSES

src/processes/cluster.jl

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
# ------------------------------------------------------------------
2+
# Licensed under the MIT License. See LICENSE in the project root.
3+
# ------------------------------------------------------------------
4+
5+
"""
6+
ClusterProcess(p, ofun)
7+
8+
A cluster process with parent process `p` and offsprings generated
9+
with `ofun`. It is a function that takes a parent point and returns
10+
a point pattern from another point process.
11+
12+
ClusterProcess(p, o, gfun)
13+
14+
Alternatively, specify the parent process `p`, the offspring process `o`
15+
and the geometry function `gfun`. It is a function that takes a parent
16+
point and returns a geometry or domain for the offspring process.
17+
18+
## Examples
19+
20+
```julia
21+
# TODO
22+
```
23+
"""
24+
struct ClusterProcess{P<:PointProcess,F<:Function} <: PointProcess
25+
p::P
26+
ofun::F
27+
end
28+
29+
ClusterProcess(p::PointProcess, o::PointProcess, gfun::Function) =
30+
ClusterProcess(p, parent -> rand(o, gfun(parent)))
31+
32+
default_sampling_algorithm(p::ClusterProcess, g) = nothing
33+
34+
function rand_single(rng::Random.AbstractRNG, p::ClusterProcess, g, ::Nothing)
35+
# retrieve parameters
36+
Dim = embeddim(g)
37+
T = coordtype(g)
38+
39+
# generate parents
40+
parents = rand_single(rng, p.p, g)
41+
42+
# generate offsprings
43+
offsprings = p.ofun.(parents)
44+
45+
# combine offsprings into single set
46+
points = mapreduce(vcat, offsprings) do pset
47+
isnothing(pset) ? Point{Dim,T}[] : collect(view(pset, g))
48+
end
49+
50+
# return point pattern
51+
PointSet(points)
52+
end
53+

src/processes/poisson.jl

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,7 @@ function rand_single(rng::Random.AbstractRNG, p::PoissonProcess{<:Function}, g,
6565
pp = rand_single(rng, PoissonProcess(algo.λmax), g, ConstantIntensity())
6666

6767
# thin point pattern
68-
points = thin(pp, RandomThinning(x -> p.λ(x) / algo.λmax))
69-
PointSet(collect(points))
68+
isnothing(pp) ? nothing : PointSet(collect(thin(pp, RandomThinning(x -> p.λ(x) / algo.λmax))))
7069
end
7170

7271
rand_single(rng::Random.AbstractRNG, p::PoissonProcess{<:Function}, d::Domain, algo::ConstantIntensity) =

0 commit comments

Comments
 (0)