Skip to content

Commit

Permalink
add more in-built data
Browse files Browse the repository at this point in the history
  • Loading branch information
huizezhang-sherry committed May 21, 2024
1 parent 7da9d44 commit abf1ea9
Show file tree
Hide file tree
Showing 24 changed files with 239 additions and 258 deletions.
1 change: 1 addition & 0 deletions .Rbuildignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,4 @@
^codemeta\.json$
^cran-comments\.md$
^CRAN-RELEASE$
^data-raw$
1 change: 1 addition & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ importFrom(cli,cli_abort)
importFrom(ggplot2,"%+replace%")
importFrom(magrittr,"%>%")
importFrom(rlang,.data)
importFrom(rlang,`:=`)
importFrom(tidyr,unnest)
importFrom(tourr,basis_random)
importFrom(tourr,interpolate)
Expand Down
2 changes: 1 addition & 1 deletion R/calc-smoothness.R
Original file line number Diff line number Diff line change
Expand Up @@ -44,4 +44,4 @@ calc_smoothness <- function(idx, data = sine1000, n_basis = 300, n = 6, d = 2,
}


globalVariables(c("basis"))
globalVariables(c("basis", "sine1000"))
42 changes: 42 additions & 0 deletions R/data-pipe-sine.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
#' Simulated sine, pipe, and gaussian mixture
#'
#' Simulated sine and pipe data for calculating optimisation features.
#' Each dataset has 1000 observations and the last two columns contain the
#' intended structure with the rest being noise.
#' @rdname pipe-sine-boa
#' @examples
#' library(ggplot2)
#' library(tidyr)
#' library(dplyr)
#' boa %>%
#' pivot_longer(cols = x1:x10, names_to = "var", values_to = "value") %>%
#' mutate(var = forcats::fct_relevel(as.factor(var), paste0("x", 1:10))) %>%
#' ggplot(aes(x = value)) +
#' geom_density() +
#' facet_wrap(vars(var))
#'
#' sine1000 |> ggplot(aes(x = V5, y = V6)) + geom_point() + theme(aspect.ratio = 1)
#' pipe1000_8d |> ggplot(aes(x = V5, y = V6)) + geom_point() + theme(aspect.ratio = 1)
#' pipe1000_8d |> ggplot(aes(x = V7, y = V8)) + geom_point() + theme(aspect.ratio = 1)
"sine1000"

#' @rdname pipe-sine-boa
"pipe1000"

#' @rdname pipe-sine-boa
"pipe1000_8d"

#' @rdname pipe-sine-boa
"pipe1000_10d"

#' @rdname pipe-sine-boa
"pipe1000_12d"

#' @rdname pipe-sine-boa
"boa"

#' @rdname pipe-sine-boa
"boa5"

#' @rdname pipe-sine-boa
"boa6"
93 changes: 8 additions & 85 deletions R/data.R
Original file line number Diff line number Diff line change
@@ -1,104 +1,27 @@
#' Simulated data
#' Data objects collected during the projection pursuit optimisation
#'
#' The \code{boa} data is simulated using different Gaussian mixtures with varied centres and weights (see section format for the simulation code).
#' Theses data are simulated for demonstrating the usage of four diagnostic plots in the package,
#' Simulated data to demonstrate the usage of four diagnostic plots in the package,
#' users can create their own guided tour data objects and diagnose with the visualisation designed in this package.
#'
#' The prefix \code{holes_*} indicates the use of holes index in the guided tour. The suffix \code{*_better/geo} indicates the optimiser used: \code{search_better} and \code{search_geodesic}.
#'
#' The name \code{boa} comes from the fact that the density plot of each variable in the data looks like boa constrictors swallowing multiple French baguettes, rather than elephants, as in the novella the little prince.
#'
#' @format
#' The code for simulating each data object is as follows:
#' \preformatted{
#' set.seed(123456);
#' holes_1d_geo <-
#' animate_dist(boa5, tour_path = guided_tour(holes(), d = 1,
#' search_f = search_geodesic),
#' rescale = FALSE)
#'
#' set.seed(123456)
#' holes_1d_better <-
#' animate_dist(boa5, tour_path = guided_tour(holes(), d = 1,
#' search_f = search_better),
#' rescale = FALSE)
#'
#'set.seed(123456);
#' holes_1d_jellyfish <- animate_dist(
#' boa5, tour_path = guided_tour(
#' holes(), d = 1, search_f = search_jellyfish, n_jellies = 100,
#' max.tries = 50), rescale = FALSE)
#'
#' set.seed(123456)
#' holes_2d_better <-
#' animate_xy(boa6, tour_path = guided_tour(holes(), d = 2,
#' search_f = search_better),
#' rescale = FALSE)
#'
#' set.seed(123456)
#' holes_2d_better_max_tries <-
#' animate_xy(boa6, tour_path = guided_tour(holes(), d = 2,
#' search_f = search_better,
#' max.tries = 500),
#' rescale = FALSE)
#'
#' library(tidyverse)
#' set.seed(1234)
#' x1 <- rnorm(1000, 0, 1)
#' x2 <- sample(c(rnorm(500, -3, 1), rnorm(500, 3, 1)), size = 1000)
#' x3 <- sample(c(rep(-1, 500), rep(1, 500)), size = 1000)
#' x4 <- sample(c(rnorm(250, -3, 1), rnorm(750, 3, 1)), size = 1000)
#' x5 <- sample(c(rnorm(330, -5, 1), rnorm(340, 0, 1), rnorm(330, 5, 1)), size = 1000)
#' x6 <- sample(c(rnorm(450, -5, 1), rnorm(100, 0, 1), rnorm(450, 5, 1)), size = 1000)
#' x7 <- sample(c(rnorm(500, -5, 1), rnorm(500, 5, 1)), size = 1000)
#' x8 <- rnorm(1000, 0, 1)
#' x9 <- rnorm(1000, 0, 1)
#' x10 <- rnorm(1000, 0, 1)
#'
#' boa <- tibble(x1 = x1, x2 = x2, x3 = x3, x4 = x4, x5 = x5,
#' x6 = x6, x7 = x7, x8 = x8, x9 = x9, x10 = x10) %>%
#' boa <- as_tibble(scale(boa))
#' boa5 <- select(boa, x1, x2, x8: x10)
#' boa6 <- select(boa, x1, x2, x7: x10)
#' }
#' The prefix \code{holes_*} indicates the use of holes index in the guided tour.
#' The suffix \code{*_better/geo/jellyfish} indicates the optimiser used:
#' \code{search_better}, \code{search_geodesic}, \code{search_jellyfish}.
#'
#' @examples
#' library(ggplot2)
#' library(tidyr)
#' library(dplyr)
#' boa %>%
#' pivot_longer(cols = x1:x10, names_to = "var", values_to = "value") %>%
#' mutate(var = forcats::fct_relevel(as.factor(var), paste0("x", 1:10))) %>%
#' ggplot(aes(x = value)) +
#' geom_density() +
#' facet_wrap(vars(var))
#'holes_1d_better %>%
#' explore_trace_interp(interp_size = 2) +
#' scale_color_continuous_botanical(palette = "fern")
#' @rdname data
"holes_1d_geo"

#' @format
#' @rdname data
"holes_1d_better"

#' @format
#' @rdname data
"holes_1d_jellyfish"

#' @format
#' @rdname data
"holes_2d_better"

#' @format
#' @rdname data
"holes_2d_better_max_tries"

#' @format
#' @rdname data
"boa"

#' @format
#' @rdname data
"boa5"

#' @format
#' @rdname data
"boa6"
1 change: 1 addition & 0 deletions R/ferrn-package.R
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@
#' @importFrom GpGp fit_model
#' @importFrom cli cli_abort
#' @importFrom tidyr unnest
#' @importFrom rlang `:=`
"_PACKAGE"
49 changes: 49 additions & 0 deletions data-raw/holes.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
#' code to prepare `holes` dataset goes her
set.seed(123456);
holes_1d_geo <- animate_dist(boa5, tour_path = guided_tour(
holes(), d = 1, search_f = search_geodesic), rescale = FALSE)

set.seed(123456)
holes_1d_better <-animate_dist(boa5, tour_path = guided_tour(
holes(), d = 1, search_f = search_better), rescale = FALSE)

set.seed(123456);
holes_1d_jellyfish <- animate_dist(boa5, tour_path = guided_tour(
holes(), d = 1, search_f = search_jellyfish, n_jellies = 100,
max.tries = 50), rescale = FALSE)

set.seed(123456)
holes_2d_better <- animate_xy(boa6, tour_path = guided_tour(
holes(), d = 2, search_f = search_better), rescale = FALSE)

set.seed(123456)
holes_2d_better_max_tries <- animate_xy(boa6, tour_path = guided_tour(
holes(), d = 2, search_f = search_better, max.tries = 500), rescale = FALSE)

library(tidyverse)
set.seed(1234)
x1 <- rnorm(1000, 0, 1)
x2 <- sample(c(rnorm(500, -3, 1), rnorm(500, 3, 1)), size = 1000)
x3 <- sample(c(rep(-1, 500), rep(1, 500)), size = 1000)
x4 <- sample(c(rnorm(250, -3, 1), rnorm(750, 3, 1)), size = 1000)
x5 <- sample(c(rnorm(330, -5, 1), rnorm(340, 0, 1), rnorm(330, 5, 1)), size = 1000)
x6 <- sample(c(rnorm(450, -5, 1), rnorm(100, 0, 1), rnorm(450, 5, 1)), size = 1000)
x7 <- sample(c(rnorm(500, -5, 1), rnorm(500, 5, 1)), size = 1000)
x8 <- rnorm(1000, 0, 1)
x9 <- rnorm(1000, 0, 1)
x10 <- rnorm(1000, 0, 1)
boa <- tibble(x1 = x1, x2 = x2, x3 = x3, x4 = x4, x5 = x5,
x6 = x6, x7 = x7, x8 = x8, x9 = x9, x10 = x10) %>%
boa <- as_tibble(scale(boa))
boa5 <- select(boa, x1, x2, x8: x10)
boa6 <- select(boa, x1, x2, x7: x10)

usethis::use_data(holes_1d_geo, overwrite = TRUE)
usethis::use_data(holes_1d_better, overwrite = TRUE)
usethis::use_data(holes_1d_jellyfish, overwrite = TRUE)
usethis::use_data(holes_2d_better, overwrite = TRUE)
usethis::use_data(holes_2d_max_tries, overwrite = TRUE)
usethis::use_data(boa, overwrite = TRUE)
usethis::use_data(boa5, overwrite = TRUE)
usethis::use_data(boa6, overwrite = TRUE)

27 changes: 27 additions & 0 deletions data-raw/pipe-sine.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
## code to prepare `pipe-sine` dataset goes here
library(spinebil) # devtools::install_github("uschiLaa/spinebil")
set.seed(123456)
sine1000 <- spinebil::sinData(6, 1000) %>% scale()
colnames(sine1000) <- paste0("V", 1:6)

set.seed(123456)
pipe1000 <- spinebil::pipeData(6, 1000) %>% scale()
colnames(pipe1000) <- paste0("V", 1:6)

set.seed(123456)
pipe1000_8d <- spinebil::pipeData(8, 1000) %>% scale()
colnames(pipe1000_8d) <- paste0("V", 1:8)

set.seed(123456)
pipe1000_10d <- spinebil::pipeData(10, 1000) %>% scale()
colnames(pipe1000_10d) <- paste0("V", 1:10)

set.seed(123456)
pipe1000_12d <- spinebil::pipeData(12, 1000) %>% scale()
colnames(pipe1000_12d) <- paste0("V", 1:12)

usethis::use_data(sine1000, overwrite = TRUE)
usethis::use_data(pipe1000, overwrite = TRUE)
usethis::use_data(pipe1000_8d, overwrite = TRUE)
usethis::use_data(pipe1000_10d, overwrite = TRUE)
usethis::use_data(pipe1000_12d, overwrite = TRUE)
Binary file added data/pipe1000.rda
Binary file not shown.
Binary file added data/pipe1000_10d.rda
Binary file not shown.
Binary file added data/pipe1000_12d.rda
Binary file not shown.
Binary file added data/pipe1000_8d.rda
Binary file not shown.
Binary file added data/sine1000.rda
Binary file not shown.
2 changes: 1 addition & 1 deletion docs/index.html

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

2 changes: 1 addition & 1 deletion docs/pkgdown.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ pandoc: 3.1.1
pkgdown: 2.0.8
pkgdown_sha: ~
articles: {}
last_built: 2024-05-21T16:44Z
last_built: 2024-05-21T17:40Z
urls:
reference: https://huizezhang-sherry.github.io/ferrn/reference
article: https://huizezhang-sherry.github.io/ferrn/articles
Expand Down
Binary file modified docs/reference/Rplot002.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/reference/Rplot003.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/reference/data-1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit abf1ea9

Please sign in to comment.