Skip to content

Commit

Permalink
fix checks
Browse files Browse the repository at this point in the history
  • Loading branch information
huizezhang-sherry committed Sep 4, 2024
1 parent 40528cd commit 17fd891
Show file tree
Hide file tree
Showing 11 changed files with 147 additions and 9 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,6 @@ License: MIT + file LICENSE
LazyData: true
URL: https://github.com/ggobi/tourr
BugReports: https://github.com/ggobi/tourr/issues
RoxygenNote: 7.3.1
RoxygenNote: 7.3.2
Encoding: UTF-8
VignetteBuilder: knitr
2 changes: 2 additions & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -142,12 +142,14 @@ importFrom(graphics,rect)
importFrom(graphics,segments)
importFrom(graphics,stars)
importFrom(graphics,text)
importFrom(stats,loess)
importFrom(stats,mahalanobis)
importFrom(stats,na.omit)
importFrom(stats,qchisq)
importFrom(stats,quantile)
importFrom(stats,residuals)
importFrom(stats,rnorm)
importFrom(stats,runif)
importFrom(stats,var)
importFrom(utils,globalVariables)
importFrom(utils,tail)
1 change: 1 addition & 0 deletions R/interesting-indices.r
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ splines2d <- function() {
}

#' @rdname spline-loess
#' @importFrom stats loess
#' @export
loess2d <- function() {
function(mat) {
Expand Down
31 changes: 27 additions & 4 deletions R/search-jellyfish.R
Original file line number Diff line number Diff line change
@@ -1,15 +1,20 @@
#' An jellyfish optimisers for the projection pursuit guided tour
#' A jellyfish optimiser for projection pursuit guided tour
#'
#' @param current starting projection, a list of basis of class "multi-bases"
#' @param index index function
#' @param tries the counter of the outer loop of the opotimiser
#' @param max.tries the maximum number of iteration before giving up
#' @param ... other arguments being passed into the \code{search_jellyfish()}
#' @keywords optimize
#' @importFrom stats runif
#' @rdname jellyfish
#' @export
#' @examples
#' res <- animate_xy(flea[, 1:6], guided_tour(holes(), search_f = search_jellyfish))
#' res
#' library(dplyr)
#' res <- animate_xy(flea[, 1:6], guided_tour(lda_pp(cl = flea$species),
#' search_f = search_jellyfish))
#' bases <- res |> filter(loop == 1) |> pull(basis) |> check_dup(0.1)
#' animate_xy(data = flea[,1:6], tour_path = planned_tour(bases), col = flea$species)
search_jellyfish <- function(current, index, tries, max.tries = 50, ...) {
rcd_env <- parent.frame(n = 4)
if (is.null(rcd_env[["record"]])) rcd_env <- parent.frame(n = 1)
Expand Down Expand Up @@ -44,7 +49,7 @@ search_jellyfish <- function(current, index, tries, max.tries = 50, ...) {
target = lapply(current, function(i) {update_typeB(i, current)})
}

target <- purrr::map2(current, target, correct_orientation)
target <- mapply(correct_orientation, current, target)
target_idx <- sapply(target, index)

# if the target is worse than current, use current
Expand Down Expand Up @@ -81,4 +86,22 @@ search_jellyfish <- function(current, index, tries, max.tries = 50, ...) {
}
}

#' @param bases a list of bases extracted from the data collection object, see examples
#' @param min_dist the minimum distance between two bases
#' @rdname jellyfish
check_dup <- function(bases, min_dist) {
res <- list()
res[[1]] <- bases[[1]]
i <- 1; j <- 2
while(j <= length(bases)){
if (proj_dist(bases[[i]], bases[[j]]) >= min_dist) {
res <- c(res, list(bases[[j]]))
i <- i + 1; j <- j + 1
} else{
j <- j + 1
}
}
return(res)
}

globalVariables(c("loop"))
1 change: 1 addition & 0 deletions R/tour-guided.r
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
#' a better projection before giving up
#' @param max.i the maximum index value, stop search if a larger value is found
#' @param n_sample number of samples to generate if \code{search_f} is \code{\link{search_polish}}
#' @param n_jellies only used for \code{search_jellyfish}, the number of jellyfish to use
#' @param ... arguments sent to the search_f
#' @seealso \code{\link{cmass}}, \code{\link{holes}} and \code{\link{lda_pp}}
#' for examples of index functions. The function should take a numeric
Expand Down
2 changes: 2 additions & 0 deletions R/util.r
Original file line number Diff line number Diff line change
Expand Up @@ -162,3 +162,5 @@ mapShapes <- function(x, shapeset) {
shapes <- shapeset
shapes[as.numeric(x)]
}


12 changes: 12 additions & 0 deletions man/anomaly_index.Rd

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

67 changes: 67 additions & 0 deletions man/guided_anomaly_tour.Rd

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

2 changes: 2 additions & 0 deletions man/guided_tour.Rd

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

18 changes: 14 additions & 4 deletions man/search_jellyfish.Rd → man/jellyfish.Rd

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

18 changes: 18 additions & 0 deletions man/mahal_dist.Rd

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

0 comments on commit 17fd891

Please sign in to comment.