Skip to content

Commit

Permalink
🐛 Bug-fix in reconstruction
Browse files Browse the repository at this point in the history
  • Loading branch information
mhesselbarth committed Nov 24, 2023
1 parent 811d032 commit a9f1b85
Showing 1 changed file with 11 additions and 6 deletions.
17 changes: 11 additions & 6 deletions R/reconstruct_algorithm.R
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,7 @@ reconstruct_algorithm <- function(pattern,
window <- pattern$window

# check if pattern is emtpy
if (n_points == 0){
stop("The observed pattern contains no points.", call. = FALSE)
}
if (n_points == 0) stop("The observed pattern contains no points.", call. = FALSE)

# calculate intensity
lambda <- n_points / spatstat.geom::area(window)
Expand Down Expand Up @@ -145,23 +143,27 @@ reconstruct_algorithm <- function(pattern,
window = window, verbose = FALSE)

# remove points because more points in simulated
if (n_points <= simulated$n) {
if (n_points < simulated$n) {

# difference between patterns
difference <- simulated$n - n_points

# id of points to remove
remove_points <- sample(x = seq_len(simulated$n), size = difference)

# remove points
simulated <- simulated[-remove_points]

# add points because less points in simulated
} else {
# add points because less points in simulated
} else if (n_points > simulated$n) {

# difference between patterns
difference <- n_points - simulated$n

# create missing points
missing_points <- spatstat.random::runifpoint(n = difference, nsim = 1, drop = TRUE,
win = pattern$window, warn = FALSE)

# add missing points to simulated
simulated <- spatstat.geom::superimpose.ppp(simulated, missing_points,
W = pattern$window, check = FALSE)
Expand All @@ -172,6 +174,9 @@ reconstruct_algorithm <- function(pattern,
# check if simulated is empty
if (simulated$n == 0) stop("The simulated pattern contains no points.", call. = FALSE)

# check if simulated has same points as observed
if (n_points != simulated$n) stop("The simulated pattern contains the same amount as observed pattern.", call. = FALSE)

# energy before reconstruction
energy <- Inf

Expand Down

0 comments on commit a9f1b85

Please sign in to comment.