Skip to content

Commit

Permalink
Fix bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
relund committed Feb 5, 2024
1 parent 75a33cb commit c2bbbb9
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 7 deletions.
35 changes: 28 additions & 7 deletions R/ndset.R
Original file line number Diff line number Diff line change
Expand Up @@ -183,8 +183,6 @@ criterionPoints<-function(pts, obj, crit, labels = "coord") {
#' addNDSet(c(2,2), nDSet, crit = "max")
#' addNDSet(c(2,2), nDSet, crit = "min")
#'
#' addNDSet(c(2,2), crit = "min")
#'
#' \donttest{
#' nDSet <- data.frame(z1=c(12,14,16,18), z2=c(18,16,12,4), z3 = c(1,7,0,6))
#' pts <- data.frame(z1=c(12,14,16,18), z2=c(18,16,12,4), z3 = c(2,2,2,6))
Expand Down Expand Up @@ -461,7 +459,7 @@ addNDSet2D<-function(pts, nDSet = NULL, crit = "max", keepDom = FALSE) {
#' sense. The best option is properly to use a center and radius here. Moreover, as for higher
#' `p` you may have to use a larger radius than half of the desired interval range.
#'
#' @return A data frame with `p` columns
#' @return A matrix with `p` columns.
#' @export
#'
#' @examples
Expand Down Expand Up @@ -782,6 +780,7 @@ genSample <- function(p, n, range = c(1,100), random = FALSE, sphere = TRUE, pla
}

if (nrow(set) != n) warning("Only ", nrow(set), " samples generated!")
colnames(set) <- paste0("z", 1:p)
return(set)
}

Expand Down Expand Up @@ -809,7 +808,8 @@ genSample <- function(p, n, range = c(1,100), random = FALSE, sphere = TRUE, pla
#'
#' @examples
#' \donttest{
#' range <- matrix(c(1,100, 50,100, 10, 50), ncol = 2, byrow = TRUE )
#' ## Random
#' range <- matrix(c(1,100, 50, 100, 10, 50), ncol = 2, byrow = TRUE)
#' pts <- genNDSet(3, 5, range = range, random = TRUE, keepDom = TRUE)
#' head(pts)
#' Rfast::colMinsMaxs(as.matrix(pts[, 1:3]))
Expand All @@ -821,6 +821,28 @@ genSample <- function(p, n, range = c(1,100), random = FALSE, sphere = TRUE, pla
#' plotCones3D(pts[pts$nd,1:3], argsPolygon3d = list(alpha = 1))
#' finalize3D()
#'
#'
#' ## Between planes
#' range <- matrix(c(1,100, 50,100, 10, 50), ncol = 2, byrow = TRUE)
#' center <- rowMeans(range)
#' planeU <- c(rep(1, 3), -1.2*sum(rowMeans(range)))
#' planeL <- c(rep(1, 3), -0.8*sum(rowMeans(range)))
#' pts <- genNDSet(3, 50, range = range, planes = TRUE, keepDom = TRUE, classify = TRUE,
#' argsPlanes = list(center = center, planeU = planeU, planeL = planeL))
#' head(pts)
#' Rfast::colMinsMaxs(as.matrix(pts[, 1:3]))
#' ini3D(FALSE, argsPlot3d = list(xlim = c(min(pts[,1])-2,max(pts[,1])+10),
#' ylim = c(min(pts[,2])-2,max(pts[,2])+10),
#' zlim = c(min(pts[,3])-2,max(pts[,3])+10),
#' box = TRUE, axes = TRUE))
#' plotPoints3D(pts[,1:3])
#' plotPoints3D(pts[pts$nd,1:3], argsPlot3d = list(col = "red", size = 10))
#' rgl::planes3d(planeL[1], planeL[2], planeL[3], planeL[4], alpha = 0.5)
#' rgl::planes3d(planeU[1], planeU[2], planeU[3], planeU[4], alpha = 0.5)
#' finalize3D()
#'
#'
#' ## On a sphere
#' ini3D()
#' range <- c(1,100)
#' cent <- rep(range[1] + (range[2]-range[1])/2, 3)
Expand Down Expand Up @@ -856,10 +878,9 @@ genNDSet <-
box = FALSE,
keepDom = FALSE,
crit = "min",
dubND = TRUE,
dubND = FALSE,
classify = FALSE,
...) {

set <- genSample(p, 2 * n, range = range, random = random, planes = planes, sphere = sphere, box = box, ...)
nDSet <- addNDSet(set, crit = crit, keepDom = keepDom, dubND = dubND, classify = FALSE)
ctr <- 0
Expand Down Expand Up @@ -887,7 +908,7 @@ genNDSet <-
slice_sample(n = n) %>%
tibble::remove_rownames()
}
if (classify) nDSet <- addNDSet(nDSet, crit = crit, keepDom = keepDom, dubND = dubND, classify = classify)
if (classify) nDSet <- addNDSet(nDSet[, 1:p], crit = crit, keepDom = keepDom, dubND = dubND, classify = classify)
return(nDSet)
}

Expand Down
3 changes: 3 additions & 0 deletions man/genNDSet.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit c2bbbb9

Please sign in to comment.