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

Commit f126d98

Browse files
committed
Add BinomialProcess
1 parent 8de2986 commit f126d98

File tree

4 files changed

+59
-2
lines changed

4 files changed

+59
-2
lines changed

Project.toml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,12 @@ authors = ["Júlio Hoffimann"]
44
version = "0.1.0"
55

66
[deps]
7+
Distributions = "31c24e10-a181-5473-b8eb-7969acd0382f"
78
GeoStatsBase = "323cb8eb-fbf6-51c0-afd0-f8fba70507b2"
89

910
[compat]
10-
GeoStatsBase = "^0.7"
11+
Distributions = "0.21"
12+
GeoStatsBase = "0.7"
1113
julia = "1"
1214

1315
[extras]

src/PointPatterns.jl

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,15 @@
44

55
module PointPatterns
66

7-
greet() = print("Hello World!")
7+
using GeoStatsBase
8+
9+
using Distributions
10+
11+
# point processes
12+
include("processes.jl")
13+
14+
export
15+
PointProcess,
16+
BinomialProcess
817

918
end # module

src/processes.jl

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# ------------------------------------------------------------------
2+
# Licensed under the ISC License. See LICENSE in the project root.
3+
# ------------------------------------------------------------------
4+
5+
"""
6+
PointProcess
7+
8+
A spatial point process.
9+
"""
10+
abstract type PointProcess end
11+
12+
"""
13+
rand(p, r, n=1)
14+
15+
Generate `n` realizations of spatial point process `p`
16+
inside spatial region `r`.
17+
"""
18+
Base.rand(p::PointProcess, r::AbstractRegion, n::Int=1) =
19+
[rand_single(p, r) for i in 1:n]
20+
21+
#-----------------
22+
# IMPLEMENTATIONS
23+
#-----------------
24+
include("processes/binomial.jl")

src/processes/binomial.jl

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# ------------------------------------------------------------------
2+
# Licensed under the ISC License. See LICENSE in the project root.
3+
# ------------------------------------------------------------------
4+
5+
struct BinomialProcess <: PointProcess
6+
npoints::Int
7+
end
8+
9+
function rand_single(p::BinomialProcess, r::RectangleRegion{T,N}) where {N,T}
10+
# region configuration
11+
lo = lowerleft(r)
12+
up = upperright(r)
13+
14+
# number of points
15+
n = p.npoints
16+
17+
# product of uniform distributions
18+
U = product_distribution([Uniform(lo[i], up[i]) for i in 1:N])
19+
20+
# return point pattern
21+
PointSet(rand(U, n))
22+
end

0 commit comments

Comments
 (0)