Commit 3c0527b6 authored by Romulo Pereira Goncalves's avatar Romulo Pereira Goncalves
Browse files

Indentation

parent ec8c492e
......@@ -148,10 +148,14 @@ model_opt_r <- function(k,
width = buffer,
byid = TRUE)
test1<-na.omit(raster::as.matrix(fasterize::fasterize(sf::st_as_sf(poly), rast[[1]])*rast))
nam<-as.vector(fasterize::fasterize(sf::st_as_sf(poly), rast[[1]], field="V1"))[-attr(test1,"na.action")]
test1 <-
na.omit(raster::as.matrix(fasterize::fasterize(sf::st_as_sf(poly), rast[[1]]) *
rast))
nam <-
as.vector(fasterize::fasterize(sf::st_as_sf(poly), rast[[1]], field = "V1"))[-attr(test1, "na.action")]
co<-raster::xyFromCell(rast, c(1:raster::ncell(rast))[-attr(test1,"na.action")])
co <-
raster::xyFromCell(rast, c(1:raster::ncell(rast))[-attr(test1, "na.action")])
pbtn1 <- as.data.frame(cbind(nam, co))
sp::coordinates(pbtn1) <- c("x", "y")
......@@ -168,33 +172,40 @@ model_opt_r <- function(k,
}
######################################
###balancing sample size
di <- c(sum(pbtn1@data$nam==1), sum(pbtn1@data$nam==2))
di <- c(sum(pbtn1@data$nam == 1), sum(pbtn1@data$nam == 2))
if (abs(di[1] - di[2]) > min(di) * 0.3) {
if (which.min(di) == 2) {
set.seed(seed)
d3 <- sample(which(pbtn1@data$nam==1), di[1]-di[2], replace = F)
d3 <- sample(which(pbtn1@data$nam == 1), di[1] - di[2], replace = F)
pbtn1 <- pbtn1[-d3, ]
test1 <- test1[-d3, ]
} else {
set.seed(seed)
d4 <- sample(which(pbtn1@data$nam==2), di[2]-di[1], replace = F)
d4 <- sample(which(pbtn1@data$nam == 2), di[2] - di[1], replace = F)
pbtn1 <- pbtn1[-d4, ]
test1 <- test1[-d4, ]
}
}
#####################################
###maximum sample size
if (sum(pbtn1@data$nam==1) > max_samples_per_class) {
if (sum(pbtn1@data$nam == 1) > max_samples_per_class) {
set.seed(seed)
dr <-
sample(which(pbtn1@data$nam==1), sum(pbtn1@data$nam==1) - max_samples_per_class, replace = F)
sample(which(pbtn1@data$nam == 1),
sum(pbtn1@data$nam == 1) - max_samples_per_class,
replace = F)
pbtn1 <- pbtn1[-dr, ]
test1 <- test1[-dr, ]
}
if (sum(pbtn1@data$nam==2) > max_samples_per_class) {
if (sum(pbtn1@data$nam == 2) > max_samples_per_class) {
set.seed(seed)
dr <-
sample(which(pbtn1@data$nam==2), sum(pbtn1@data$nam==2) - max_samples_per_class, replace = F)
sample(
which(pbtn1@data$nam == 2),
sum(pbtn1@data$nam == 2) - max_samples_per_class,
replace = F
)
pbtn1 <- pbtn1[-dr, ]
test1 <- test1[-dr, ]
}
......
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