Skip to content

Commit 9118f22

Browse files
committed
Continue working on docstrings
1 parent 45a9d43 commit 9118f22

14 files changed

+445
-100
lines changed

src/common.jl

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,48 @@
1+
"""
2+
AbstractPointProcess{T}
3+
4+
Abstract type encoding the notion of [point process](https://en.wikipedia.org/wiki/Point_process)
5+
The type `T` corresponds to the elements' type of the point process (vectors, graph edges, etc.)
6+
7+
**See also**
8+
- [`PRS.AbstractSpatialPointProcess`](@ref)
9+
- [`PRS.AbstractGraphPointProcess`](@ref)
10+
"""
111
abstract type AbstractPointProcess{T} end
212
Base.eltype(pp::AbstractPointProcess{T}) where {T} = T
313

14+
@doc raw"""
15+
AbstractSpatialPointProcess{T<:Vector{Float64}} <: AbstractPointProcess{T}
16+
17+
Abstract type encoding point processes defined on ``\mathbb{R}^d``.
18+
19+
Concrete instances must have a `window` field of type [`PRS.AbstractSpatialWindow`](@ref)
20+
"""
421
abstract type AbstractSpatialPointProcess{T<:Vector{Float64}} <: AbstractPointProcess{T} end
522

23+
"""
24+
window(pp::AbstractSpatialPointProcess) = pp.window
25+
"""
626
window(pp::AbstractSpatialPointProcess) = pp.window
27+
28+
"""
29+
dimension(pp::AbstractSpatialPointProcess) = dimension(window(pp))
30+
31+
**See also**
32+
- [`window`](@ref)
33+
"""
734
dimension(pp::AbstractSpatialPointProcess) = dimension(window(pp))
835

936
abstract type AbstractGraphPointProcess{T} <: AbstractPointProcess{T} end
1037

38+
# Default methods
39+
40+
"""
41+
Default exact sampling method
42+
"""
1143
function generate_sample end
44+
45+
"""
46+
Default exact sampling method using Partial Rejection Sampling (PRS, [GuJeLi19](@cite))
47+
"""
1248
function generate_sample_prs end

src/dominated_cftp.jl

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,18 @@ Compute an upper bound of [`papangelou_conditional_intensity`](@ref)
2828
"""
2929
function upper_bound_papangelou_conditional_intensity end
3030

31+
"""
32+
isrepulsive
33+
34+
Property of a [`PRS.AbstractSpatialPointProcess`](@ref) used in [`generate_sample_dcftp`](@ref).
35+
"""
3136
function isrepulsive end
37+
38+
"""
39+
isattractive
40+
41+
Property of a [`PRS.AbstractSpatialPointProcess`](@ref) used in [`generate_sample_dcftp`](@ref).
42+
"""
3243
function isattractive end
3344

3445
"""
@@ -47,8 +58,8 @@ Generate an exact sample from a spatial point process `pp` on window optional wi
4758
4859
**See also**
4960
50-
- [KeMo99](@cite), [KeMo00](@cite)
51-
- Section 11.2.6 [MoWa04](@cite)
61+
- [KeMo99](@cite), [KeMo00](@cite)
62+
- Section 11.2.6 [MoWa04](@cite)
5263
"""
5364
function generate_sample_dcftp(
5465
pp::AbstractSpatialPointProcess{T};

src/grid_prs.jl

Lines changed: 61 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,22 +2,57 @@
22
Implementation of Grid Partial Rejection Sampling of [MoKr20](@cite)
33
"""
44

5+
"""
6+
AbstractCellGridPRS
7+
8+
Abstract type describing a cell used Grid Partial Rejection Sampling of [MoKr20](@cite).
9+
"""
510
abstract type AbstractCellGridPRS end
11+
12+
"""
13+
GraphCellGridPRS{T} <: AbstractCellGridPRS
14+
15+
Mutable struct describing a graph node with fields
16+
- `window` of type [`PRS.GraphNode`](@ref)`{T}`
17+
- `value` of type `T`
18+
"""
619
mutable struct GraphCellGridPRS{T} <: AbstractCellGridPRS
720
window::GraphNode{T}
821
value::T
922
end
23+
24+
"""
25+
SpatialCellGridPRS{T<:Vector{Float64}} <: AbstractCellGridPRS
26+
27+
Mutable struct describing a spatial cell with fields
28+
- `window` of type `Union{`[`PRS.RectangleWindow`](@ref)`,`[`PRS.RectangleWindow`](@ref)`}``
29+
- `value` of type `Vector{T}`
30+
"""
1031
mutable struct SpatialCellGridPRS{T<:Vector{Float64}} <: AbstractCellGridPRS
1132
window::Union{RectangleWindow,SquareWindow}
1233
value::Vector{T}
1334
end
1435

36+
"""
37+
window(cell::AbstractCellGridPRS) = cell.window
38+
"""
1539
window(cell::AbstractCellGridPRS) = cell.window
40+
41+
"""
42+
dimension(cell::AbstractCellGridPRS) = dimension(window(cell))
43+
"""
1644
dimension(cell::AbstractCellGridPRS) = dimension(window(cell))
1745

18-
Base.isempty(cell::SpatialCellGridPRS) = isempty(cell.value)
46+
"""
47+
Base.iterate(cell::AbstractCellGridPRS, state=1) = iterate(cell.value, state)
48+
"""
1949
Base.iterate(cell::AbstractCellGridPRS, state=1) = iterate(cell.value, state)
2050

51+
"""
52+
Base.isempty(cell::SpatialCellGridPRS) = isempty(cell.value)
53+
"""
54+
Base.isempty(cell::SpatialCellGridPRS) = isempty(cell.value)
55+
2156
"""
2257
generate_sample!(
2358
cell::AbstractCellGridPRS,
@@ -36,6 +71,16 @@ function generate_sample!(
3671
cell.value = generate_sample(pp; win=cell.window, rng=rng)
3772
end
3873

74+
"""
75+
generate_sample!(
76+
cells::Vector{T},
77+
indices,
78+
pp::AbstractPointProcess;
79+
rng=-1
80+
) where {T<:AbstractCellGridPRS}
81+
82+
Apply [`generate_sample!`](@ref) to each cell of `cells` indexed by `indices`.
83+
"""
3984
function generate_sample!(
4085
cells::Vector{T},
4186
indices,
@@ -79,7 +124,7 @@ end
79124
rng=-1
80125
)::SWG.SimpleWeightedGraph
81126
82-
Construct the weighted interaction graph ([King graph](https://en.wikipedia.org/wiki/King%27s_graph)) used in [`generate_sample_grid_prs`](@ref), to generate exact samples from [`AbstractSpatialPointProcess`](@ref)
127+
Construct the weighted interaction graph ([King graph](https://en.wikipedia.org/wiki/King%27s_graph)) used in [`PRS.generate_sample_grid_prs`](@ref), to generate exact samples from [`PRS.AbstractSpatialPointProcess`](@ref)
83128
84129
The `pp.window` is divided into cells of length the interaction range `pp.r`.
85130
Each cell represents a vertex of the interaction (king) graph and each edge carries a uniform random varialble.
@@ -111,6 +156,13 @@ function weighted_interaction_graph(
111156
return g
112157
end
113158

159+
"""
160+
gibbs_interaction
161+
162+
Compute the pairwise Gibbs interaction for a [`PRS.AbstractPointProcess`](@ref) between two [`PRS.AbstractCellGridPRS`](@ref).
163+
164+
This is a subroutine of [`PRS.generate_sample_grid_prs`](@ref).
165+
"""
114166
function gibbs_interaction end
115167

116168
@doc raw"""
@@ -162,9 +214,10 @@ end
162214
Identify the set of events to be resampled as constructed by Algorithm 5 in [GuJeLi19](@cite) as part of the Partial Rejection Sampling (PRS) method.
163215
Return the indices of the variables (here cells) involved in the corresponding events.
164216
165-
This function is used as a subroutine of the grid PRS methodology of [MoKr20](@cite), see [`generate_sample_grid_prs`](@ref)
217+
This function is used as a subroutine of the grid PRS methodology of [MoKr20](@cite), see [`PRS.generate_sample_grid_prs`](@ref).
166218
167219
**Note**
220+
168221
If the event associated to the edge ``\{i,j\}`` of `g` is selected to be resampled, the uniform random variable encoded as the weight of the correspond edge is resampled (hence the "!")
169222
"""
170223
function find_cells_to_resample_indices!(
@@ -203,9 +256,9 @@ end
203256
spp::AbstractSpatialPointProcess{T},
204257
)::Vector{SpatialCellGridPRS{T}} where {T}
205258
206-
The `spp.window` ([`RectangleWindow`](@ref) or [`SquareWindow`](@ref)) is divided into [`SpatialCellGridPRS`](@ref) of length the interaction range `pp.r` following the construction of [MoKr20](@cite) in their grid Partial Rejection Sampling (grid PRS) methodology.
259+
The `spp.window` ([`PRS.RectangleWindow`](@ref) or [`PRS.SquareWindow`](@ref)) is divided into [`PRS.SpatialCellGridPRS`](@ref) of length the interaction range `pp.r` following the construction of [MoKr20](@cite) in their grid Partial Rejection Sampling (grid PRS) methodology.
207260
208-
This function is used as a subroutine of [`generate_sample_grid_prs`](@ref)
261+
This function is used as a subroutine of [`PRS.generate_sample_grid_prs`](@ref)
209262
"""
210263
function initialize_cells(
211264
spp::AbstractSpatialPointProcess{T},
@@ -236,10 +289,10 @@ end
236289
cell_j::SpatialCellGridPRS
237290
) = false
238291
239-
Assume `cell_i` and `cell_j` are neighboring cells in the weighted interaction graph constructed by [`weighted_interaction_graph`](@ref) from `spp` and already identified in the set of variables to be resampled in [`generate_sample_grid_prs`](@ref)
292+
Assume `cell_i` and `cell_j` are neighboring cells in the weighted interaction graph constructed by [`weighted_interaction_graph`](@ref) from `spp` and already identified in the set of variables to be resampled in [`PRS.generate_sample_grid_prs`](@ref)
240293
Since the configuration of points in the corresponding cells and the uniform random variable associated to the event `\{i,j\}` are considered fixed, there is no degree of freedom to make the interaction between `cell_i` and `cell_j` possible.
241294
242-
This function is used as a subroutine of [`generate_sample_grid_prs`](@ref)
295+
This function is used as a subroutine of [`PRS.generate_sample_grid_prs`](@ref)
243296
"""
244297
function is_inner_interaction_possible(
245298
spp::AbstractSpatialPointProcess,
@@ -259,7 +312,7 @@ end
259312
Assume `cell_i` and `cell_j` are neighboring cells in the weighted interaction graph constructed by [`weighted_interaction_graph`](@ref) from `spp`.
260313
Given the configuration of points in `cell_i`, check whether a realization of `spp` in `cell_j` can induce a bad event.
261314
262-
This function is used as a subroutine of [`generate_sample_grid_prs`](@ref)
315+
This function is used as a subroutine of [`PRS.generate_sample_grid_prs`](@ref)
263316
"""
264317
function is_outer_interaction_possible(
265318
spp::AbstractSpatialPointProcess,

src/hard_core_graph.jl

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ end
3232
β::Real
3333
) where {T<:Integer}
3434
35-
Construct a [`HardCoreGraph`](@ref) model on `graph` with parameter `β≥0`
35+
Construct a [`HardCoreGraph`](@ref)
3636
"""
3737
function HardCoreGraph(
3838
graph::LG.SimpleGraph{T},
@@ -48,9 +48,8 @@ end
4848

4949
"""
5050
generate_sample_prs(
51-
pp::HardCoreGraph{T};
52-
win::Union{Nothing,AbstractWindow}=nothing,
53-
rng=-1
51+
hcg::HardCoreGraph{T};
52+
rng=-1
5453
)::Vector{T} where {T}
5554
5655
Sample from [`PRS.HardCoreGraph`](@ref) using Partial Rejection Sampling (PRS), see Section 7.2 of [GuJeLi19](@cite)

src/hard_core_spatial.jl

Lines changed: 56 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,18 @@ Spatial point process with density (w.r.t. the homogenous Poisson point process
77
\prod_{x \in X}
88
\beta
99
\prod_{\{x, y\} \subseteq X}
10-
1_{ \left\| x - y \right\|_2 > r }
10+
1_{ \left\| x - y \right\|_2 > r },
1111
```
1212
1313
where ``\beta > 0`` is called the background intensity and ``r > 0`` the interaction range.
1414
15-
[`PRS.HardCorePointProcess`](@ref) can be viewed as a [`PRS.StraussPointProcess`](@ref) with interaction coefficient ``\gamma=0``.
15+
[`PRS.HardCorePointProcess`](@ref) can be viewed as
16+
- [`PRS.HomogeneousPoissonPointProcess`](@ref) conditioned to having no pair of points at distance less than ``r``,
17+
- [`PRS.StraussPointProcess`](@ref) with interaction coefficient ``\gamma=0``.
1618
1719
**See also**
1820
19-
- [`PRS.HardCoreGraph`](@ref)
21+
- [`PRS.HardCoreGraph`](@ref), the graph counterpart of [`PRS.HardCorePointProcess`](@ref)
2022
"""
2123
struct HardCorePointProcess{T<:Vector{Float64}} <: AbstractSpatialPointProcess{T}
2224
"Intensity"
@@ -29,53 +31,92 @@ end
2931
@doc raw"""
3032
HardCorePointProcess(β::Real, r::Real, window::AbstractSpatialWindow)
3133
32-
Construct a [`PRS.HardCorePointProcess`](@ref) with intensity ``\beta > 0`` and interaction range ``r > 0``, restricted to `window`.
34+
Construct a [`PRS.HardCorePointProcess`](@ref) with intensity `β` and interaction range `r`, restricted to `window`.
3335
"""
3436
function HardCorePointProcess::Real, r::Real, window::AbstractSpatialWindow)
3537
@assert β > 0
3638
@assert r > 0
3739
return HardCorePointProcess{Vector{Float64}}(β, r, window)
3840
end
3941

42+
"""
43+
intensity(pp::HardCorePointProcess) = pp.β
44+
"""
4045
intensity(pp::HardCorePointProcess) = pp.β
46+
47+
"""
48+
interaction_coefficient(pp::HardCorePointProcess) = 0.0
49+
"""
4150
interaction_coefficient(pp::HardCorePointProcess) = 0.0
51+
52+
"""
53+
interaction_range(pp::HardCorePointProcess) = pp.r
54+
"""
4255
interaction_range(pp::HardCorePointProcess) = pp.r
4356

4457
## Sampling
4558

4659
"""
4760
generate_sample(
48-
pp::HardCorePointProcess{T};
49-
win::Union{Nothing,AbstractWindow}=nothing,
50-
rng=-1
61+
pp::HardCorePointProcess{T};
62+
win::Union{Nothing,AbstractWindow}=nothing,
63+
rng=-1
5164
)::Vector{T} where {T}
5265
5366
Generate an exact sample from the [`PRS.HardCorePointProcess`](@ref).
54-
Default sampler is [`PRS.generate_sample_prs`](@ref), see also [`PRS.generate_sample_dcftp`](@ref) and [`PRS.generate_sample_grid_prs`](@ref).
67+
Default sampler is [`PRS.generate_sample_prs`](@ref).
68+
69+
**See also**
70+
- [`PRS.generate_sample_dcftp`](@ref)
71+
- [`PRS.generate_sample_grid_prs`](@ref).
5572
"""
5673
function generate_sample(
57-
pp::HardCorePointProcess{T};
58-
win::Union{Nothing,AbstractWindow}=nothing,
59-
rng=-1
74+
pp::HardCorePointProcess{T};
75+
win::Union{Nothing,AbstractWindow}=nothing,
76+
rng=-1
6077
)::Vector{T} where {T}
6178
return generate_sample_prs(pp; win=win, rng=rng)
6279
end
6380

6481
### dominated CFTP, see dominated_cftp.jl
6582

83+
"""
84+
isrepulsive(pp::HardCorePointProcess) = true
85+
"""
6686
isrepulsive(pp::HardCorePointProcess) = true
87+
88+
"""
89+
isattractive(pp::HardCorePointProcess) = false
90+
"""
6791
isattractive(pp::HardCorePointProcess) = false
6892

69-
function papangelou_conditional_intensity(
93+
@doc raw"""
94+
papangelou_conditional_intensity(
7095
pp::HardCorePointProcess{Vector{T}},
7196
x::AbstractVector{T},
7297
X::Union{AbstractVector{Vector{T}},AbstractSet{Vector{T}}}
98+
)::Real where {T}
99+
100+
Compute
101+
```math
102+
\beta
103+
\prod_{y\in X} 1_{\left\| x - y \right\|_2 > r\}},
104+
```
105+
where ``\beta=`` `pp.β`` and ``r=`` `pp.r`.
106+
"""
107+
function papangelou_conditional_intensity(
108+
pp::HardCorePointProcess{Vector{T}},
109+
x::AbstractVector{T},
110+
X::Union{AbstractVector{Vector{T}},AbstractSet{Vector{T}}}
73111
)::Real where {T}
74112
x in X && return 0.0
75113
β, r = intensity(pp), interaction_range(pp)
76114
return β * !any(Distances.euclidean(x, y) <= r for y in X)
77115
end
78116

117+
"""
118+
upper_bound_papangelou_conditional_intensity(pp::HardCorePointProcess) = intensity(pp)
119+
"""
79120
upper_bound_papangelou_conditional_intensity(pp::HardCorePointProcess) = intensity(pp)
80121

81122
### Partial Rejection Sampling
@@ -126,9 +167,9 @@ Compute the pairwise Gibbs interaction for a [`PRS.HardCorePointProcess`](@ref)
126167
```
127168
"""
128169
function gibbs_interaction(
129-
pp::HardCorePointProcess{T},
130-
cell1::SpatialCellGridPRS{T},
131-
cell2::SpatialCellGridPRS{T},
170+
pp::HardCorePointProcess{T},
171+
cell1::SpatialCellGridPRS{T},
172+
cell2::SpatialCellGridPRS{T},
132173
)::Real where {T}
133174
(isempty(cell1) || isempty(cell2)) && return 1.0
134175
r = interaction_range(pp)

0 commit comments

Comments
 (0)