Skip to content

Commit e63ab8c

Browse files
committed
✨ Specify r intervals for reconstruction
1 parent 0e22da7 commit e63ab8c

10 files changed

+58
-14
lines changed

NEWS.md

+1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# shar 1.0
22
* Improvements
33
* Printing methods for most objects
4+
* Possibility to specify intervals of r for all reconstruction functions
45
* New functionality
56
* `plot_energy()` to plot energy over iterations for reconstructed patterns
67
* `reconstruct_pattern_hetero()` allows to reconstruct heterogeneous patterns

R/reconstruct_pattern_cluster.R

+6-1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
#' @param annealing Probability to keep relocated point even if energy did not decrease.
1111
#' @param comp_fast If pattern contains more points than threshold, summary functions are estimated in a computational fast way.
1212
#' @param weights Weights used to calculate energy. The first number refers to Gest(r), the second number to pcf(r).
13+
#' @param r_length Number of intervals from r = 0 to r = rmax the summary functions are evaluated.
1314
#' @param return_input The original input data is returned as last list entry
1415
#' @param simplify If n_random = 1 and return_input = FALSE only pattern will be returned.
1516
#' @param verbose Print progress report.
@@ -34,6 +35,9 @@
3435
#' The weights must be 0 < sum(weights) <= 1. To weight both summary functions identical,
3536
#' use \code{weights = c(0.5, 0.5)}.
3637
#'
38+
#' \code{spatstat} sets \code{r_length} to 513 by default. However, a lower value decreases
39+
#' the computational time while increasing the "bumpiness" of the summary function.
40+
#'
3741
#' @seealso
3842
#' \code{\link{calculate_energy}} \cr
3943
#' \code{\link{plot_randomized_pattern}}
@@ -67,6 +71,7 @@ reconstruct_pattern_cluster <- function(pattern,
6771
annealing = 0.01,
6872
comp_fast = 1000,
6973
weights = c(0.5, 0.5),
74+
r_length = 250,
7075
return_input = TRUE,
7176
simplify = FALSE,
7277
verbose = TRUE,
@@ -128,7 +133,7 @@ reconstruct_pattern_cluster <- function(pattern,
128133
r <- seq(from = 0,
129134
to = spatstat::rmax.rule(W = pattern$window,
130135
lambda = spatstat::intensity.ppp(pattern)),
131-
length.out = 250)
136+
length.out = r_length)
132137

133138
# start with fitted pattern
134139
# fit Thomas process

R/reconstruct_pattern_hetero.R

+6-1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
#' @param annealing Probability to keep relocated point even if energy did not decrease.
1111
#' @param comp_fast If pattern contains more points than threshold, summary functions are estimated in a computational fast way.
1212
#' @param weights Weights used to calculate energy. The first number refers to Gest(r), the second number to pcf(r).
13+
#' @param r_length Number of intervals from r = 0 to r = rmax the summary functions are evaluated.
1314
#' @param return_input The original input data is returned as last list entry
1415
#' @param simplify If n_random = 1 and return_input = FALSE only pattern will be returned.
1516
#' @param verbose Print progress report.
@@ -34,6 +35,9 @@
3435
#' The weights must be 0 < sum(weights) <= 1. To weight both summary functions identical,
3536
#' use \code{weights = c(0.5, 0.5)}.
3637
#'
38+
#' \code{spatstat} sets \code{r_length} to 513 by default. However, a lower value decreases
39+
#' the computational time while increasing the "bumpiness" of the summary function.
40+
#'
3741
#' @seealso
3842
#' \code{\link{calculate_energy}} \cr
3943
#' \code{\link{plot_randomized_pattern}}
@@ -69,6 +73,7 @@ reconstruct_pattern_hetero <- function(pattern,
6973
annealing = 0.01,
7074
comp_fast = 1000,
7175
weights = c(0.5, 0.5),
76+
r_length = 250,
7277
return_input = TRUE,
7378
simplify = FALSE,
7479
verbose = TRUE,
@@ -132,7 +137,7 @@ reconstruct_pattern_hetero <- function(pattern,
132137
r <- seq(from = 0,
133138
to = spatstat::rmax.rule(W = pattern$window,
134139
lambda = spatstat::intensity.ppp(pattern)),
135-
length.out = 250)
140+
length.out = r_length)
136141

137142
# estimate lambda(x,y)
138143
lambda <- spatstat::density.ppp(pattern)

R/reconstruct_pattern_homo.R

+7-2
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
#' @param annealing Probability to keep relocated point even if energy did not decrease.
1111
#' @param comp_fast If pattern contains more points than threshold, summary functions are estimated in a computational fast way.
1212
#' @param weights Weights used to calculate energy. The first number refers to Gest(r), the second number to pcf(r).
13+
#' @param r_length Number of intervals from r = 0 to r = rmax the summary functions are evaluated.
1314
#' @param return_input The original input data is returned as last list entry
1415
#' @param simplify If n_random = 1 and return_input = FALSE only pattern will be returned.
1516
#' @param verbose Print progress report.
@@ -34,6 +35,9 @@
3435
#' The weights must be 0 < sum(weights) <= 1. To weight both summary functions identical,
3536
#' use \code{weights = c(0.5, 0.5)}.
3637
#'
38+
#' \code{spatstat} sets \code{r_length} to 513 by default. However, a lower value decreases
39+
#' the computational time while increasing the "bumpiness" of the summary function.
40+
#'
3741
#' @seealso
3842
#' \code{\link{calculate_energy}} \cr
3943
#' \code{\link{plot_randomized_pattern}} \cr
@@ -45,7 +49,7 @@
4549
#'
4650
#' @examples
4751
#' \dontrun{
48-
#' pattern_recon <- reconstruct_pattern_homo(species_b, n_random = 19, max_runs = 1000)
52+
#' pattern_recon <- reconstruct_pattern_homo(species_a, n_random = 19, max_runs = 1000)
4953
#' }
5054
#'
5155
#' @aliases reconstruct_pattern_homo
@@ -67,6 +71,7 @@ reconstruct_pattern_homo <- function(pattern,
6771
annealing = 0.01,
6872
comp_fast = 1000,
6973
weights = c(0.5, 0.5),
74+
r_length = 250,
7075
return_input = TRUE,
7176
simplify = FALSE,
7277
verbose = TRUE,
@@ -128,7 +133,7 @@ reconstruct_pattern_homo <- function(pattern,
128133
r <- seq(from = 0,
129134
to = spatstat::rmax.rule(W = pattern$window,
130135
lambda = spatstat::intensity.ppp(pattern)),
131-
length.out = 250)
136+
length.out = r_length)
132137

133138
# create Poisson simulation data
134139
simulated <- spatstat::runifpoint(n = pattern$n,

R/reconstruct_pattern_marks.R

+6-1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
#' @param max_runs Maximum number of iterations of e_threshold is not reached.
1010
#' @param no_change Reconstrucction will stop if energy does not decrease for this number of iterations.
1111
#' @param annealing Probability to keep relocated point even if energy did not decrease.
12+
#' @param r_length Number of intervals from r = 0 to r = rmax the summary functions are evaluated.
1213
#' @param return_input The original input data is returned as last list entry
1314
#' @param simplify If n_random = 1 and return_input = FALSE only pattern will be returned.
1415
#' @param verbose Print progress report.
@@ -24,6 +25,9 @@
2425
#' randomly chosen marks are switch each iterations and changes only kept if the
2526
#' deviation between the observed and the reconstructed pattern decreases.
2627
#'
28+
#' \code{spatstat} sets \code{r_length} to 513 by default. However, a lower value decreases
29+
#' the computational time while increasing the "bumpiness" of the summary function.
30+
#'
2731
#' @seealso
2832
#' \code{\link{fit_point_process}} \cr
2933
#' \code{\link{reconstruct_pattern_homo}} \cr
@@ -58,6 +62,7 @@ reconstruct_pattern_marks <- function(pattern,
5862
max_runs = 10000,
5963
no_change = Inf,
6064
annealing = 0.01,
65+
r_length = 250,
6166
return_input = TRUE,
6267
simplify = FALSE,
6368
verbose = TRUE,
@@ -108,7 +113,7 @@ reconstruct_pattern_marks <- function(pattern,
108113
r <- seq(from = 0,
109114
to = spatstat::rmax.rule(W = pattern$window,
110115
lambda = spatstat::intensity.ppp(pattern)),
111-
length.out = 250)
116+
length.out = r_length)
112117

113118
# create random pattern
114119
simulated <- pattern

man/reconstruct_pattern_cluster.Rd

+8-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/reconstruct_pattern_hetero.Rd

+8-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/reconstruct_pattern_homo.Rd

+9-3
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/reconstruct_pattern_marks.Rd

+7-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tests/testthat/Rplots.pdf

1.3 KB
Binary file not shown.

0 commit comments

Comments
 (0)