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

Commit 2a2f4f2

Browse files
ErickChaconjuliohm
authored andcommitted
examples and tests
1 parent fb4c55f commit 2a2f4f2

File tree

2 files changed

+64
-2
lines changed

2 files changed

+64
-2
lines changed

src/processes/cluster.jl

Lines changed: 52 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,58 @@ parent point and returns a geometry or domain for the offspring process.
1818
## Examples
1919
2020
```julia
21-
# TODO
21+
import CairoMakie
22+
using Meshes, MeshViz
23+
using PointPatterns
24+
25+
# Matern cluster process
26+
d = Box((0,0), (5,5))
27+
p = ClusterProcess(
28+
PoissonProcess(1),
29+
PoissonProcess(1000),
30+
parent -> Ball(parent, 0.2)
31+
)
32+
ps = rand(p, d)
33+
34+
fig = viz(d, alpha = 0.5; axis = (;title = "Matern cluster process"))
35+
viz!(ps, color = :black, pointsize = 5)
36+
37+
# Inhomogenegeous parent process with fixed number of offsprings
38+
39+
d = Box((-2.5,-2.5), (2.5,2.5))
40+
p = ClusterProcess(
41+
PoissonProcess(s -> 1 * sum(coordinates(s) .^ 2)),
42+
BinomialProcess(100),
43+
parent -> Ball(parent, 0.2)
44+
)
45+
ps = rand(p, d)
46+
47+
fig = viz(d, alpha = 0.5; axis = (;title = "Inhomogeneneous with fixed number of offsprings"))
48+
viz!(ps, color = :black, pointsize = 5)
49+
50+
# Inhomogenegeous parent process and inhomogeneneous offspring process
51+
52+
d = Box((0,0), (5,5))
53+
p = ClusterProcess(
54+
PoissonProcess(s -> 0.1 * sum(coordinates(s) .^ 2)),
55+
parent -> rand(PoissonProcess(x -> 5000 * sum((x - parent).^2)), Ball(parent, 0.5))
56+
)
57+
ps = rand(p, d)
58+
59+
fig = viz(d, alpha = 0.5; axis = (;title = "Inhomogenegeous parent and inhomogeneneous offspring"))
60+
viz!(ps, color = :black, pointsize = 5)
61+
62+
# Inhomogenegeous parent process and regularsampling
63+
64+
d = Box((0,0), (5,5))
65+
p = ClusterProcess(
66+
PoissonProcess(s -> 0.2 * sum(coordinates(s) .^ 2)),
67+
parent -> PointSet(sample(Sphere(parent, 0.1), RegularSampling(10)))
68+
)
69+
ps = rand(p, d)
70+
71+
fig = viz(d, alpha = 0.5; axis = (;title = "Inhomogenegeous parent and regular sampling"))
72+
viz!(ps, color = :black, pointsize = 5)
2273
```
2374
"""
2475
struct ClusterProcess{P<:PointProcess,F<:Function} <: PointProcess

test/processes.jl

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,18 @@
5757

5858
@testset "Inhibition" begin end
5959

60-
@testset "Cluster" begin end
60+
@testset "Cluster" begin
61+
offspring1 = parent -> rand(BinomialProcess(10), Ball(parent, 0.2))
62+
offspring2 = parent -> rand(PoissonProcess(100), Ball(parent, 0.2))
63+
offspring3 = parent -> rand(PoissonProcess(x -> 100 * sum((x - parent).^2)), Ball(parent, 0.5))
64+
offspring4 = parent -> PointSet(sample(Sphere(parent, 0.1), RegularSampling(10)))
65+
offspringfuns = [offspring1, offspring2, offspring3, offspring4]
66+
for p in procs, ofun in offspringfuns, g in geoms
67+
cp = ClusterProcess(p, ofun)
68+
pp = rand(cp, g)
69+
@test all((g), pp)
70+
end
71+
end
6172

6273
@testset "Union" begin
6374
b = Box((0.0, 0.0), (100.0, 100.0))

0 commit comments

Comments
 (0)