Skip to content

Commit

Permalink
Merge pull request #44 from dewittpe/v0.3.0-rc
Browse files Browse the repository at this point in the history
V0.3.0 rc
  • Loading branch information
dewittpe authored Nov 29, 2023
2 parents 2743303 + f63ab96 commit 33e0299
Show file tree
Hide file tree
Showing 63 changed files with 822 additions and 2,209 deletions.
1 change: 1 addition & 0 deletions .Rbuildignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,4 @@
.document.Rout
.install_dev_deps.Rout
^\.github$
^cran-comments\.md$
13 changes: 7 additions & 6 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
Package: cpr
Title: Control Polygon Reduction
Version: 0.2.3.9005
Version: 0.3.0
Authors@R:
c(person("Peter", "DeWitt", email = "dewittpe@gmail.com", role = c("aut", "cre")),
c(person("Peter", "DeWitt", email = "dewittpe@gmail.com", role = c("aut", "cre"), comment = c(ORCID = "0000-0002-6391-0795")),
person("Samantha", "MaWhinney", email = "sam.mawhinney@ucdenver.edu", role = c("ths")),
person("Nichole", "Carlson", email = "nichole.carlson@ucdenver.edu", role = c("ths")))
Description: Implementation of the Control Polygon Reduction and Control Net
Expand All @@ -12,20 +12,21 @@ Depends:
License: GPL (>= 2)
Encoding: UTF-8
URL: https://github.com/dewittpe/cpr/
Language: en-us
LazyData: true
Imports:
ggplot2 (>= 2.2.0),
ggplot2 (>= 3.0.0),
lme4,
plot3D,
Rcpp (>= 0.12.13),
Rcpp (>= 1.0.11),
scales
LinkingTo: Rcpp (>= 0.12.13),
LinkingTo: Rcpp (>= 1.0.11),
RcppArmadillo
Suggests:
covr,
knitr,
qwraps2,
rmarkdown,
rgl
RoxygenNote: 7.2.1
RoxygenNote: 7.2.3
VignetteBuilder: knitr
5 changes: 3 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ CRAN = "https://cran.rstudio.com"

SRC = $(wildcard $(PKG_ROOT)/src/*.cpp)
RFILES = $(wildcard $(PKG_ROOT)/R/*.R)
EXAMPLES = $(wildcard $(PKG_ROOT)/examples/*.R)
TESTS = $(wildcard $(PKG_ROOT)/tests/testthat/*.R)
VIGNETTES = $(wildcard $(PKG_ROOT)/vignettes/*)
RAWDATAR = $(wildcard $(PKG_ROOT)/data-raw/*.R)
Expand All @@ -22,7 +21,7 @@ all: $(PKG_NAME)_$(PKG_VERSION).tar.gz
-e "options(warn = 2)"
@touch $@

.document.Rout: $(RFILES) $(SRC) $(EXAMPLES) $(RAWDATAR) $(VIGNETTES) $(PKG_ROOT)/DESCRIPTION
.document.Rout: $(RFILES) $(SRC) $(RAWDATAR) $(VIGNETTES) $(PKG_ROOT)/DESCRIPTION
if [ -e "$(PKG_ROOT)/data-raw/Makefile" ]; then $(MAKE) -C $(PKG_ROOT)/data-raw/; else echo "Nothing to do"; fi
Rscript --vanilla --quiet -e "options(repo = c('$(CRAN)', '$(BIOC)'))" \
-e "options(warn = 2)" \
Expand All @@ -44,4 +43,6 @@ clean:
$(RM) -rf $(PKG_NAME).Rcheck
$(RM) -f .document.Rout
$(RM) -f .install_dev_deps.Rout
$(RM) -f src/*.o
$(RM) -f src/*.so

2 changes: 2 additions & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ S3method(cn,formula)
S3method(cnr,cpr_cn)
S3method(cp,cpr_bs)
S3method(cp,formula)
S3method(cp_value,cpr_cp)
S3method(cp_value,default)
S3method(cpr,cpr_cp)
S3method(get_spline,cpr_cn)
S3method(get_spline,cpr_cp)
Expand Down
29 changes: 14 additions & 15 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,21 +1,20 @@
# Version 0.2.3.9005
# Version 0.3.0

## New Examples
* `cpr` has examples

## Vignettes
* The package overview has been changed from .Rmd to .Rnw and will be a draft of
a JSS submission.
* A new vignette focused on just B-splines has been started.

## Other Changes
* Depends on Rcpp >= 0.12.11 to handle registering native routines.
* Moves rgl from `Imports` to `Enhances` (re #36)
* Depends on Rcpp >= 0.12.11 (actually moved to >= 1.0.11) to handle registering native routines.
* Moves rgl from `Imports` to `Suggests` (re #36)
* Refactoring base code to eliminate the use of dplyr, tidyr, tibble, etc.
Focus on base R methods to reduce install dependencies and improve long term
stability of the package.
* Require R > 3.5.0
* Stop using testthat for testing
* Remove use of the tidyr, dplyr
* Improve documentation
* Minor bug fixes
* Replace use of now deprecated `ggplot2::aes_string`

# Version 0.2.3
First public release.
Expand Down Expand Up @@ -48,7 +47,7 @@ Documentation improvements.
* `is.` a collection of `is.cpr_cp`, `is.cpr_bs`, ... functions added.
* The dataset `spdg` has been added to the package.

## Non-User Visible Changes
## Other Changes
* removed a redundant `build_tensor` definition

# Version 0.2.0
Expand All @@ -75,12 +74,12 @@ Continued development should be focused on bug fixes and minor enhancements.
sequence and numeric values in `plot.cpr_bs` (#18)

## Bug Fixes
* `from` and `to` args for `plot.cpr_cpr` fixed (#14)
* `from` and `to` arguments for `plot.cpr_cpr` fixed (#14)
* correct construction of missing `iknots` argument in `btensor`
* `keep` is correctly handled in the `cnr` call.
* `show_xi` correctly handled in the `plot.cpr_cp` call.

## Non-User visible changes
## Non visible changes
* non-exported function `knot_expr` created to help with plotting the knot
locations in `cpr:::plot.cpr_bs`.

Expand All @@ -91,7 +90,7 @@ Continued development should be focused on bug fixes and minor enhancements.
When plotting multiple control polygons and splines, this option will make it
easier to view the spline functions.

# Non-visible changes:
## Non visible changes
* Extended testing scripts.

# Version 0.1.0
Expand All @@ -118,7 +117,7 @@ series. The aim for version 0.2.0 will be to have a very similar API for

## End User non-visible changes:
* Added the not-to-be-exported function `generate_cp_data`
* Redesign of the deboor.cpp file so that the bsplines are accessible. The
* Redesign of the `deboor.cpp` file so that the `bsplines` are accessible. The
prior design only allowed access to the basis, the current design allows
access to the generic B-splines.

Expand All @@ -131,8 +130,8 @@ Biometric Society, Student paper competition. The conference will be held 10 -
16 July 2016 in Victoria, British Columbia, Canada.

## Bug Fixes
* Corrected the attr calls within `cpr` after adjusting the attributes being set
on a `cpr_cp`.
* Corrected the attributes calls within `cpr` after adjusting the attributes
being set on a `cpr_cp`.

* `plot.cpr_bs` correctly displays the indices for the knot sequence.

Expand Down
21 changes: 11 additions & 10 deletions R/RcppExports.R
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# Generator token: 10BE3573-1514-4C36-9D1C-5A225CD40393

#' Knot Insertion, Removal, and Reinsertion
#'
#'
#' Functions for the insertion, removal, and reinsertion of internal knots for
#' B-splines.
#'
Expand All @@ -24,7 +24,7 @@
#' in knot insertion matrix.
#'
#' Examples for the \code{refine_ordinate}, \code{coarsen_ordinate}, and
#' \code{hat_ordinate} are best shown in the vignette,
#' \code{hat_ordinate} are best shown in the vignette,
#' \code{vignette("cpr-pkg", package = "cpr")}.
#'
#' \code{iknot_weights} returns a vector with the 'importance weight' of each
Expand Down Expand Up @@ -94,15 +94,16 @@ diag_only <- function(A, B) {
#'
#' Determine the rank (number of linearly independent columns) of a matrix.
#'
#' Implimentation via the Armadillo C++ linear algrebra library. The function
#' returns the rank of the matix \code{x}. The computation is based on the
#' singular value decomposition of the matrix; a std::runtime_error excetion
#' Implementation via the Armadillo C++ linear algebra library. The function
#' returns the rank of the matrix \code{x}. The computation is based on the
#' singular value decomposition of the matrix; a std::runtime_error exception
#' will be thrown if the decomposition fails. Any singular values less than
#' the tolerance are treated as zeros. The tolerance is max(m, n) * max_sv *
#' datum::eps, where m is the number of rows of x, n is the number of columns
#' of x, max_sv is the maximal singular value of x, and datum::eps is the
#' difference between 1 and the least value greater than 1 that is
#' representable.
#' the tolerance are treated as zeros. The tolerance is
#' \code{max(m, n) * max_sv * arma::datum::eps}, where \code{m} is the number
#' of rows of \code{x}, \code{n} is the number of columns of \code{x},
#' \code{max_sv} is the maximal singular value of \code{x}, and
#' \code{arma::datum::eps} is the difference between 1 and the least value
#' greater than 1 that is representable.
#'
#' @param x a numeric matrix
#'
Expand Down
10 changes: 6 additions & 4 deletions R/bsplines.R
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,8 @@ print.cpr_bs <- function(x, n = 6L, ...) {
#' plot(bmat, show_xi = FALSE, show_x = TRUE)
#' plot(bmat, show_xi = TRUE, show_x = FALSE) ## Default
#' plot(bmat, show_xi = FALSE, show_x = FALSE)
#' plot(bmat, show_xi = FALSE, show_x = FALSE)
#' plot(bmat, show_xi = FALSE, show_x = FALSE, color = FALSE)
#' @method plot cpr_bs
#' @export
plot.cpr_bs <- function(x, ..., show_xi = TRUE, show_x = FALSE, color = TRUE, digits = 2, n = 100) {
Expand All @@ -131,22 +133,22 @@ plot.cpr_bs <- function(x, ..., show_xi = TRUE, show_x = FALSE, color = TRUE, di
names(plot_data) <- c("value", "spline")
plot_data <- cbind(plot_data, data.frame(x = rep(xvec, times = ncol(bmat))))
levels(plot_data$spline) <- sub("V", "B", levels(plot_data$spline))
levels(plot_data$spline) <- sub("(\\d+)",
levels(plot_data$spline) <- sub("(\\d+)",
paste0("[list(\\1,k==", attr(x, "order"), ",bold(xi))](x)"),
levels(plot_data$spline))

g <-
ggplot2::ggplot(plot_data) +
ggplot2::theme_bw() +
ggplot2::aes_string(x = "x", y = "value") +
eval(substitute(ggplot2::aes(x = X, y = Y), list(X = as.name("x"), Y = as.name("value")))) +
ggplot2::geom_line() +
ggplot2::theme(axis.title = ggplot2::element_blank())

if (color) {
g <- g + ggplot2::aes_string(color = "spline")
g <- g + eval(substitute(ggplot2::aes(color = GRP), list(GRP = as.name("spline"))))
g <- g + ggplot2::scale_color_discrete(labels = scales::parse_format())
} else {
g <- g + ggplot2::aes_string(group = "spline")
g <- g + eval(substitute(ggplot2::aes(group = GRP), list(GRP = as.name("spline"))))
}

if (show_xi | show_x) {
Expand Down
17 changes: 16 additions & 1 deletion R/build_tensor.R
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,25 @@
#' @param x a matrix, or list of numeric matrices, build the tensor product
#' @param ... additional numeric matrices to build the tensor product
#'
#' @seealso
#' \code{vignette("cpr-pkg", package = "cpr")} for details on tensor products.
#'
#' @return
#' A matrix
#'
#' @example examples/build_tensor.R
#' @examples
#'
#' A <- matrix(1:4, nrow = 10, ncol = 20)
#' B <- matrix(1:6, nrow = 10, ncol = 6)
#'
#' # Two ways of building the same tensor product
#' tensor1 <- build_tensor(A, B)
#' tensor2 <- build_tensor(list(A, B))
#' all.equal(tensor1, tensor2)
#'
#' # a three matrix tensor product
#' tensor3 <- build_tensor(A, B, B)
#' str(tensor3)
#'
#' @export
build_tensor <- function(x, ...) {
Expand Down
4 changes: 2 additions & 2 deletions R/cnr_diagnostics.R
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
#' @export
#' @param x a \code{cpr_cnr} object
#' @param type type of diagnostic plot.
#' \code{"loglik"} for the loglikihood by degrees of freedom,
#' \code{"loglik"} for the log likelihood by degrees of freedom,
#' \code{"rmse"} for root mean squared residuals by model index
#' @param from the first index of \code{x} to plot
#' @param to the last index of \code{x} to plot
Expand All @@ -30,7 +30,7 @@ plot.cpr_cnr <- function(x, type = "rmse", from = 1, to, ...) {

ggplot2::ggplot(subset(s, (s$index >= from) & (s$index <= to))) +
ggplot2::theme_bw() +
ggplot2::aes_string(x = "index", y = type) +
eval(substitute(ggplot2::aes(x = X, y = Y), list(X = as.name("index"), Y = as.name(type)))) +
ggplot2::geom_point() +
ggplot2::geom_line() +
ggplot2::xlab("Index")
Expand Down
22 changes: 11 additions & 11 deletions R/cp.R
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,11 @@
#'
#' # via formula
#' dat <- data.frame(x = xvec, y = sin((xvec - 2)/pi) + 1.4 * cos(xvec/pi))
#' cp3 <- cp(y ~ cpr::bsplines(x) + 0, data = dat)
#' cp3 <- cp(y ~ cpr::bsplines(x), data = dat)
#'
#' # plot the control polygon, spline and target data.
#' plot(cp3, show_spline = TRUE) +
#' ggplot2::geom_line(mapping = ggplot2::aes_string(x = "x", y = "y"),
#' ggplot2::geom_line(mapping = ggplot2::aes(x = x, y = y),
#' data = dat, linetype = 2, color = "red")
#'
#' @export
Expand Down Expand Up @@ -158,7 +158,7 @@ summary.cpr_cp <- function(object, wiggle = FALSE, integrate.args = list(), ...)
wggl <- try(do.call(wiggle.cpr_cp, c(list(object = object), integrate.args)), silent = TRUE)


if (class(wggl) == "integrate") {
if (inherits(x = wggl, what = "integrate")) {
out$wiggle <- as.numeric(wggl$value)
attr(out$wiggle, "abs.error") <- wggl$abs.error
attr(out$wiggle, "subdivisions") <- wggl$subdivisions
Expand All @@ -182,7 +182,7 @@ summary.cpr_cp <- function(object, wiggle = FALSE, integrate.args = list(), ...)
#' \code{\link[ggplot2]{geom_rug}} to show the location of the knots in the
#' respective control polygons.
#' @param color Boolean (default FALSE) if more than one \code{cpr_cp} object is
#' to be plotted, set this value to TRUE to have the graphic in color (linetypes
#' to be plotted, set this value to TRUE to have the graphic in color (line types
#' will be used regardless of the color setting).
#' @param n the number of data points to use for plotting the spline
#'
Expand All @@ -195,10 +195,10 @@ plot.cpr_cp <- function(x, ..., show_cp = TRUE, show_spline = FALSE, show_xi = T
spline_data <-
lapply(list(x, ...), function(xx) {
b <- xx$bknots
bmat <- cpr::bsplines(seq(b[1], b[2], length = n),
iknots = xx$iknots,
bknots = b,
order = xx$order)
bmat <- bsplines(seq(b[1], b[2], length = n),
iknots = xx$iknots,
bknots = b,
order = xx$order)
data.frame(x = seq(b[1], b[2], length = n),
y = as.numeric(bmat %*% xx$cp$theta))
})
Expand Down Expand Up @@ -230,7 +230,7 @@ plot.cpr_cp <- function(x, ..., show_cp = TRUE, show_spline = FALSE, show_xi = T
base_plot <-
ggplot2::ggplot(plot_data) +
ggplot2::theme_bw() +
ggplot2::aes_string(x = "x", y = "y") +
eval(substitute(ggplot2::aes(x = X, y = Y), list(X = as.name("x"), Y = as.name("y")))) +
ggplot2::theme(axis.title = ggplot2::element_blank())

if (show_xi) {
Expand All @@ -255,14 +255,14 @@ plot.cpr_cp <- function(x, ..., show_cp = TRUE, show_spline = FALSE, show_xi = T
if (length(cps) > 1) {
base_plot <-
base_plot +
ggplot2::aes_string(linetype = "row") +
eval(substitute(ggplot2::aes(linetype = LTY), list(LTY = as.name("row")))) +
ggplot2::theme(legend.title = ggplot2::element_blank())
}

if (color) {
base_plot <-
base_plot +
ggplot2::aes_string(color = "row") +
eval(substitute(ggplot2::aes(color = CLR), list(CLR = as.name("row")))) +
ggplot2::theme(legend.title = ggplot2::element_blank())
}

Expand Down
13 changes: 7 additions & 6 deletions R/cp_diagnostics.R
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,24 @@
#'
#' @return
#' \code{cp_value} returns the ordinate on the control polygon line segment for
#' the abscissae \code{x} given. \code{x} could be a control vertex or on a
#' the abscissa \code{x} given. \code{x} could be a control vertex or on a
#' line segment defined by two control vertices of the control polygon
#' provided.
#'
#' \code{cp_diff} returns the absolute vertical distance between the control
#' vertices of cp1 to the control polygon cp2.
#'
#' @export
#' @rdname cp_diagnostics
#' @param x absicissa at which to determine the ordinate on control polygon cp
#' @param x abscissa at which to determine the ordinate on control polygon cp
#' @param obj a cpr_cp object or \code{data.frame} where the first column is the
#' abscissa and the second column is the ordinate for the control polygon vertices.
#'
#' @export
#' @rdname cp_diagnostics
cp_value <- function(obj, x) {
UseMethod("cp_value")
}

#' @method cp_value cpr_cp
#' @export
cp_value.cpr_cp <- function(obj, x) {
xi_star <- obj$xi_star
theta <- obj$theta
Expand All @@ -30,7 +31,7 @@ cp_value.cpr_cp <- function(obj, x) {
unname((theta[idx] - theta[idx - 1L]) / (xi_star[idx] - xi_star[idx - 1L]) * (x - xi_star[idx]) + theta[idx])
}

#' @method cp_value default
#' @export
cp_value.default <- function(obj, x) {
xi_star <- obj[[1]]
theta <- obj[[2]]
Expand Down
Loading

0 comments on commit 33e0299

Please sign in to comment.