Commit e1d9e630 authored by Romulo Pereira Goncalves's avatar Romulo Pereira Goncalves
Browse files

When the user does not need to save the runs, then we should not build a...

When the user does not need to save the runs, then we should not build a complete Habitat Class object which takes a lot of space in memory.
parent b653d269
......@@ -15,6 +15,7 @@
#' @param last only true for one class classifier c("FALSE", TRUE")
#' @param seed set seed for reproducable results
#' @param init.seed "sample" for new or use run1@seeds to reproduce previous steps
#' @param save_runs if the user wants to save the runs, if TRUE the complete Habitat Class object is returned
#' @param parallel_mode run loops in parallel
#' @param max_num_cores maximum number of cores for parallelism
#'
......@@ -22,13 +23,13 @@
#' 1) An index
#' 2) Accuracy vector
#' 3) A vector with a Habitat objects, each consisting of 7 slots: \cr
#' run1@models - list of selected classifiers \cr
#' run1@ref_samples - list of SpatialPointsDataFrames with same length as run1@models holding reference labels [1,2] for each selected model \cr
#' run1@switch - vector of length run1@models indicating if target class equals 2, if not NA the labels need to be switched \cr
#' run1@models - list of selected classifiers (only if save_runs is TRUE) \cr
#' run1@ref_samples - list of SpatialPointsDataFrames with same length as run1@models holding reference labels [1,2] for each selected model (only if save_runs is TRUE) \cr
#' run1@switch - vector of length run1@models indicating if target class equals 2, if not NA the labels need to be switched (only if save_runs is TRUE) \cr
#' run1@layer - raster map of habitat type probability \cr
#' run1@mod_all - list of all classifiers (equals nb_models) \cr
#' run1@class_ind - vector of predictive distance measure for all habitats \cr
#' run1@seeds - vector of seeds for random sampling \cr
#' run1@mod_all - list of all classifiers (equals nb_models) (only if save_runs is TRUE) \cr
#' run1@class_ind - vector of predictive distance measure for all habitats (only if save_runs is TRUE) \cr
#' run1@seeds - vector of seeds for random sampling (only if save_runs is TRUE) \cr
#' all files are saved with step number, the *.tif file is additionally saved with class names
#' @keywords internal
......@@ -47,6 +48,7 @@ sample_nb <- function(raster,
last,
seed,
init.seed,
save_runs,
parallel_mode,
max_num_cores) {
###
......@@ -154,6 +156,7 @@ sample_nb <- function(raster,
if (length(which_models_null[which_models_null == FALSE]) > 0) {
models <- models[which_models_null]
}
for (jj in 1:nrow(reference)) {
ref <- jj
rr = 3
......@@ -249,16 +252,29 @@ sample_nb <- function(raster,
dummy <- raster::calc(dummy, fun = sum)
layer[[1]] <- dummy
obj <- new(
"Habitat",
models = models,
ref_samples = points,
switch = switch,
layer = layer,
mod_all = mod_all,
class_ind = dif,
seeds = seed2
)
if (save_runs == TRUE) {
obj <- new(
"Habitat",
models = models,
ref_samples = points,
switch = switch,
layer = layer,
mod_all = mod_all,
class_ind = dif,
seeds = seed2
)
} else {
obj <- new(
"Habitat",
models = NULL,
ref_samples = NULL,
switch = NULL,
layer = layer,
mod_all = NULL,
class_ind = NULL,
seeds = NULL
)
}
out <- list(index = index, acc = acc, obj = obj)
return(out)
}
......@@ -158,6 +158,7 @@ multi_Class_Sampling <- function(in.raster,
last = last,
seed = seed,
init.seed = init.seed,
save_runs = save_runs,
parallel_mode = parallel_mode,
max_num_cores = max_num_cores
)
......@@ -210,6 +211,7 @@ multi_Class_Sampling <- function(in.raster,
last = last,
seed = seed,
init.seed = init.seed,
save_runs = save_runs,
parallel_mode = parallel_mode,
max_num_cores = max_num_cores
)
......@@ -267,6 +269,7 @@ multi_Class_Sampling <- function(in.raster,
last = last,
seed = seed,
init.seed = init.seed,
save_runs = save_runs,
parallel_mode = parallel_mode,
max_num_cores = max_num_cores
)
......
......@@ -18,6 +18,7 @@ sample_nb(
last,
seed,
init.seed,
save_runs,
parallel_mode,
max_num_cores
)
......@@ -47,6 +48,8 @@ sample_nb(
\item{init.seed}{"sample" for new or use run1@seeds to reproduce previous steps}
\item{save_runs}{if the user wants to save the runs, if TRUE the complete Habitat Class object is returned}
\item{parallel_mode}{run loops in parallel}
\item{max_num_cores}{maximum number of cores for parallelism}
......@@ -59,13 +62,13 @@ a list with 3 elements:
\item An index
\item Accuracy vector
\item A vector with a Habitat objects, each consisting of 7 slots: \cr
run1@models - list of selected classifiers \cr
run1@ref_samples - list of SpatialPointsDataFrames with same length as run1@models holding reference labels \link{1,2} for each selected model \cr
run1@switch - vector of length run1@models indicating if target class equals 2, if not NA the labels need to be switched \cr
run1@models - list of selected classifiers (only if save_runs is TRUE) \cr
run1@ref_samples - list of SpatialPointsDataFrames with same length as run1@models holding reference labels \link{1,2} for each selected model (only if save_runs is TRUE) \cr
run1@switch - vector of length run1@models indicating if target class equals 2, if not NA the labels need to be switched (only if save_runs is TRUE) \cr
run1@layer - raster map of habitat type probability \cr
run1@mod_all - list of all classifiers (equals nb_models) \cr
run1@class_ind - vector of predictive distance measure for all habitats \cr
run1@seeds - vector of seeds for random sampling \cr
run1@mod_all - list of all classifiers (equals nb_models) (only if save_runs is TRUE) \cr
run1@class_ind - vector of predictive distance measure for all habitats (only if save_runs is TRUE) \cr
run1@seeds - vector of seeds for random sampling (only if save_runs is TRUE) \cr
all files are saved with step number, the *.tif file is additionally saved with class names
}
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment