Skip to content

Commit 45a9d43

Browse files
committed
Global pass on docstrings
1 parent b9256a4 commit 45a9d43

18 files changed

+981
-431
lines changed

Project.toml

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,10 @@ authors = ["Guillaume Gautier <[email protected]> and contributors"]
44
version = "0.1.0"
55

66
[deps]
7-
Colors = "5ae59095-9a9b-59fe-a467-6f913c188581"
87
Distances = "b4f34e82-e78d-54a5-968a-f98e89d6e8f7"
98
Distributions = "31c24e10-a181-5473-b8eb-7969acd0382f"
10-
GraphPlot = "a2cc645c-3eea-5389-862e-a155d0052231"
11-
LazySets = "b4f0291d-fe17-52bc-9479-3d1a343d9043"
129
LightGraphs = "093fc24a-ae57-5d10-9952-331d41423f4d"
1310
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
14-
Plots = "91a5bcdd-55d7-5caf-9e0b-520d859cae80"
15-
RCall = "6f49c342-dc21-5d91-9882-a32aef131414"
1611
Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c"
1712
SimpleWeightedGraphs = "47aef6b3-ad0c-573a-a1e2-d07658019622"
1813
SpecialFunctions = "276daf66-3868-5448-9aa4-cd146d93841b"

src/PartialRejectionSampling.jl

Lines changed: 37 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
module PartialRejectionSampling
22

3+
# Imports
4+
35
using LinearAlgebra
46
const LA = LinearAlgebra
57

@@ -11,16 +13,44 @@ const LG = LightGraphs
1113
using SimpleWeightedGraphs
1214
const SWG = SimpleWeightedGraphs
1315

14-
using Plots, GraphPlot, Colors
15-
1616
using Distances
1717

18-
using LazySets
19-
const LS = LazySets
20-
2118
using SpecialFunctions
2219
const SF = SpecialFunctions
2320

21+
# Exports
22+
23+
const PRS = PartialRejectionSampling
24+
export PRS
25+
26+
export AbstractWindow
27+
export AbstractSpatialWindow,
28+
RectangleWindow,
29+
SquareWindow,
30+
BallWindow
31+
export AbstractDiscreteWindow,
32+
GraphNode
33+
34+
export AbstractPointProcess
35+
export AbstractSpatialPointProcess,
36+
HomogeneousPoissonPointProcess,
37+
HardCorePointProcess,
38+
StraussPointProcess
39+
export AbstractGraphPointProcess,
40+
Ising,
41+
HardCoreGraph,
42+
RootedSpanningForest,
43+
SinkFreeGraph
44+
export PatternFreeString
45+
46+
export generate_sample,
47+
generate_sample_prs,
48+
generate_sample_grid_prs,
49+
generate_sample_dcftp, # For Spatial point processes
50+
generate_sample_gibbs_perfect # For the Ising model
51+
52+
# Code inclusions
53+
2454
include("common.jl")
2555

2656
include("utils.jl")
@@ -35,17 +65,13 @@ include("poisson.jl")
3565
include("strauss.jl")
3666
include("hard_core_spatial.jl")
3767

38-
include("hard_core_graph.jl")
39-
include("ising.jl")
40-
4168
# Graph point processes
69+
include("ising.jl")
70+
include("hard_core_graph.jl")
4271
include("rooted_spanning_forest.jl")
4372
include("sink_free_graph.jl")
4473

4574
# Misc
4675
include("pattern_free_string.jl")
4776

48-
# Display
49-
include("display.jl")
50-
5177
end

src/common.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,4 @@ dimension(pp::AbstractSpatialPointProcess) = dimension(window(pp))
99
abstract type AbstractGraphPointProcess{T} <: AbstractPointProcess{T} end
1010

1111
function generate_sample end
12+
function generate_sample_prs end

src/display.jl

Lines changed: 0 additions & 142 deletions
This file was deleted.

src/dominated_cftp.jl

Lines changed: 91 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,60 @@
1-
## Dominated Coupling From The Past (dCFTP)
2-
# - [Kendall \& Moller's orginal formulation of dCFTP](https://www.researchgate.net/publication/ 2821877_Perfect_Metropolis-Hastings_simulation_of_locally_stable_point_processes)
3-
# - Huber, Perfect Simulation
4-
# - [Kendall's notes on perfect simulation](https://warwick.ac.uk/fac/sci/statistics/staff/ academic-research/kendall/personal/ppt/428.pdf)
5-
#
6-
# Requirement: the target spatial point process must have the following methods
7-
# - function papangelou_conditional_intensity end
8-
# - function upper_bound_papangelou_conditional_intensity end
9-
# - function window end
1+
"""
2+
Implementation of dominated Coupling From The Past (dCFTP)
3+
- [KeMo99](@cite) and [KeMo00](@cite) orginal formulation of dCFTP
4+
- [Hub16](@cite)
5+
- [Kendall's notes on perfect simulation](https://warwick.ac.uk/fac/sci/statistics/staff/ academic-research/kendall/personal/ppt/428.pdf)
6+
"""
107

11-
function generate_sample_dcftp(
8+
@doc raw"""
9+
papangelou_conditional_intensity(pp, x, X)
10+
11+
Compute the [Papangelou conditional intensity](https://en.wikipedia.org/wiki/Point_process#Papangelou_intensity_function) of the point process `pp`, as the ratio of densities ``\frac{f(X \cup x)}{f(X)}``.
12+
13+
**See also**
14+
15+
- Section 6.1.1 [MoWa04](@cite)
16+
- [wiki](https://en.wikipedia.org/wiki/Point_process#Papangelou_intensity_function)
17+
"""
18+
function papangelou_conditional_intensity end
19+
20+
"""
21+
upper_bound_papangelou_conditional_intensity
22+
23+
Compute an upper bound of [`papangelou_conditional_intensity`](@ref)
24+
25+
**See also**
26+
27+
- Equation 2.1 [KeMo99](@cite)
28+
"""
29+
function upper_bound_papangelou_conditional_intensity end
30+
31+
function isrepulsive end
32+
function isattractive end
33+
34+
"""
35+
generate_sample_dcftp(
1236
pp::AbstractSpatialPointProcess{T};
13-
n₀::Int=1,
1437
win::Union{Nothing,AbstractWindow}=nothing,
38+
n₀::Int=1,
1539
rng=-1
40+
)::Vector{T} where {T}
41+
42+
Generate an exact sample from a spatial point process `pp` on window optional window `win` using dominated coupling from the past.
43+
44+
- Default window is `window(pp)=pp.window`
45+
- Initial coalescence check performed after `n₀` steps.
46+
- Seed or random number generator is passed via `rng`.
47+
48+
**See also**
49+
50+
- [KeMo99](@cite), [KeMo00](@cite)
51+
- Section 11.2.6 [MoWa04](@cite)
52+
"""
53+
function generate_sample_dcftp(
54+
pp::AbstractSpatialPointProcess{T};
55+
win::Union{Nothing,AbstractWindow}=nothing,
56+
n₀::Int=1,
57+
rng=-1
1658
)::Vector{T} where {T}
1759

1860
@assert n₀ >= 1
@@ -23,29 +65,48 @@ function generate_sample_dcftp(
2365
birth_rate = β * volume(window_)
2466

2567
# Dominating process
26-
hp = HomogeneousPoissonPointProcess(β, window_)
27-
D = Set{T}(eachcol(generate_sample(hp; rng=rng)))
68+
hppp = HomogeneousPoissonPointProcess(β, window_)
69+
D = Set{T}(eachcol(generate_sample(hppp; rng=rng)))
2870

2971
M = Float64[] # Marking process
3072
R = T[] # Recording process
3173

3274
steps = -1:-1:-n₀
3375
while true
34-
backward_update!(D, M, R, steps, birth_rate, window_; rng=rng)
76+
backward_extend!(D, M, R, steps, birth_rate, window_; rng=rng)
3577
coupling, L = forward_coupling(D, M, R, pp, β)
3678
coupling && return collect(L)
3779
steps = (steps.stop-1):-1:(2*steps.stop)
3880
end
3981
end
4082

41-
function backward_update!(
83+
"""
84+
backward_extend!(
4285
D::Set{T}, # Dominating process
4386
M::Vector{Float64}, # Marking process
4487
R::Vector{T}, # Recording process
4588
steps::StepRange, # Number of backward steps
4689
birth_rate::Real,
4790
win::AbstractWindow;
4891
rng=-1
92+
) where {T}
93+
94+
Sample from the dominating birth-death process backwards in time according to `steps`.
95+
The marks `M` and the points `R` which were added (uniform mark) / deleted (mark=0) along the run are recorded (`pushfirst!`).
96+
The final state of the dominating process is updated to `D`.
97+
98+
**See also**
99+
100+
- SBDevolve() [KeMo99](@cite)
101+
"""
102+
function backward_extend!(
103+
D::Set{T}, # Dominating process
104+
M::Vector{Float64}, # Marking process
105+
R::Vector{T}, # Recording process
106+
steps::StepRange, # Number of backward steps
107+
birth_rate::Real,
108+
win::AbstractWindow;
109+
rng=-1
49110
) where {T}
50111
rng = getRNG(rng)
51112
for _ in steps
@@ -66,6 +127,21 @@ function backward_update!(
66127
end
67128
end
68129

130+
"""
131+
forward_coupling(
132+
D::Set{T}, # Dominating process
133+
M::Vector{Float64}, # Marking process
134+
R::Vector{T}, # Recording process
135+
pp::AbstractSpatialPointProcess{T},
136+
β::Real # Upper bound on papangelou conditional intensity
137+
) where {T}
138+
139+
Check if coalescence occured between the lower and upper bounding processes and return the state of the lower bounding process at time 0.
140+
141+
**See also**
142+
143+
- SBDadd() [KeMo99](@cite)
144+
"""
69145
function forward_coupling(
70146
D::Set{T}, # Dominating process
71147
M::Vector{Float64}, # Marking process

0 commit comments

Comments
 (0)