diff --git a/DESCRIPTION b/DESCRIPTION index c718cee1..9d455634 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -41,6 +41,6 @@ License: MIT + file LICENSE LazyData: true URL: https://github.com/ggobi/tourr, https://ggobi.github.io/tourr/ BugReports: https://github.com/ggobi/tourr/issues -RoxygenNote: 7.3.1 +RoxygenNote: 7.3.2 Encoding: UTF-8 VignetteBuilder: knitr diff --git a/NAMESPACE b/NAMESPACE index 9ba0d279..2eda24e4 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -143,12 +143,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) diff --git a/R/interesting-indices.r b/R/interesting-indices.r index 160d665a..572596d1 100644 --- a/R/interesting-indices.r +++ b/R/interesting-indices.r @@ -84,6 +84,7 @@ splines2d <- function() { } #' @rdname spline-loess +#' @importFrom stats loess #' @export loess2d <- function() { function(mat) { diff --git a/R/search-jellyfish.R b/R/search-jellyfish.R index 36e14664..44a45403 100644 --- a/R/search-jellyfish.R +++ b/R/search-jellyfish.R @@ -1,4 +1,4 @@ -#' 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 @@ -6,10 +6,15 @@ #' @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) @@ -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 @@ -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")) diff --git a/R/tour-guided.r b/R/tour-guided.r index 25fbe3cb..a3a4e1d7 100644 --- a/R/tour-guided.r +++ b/R/tour-guided.r @@ -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 diff --git a/R/util.r b/R/util.r index e2750d10..468de741 100644 --- a/R/util.r +++ b/R/util.r @@ -162,3 +162,5 @@ mapShapes <- function(x, shapeset) { shapes <- shapeset shapes[as.numeric(x)] } + + diff --git a/man/guided_tour.Rd b/man/guided_tour.Rd index 83375437..6ea88cb2 100644 --- a/man/guided_tour.Rd +++ b/man/guided_tour.Rd @@ -33,6 +33,8 @@ a better projection before giving up} \item{search_f}{the search strategy to use: \code{\link{search_geodesic}}, \code{\link{search_better}}, \code{\link{search_better_random}}, \code{\link{search_polish}}. Default is \code{\link{search_geodesic}}.} +\item{n_jellies}{only used for \code{search_jellyfish}, the number of jellyfish to use} + \item{n_sample}{number of samples to generate if \code{search_f} is \code{\link{search_polish}}} \item{alpha}{the initial size of the search window, in radians} diff --git a/man/search_jellyfish.Rd b/man/jellyfish.Rd similarity index 50% rename from man/search_jellyfish.Rd rename to man/jellyfish.Rd index c4fec8d1..0307cfa0 100644 --- a/man/search_jellyfish.Rd +++ b/man/jellyfish.Rd @@ -2,9 +2,12 @@ % Please edit documentation in R/search-jellyfish.R \name{search_jellyfish} \alias{search_jellyfish} -\title{An jellyfish optimisers for the projection pursuit guided tour} +\alias{check_dup} +\title{A jellyfish optimiser for projection pursuit guided tour} \usage{ search_jellyfish(current, index, tries, max.tries = 50, ...) + +check_dup(bases, min_dist) } \arguments{ \item{current}{starting projection, a list of basis of class "multi-bases"} @@ -16,12 +19,19 @@ search_jellyfish(current, index, tries, max.tries = 50, ...) \item{max.tries}{the maximum number of iteration before giving up} \item{...}{other arguments being passed into the \code{search_jellyfish()}} + +\item{bases}{a list of bases extracted from the data collection object, see examples} + +\item{min_dist}{the minimum distance between two bases} } \description{ -An jellyfish optimisers for the projection pursuit guided tour +A jellyfish optimiser for projection pursuit guided tour } \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) } \keyword{optimize} diff --git a/man/skewness.Rd b/man/skewness.Rd new file mode 100644 index 00000000..d08ae03a --- /dev/null +++ b/man/skewness.Rd @@ -0,0 +1,14 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/interesting-indices.r +\name{skewness} +\alias{skewness} +\title{Skewness index.} +\usage{ +skewness() +} +\description{ +Calculates the skewness index. See Cook, Buja and Cabrera (1993) +Projection pursuit indexes based on orthonormal function expansions + for equations. +} +\keyword{hplot}