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

Commit 95cc99a

Browse files
ErickChaconjuliohm
andauthored
Fix random thinning PointSets (#30)
* Fix thinning a poinset * remove inds * test for thinning * Update src/thinning/random.jl --------- Co-authored-by: Júlio Hoffimann <[email protected]>
1 parent ec0b058 commit 95cc99a

File tree

3 files changed

+26
-4
lines changed

3 files changed

+26
-4
lines changed

src/thinning/random.jl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,16 +30,16 @@ thin(p::PoissonProcess{<:Function}, t::RandomThinning{<:Real}) = PoissonProcess(
3030
function thin(pp::PointSet, t::RandomThinning{<:Real})
3131
draws = rand(Bernoulli(t.p), nelements(pp))
3232
inds = findall(isequal(1), draws)
33-
PointSet(coordinates(pp, inds))
33+
view(pp, inds)
3434
end
3535

3636
function thin(pp::PointSet, t::RandomThinning{<:Function})
3737
inds = Vector{Int}()
3838
for j in 1:nelements(pp)
39-
x = coordinates(pp, j)
39+
x = element(pp, j)
4040
if rand(Bernoulli(t.p(x)))
4141
push!(inds, j)
4242
end
4343
end
44-
PointSet(coordinates(pp, inds))
44+
PointSet(pp.items[inds])
4545
end

test/runtests.jl

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,10 @@ using GeoStatsBase
44
using Test, Random
55

66
# list of tests
7-
testfiles = ["processes.jl"]
7+
testfiles = [
8+
"processes.jl",
9+
"thinning.jl"
10+
]
811

912
@testset "PointPatterns.jl" begin
1013
for testfile in testfiles

test/thinning.jl

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
@testset "Thinning" begin
2+
@testset "PointSet" begin
3+
p = PoissonProcess(10)
4+
q = Quadrangle((0.0, 0.0), (4.0, 0.0), (4.0, 4.0), (0.0, 4.0))
5+
pp = rand(p, q)
6+
tp = thin(pp, RandomThinning(0.3))
7+
@test length(tp) length(pp)
8+
xs = coordinates.(tp)
9+
@test all(0 .≤ first.(xs) .≤ 4.0)
10+
@test all(0 .≤ last.(xs) .≤ 4.0)
11+
12+
λ(s::Point2) = sum(coordinates(s) .^ 2)
13+
tp = thin(pp, RandomThinning(s -> λ(s) / λ(Point(4.0,4.0))))
14+
@test length(tp) length(pp)
15+
xs = coordinates.(tp)
16+
@test all(0 .≤ first.(xs) .≤ 4.0)
17+
@test all(0 .≤ last.(xs) .≤ 4.0)
18+
end
19+
end

0 commit comments

Comments
 (0)