Skip to content

Commit

Permalink
revert to static Makevars.win + add hatvalues()
Browse files Browse the repository at this point in the history
  • Loading branch information
JorisChau committed Apr 30, 2024
1 parent bda3f58 commit 0500436
Show file tree
Hide file tree
Showing 15 changed files with 96 additions and 88 deletions.
11 changes: 0 additions & 11 deletions .github/workflows/R-CMD-check.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ jobs:
- {os: windows-latest, r: 'devel', rtools: '44'}
- {os: windows-latest, r: 'next', rtools: '44'}
- {os: windows-latest, r: 'release', rtools: '43'}
#- {os: windows-latest, r: 'oldrel', rtools: '42'}
- {os: ubuntu-latest, r: 'devel'}
- {os: ubuntu-latest, r: 'next'}
- {os: ubuntu-latest, r: 'release'}
Expand All @@ -48,9 +47,6 @@ jobs:
env:
GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }}
R_KEEP_PKG_SOURCE: yes
RTOOLS42_HOME: C:\rtools42
RTOOLS43_HOME: C:\rtools43
RTOOLS44_HOME: C:\rtools44

steps:
- name: Configure git
Expand All @@ -72,13 +68,6 @@ jobs:
run: |
brew install gsl
- name: Install gsl (windows)
if: runner.os == 'windows'
run: |
pacman -Sy --noconfirm
pacman -S --noconfirm mingw-w64-{i686,x86_64}-gsl
shell: bash

- uses: r-lib/actions/setup-r-dependencies@v2
with:
extra-packages: rcmdcheck
Expand Down
4 changes: 2 additions & 2 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
Package: gslnls
Type: Package
Title: GSL Multi-Start Nonlinear Least-Squares Fitting
Version: 1.3.1
Date: 2024-04-25
Version: 1.3.2
Date: 2024-04-30
Authors@R: person("Joris", "Chau", email = "[email protected]", role = c("aut", "cre"))
Description: An R interface to nonlinear least-squares optimization with the GNU Scientific Library (GSL), see M. Galassi et al. (2009, ISBN:0954612078). The available trust region methods include the Levenberg-Marquardt algorithm with and without geodesic acceleration, the Steihaug-Toint conjugate gradient algorithm for large systems and several variants of Powell's dogleg algorithm. Multi-start optimization based on quasi-random samples is implemented using a modified version of the algorithm in Hickernell and Yuan (1997, OR Transactions). Bindings are provided to tune a number of parameters affecting the low-level aspects of the trust region algorithms. The interface mimics R's nls() function and returns model objects inheriting from the same class.
BugReports: https://github.com/JorisChau/gslnls/issues
Expand Down
2 changes: 2 additions & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ S3method(gsl_nls,"function")
S3method(gsl_nls,formula)
S3method(gsl_nls_large,"function")
S3method(gsl_nls_large,formula)
S3method(hatvalues,gsl_nls)
S3method(logLik,gsl_nls)
S3method(nobs,gsl_nls)
S3method(predict,gsl_nls)
Expand All @@ -35,6 +36,7 @@ importFrom(stats,df.residual)
importFrom(stats,fitted)
importFrom(stats,formula)
importFrom(stats,getInitial)
importFrom(stats,hatvalues)
importFrom(stats,model.weights)
importFrom(stats,nls)
importFrom(stats,nls.control)
Expand Down
5 changes: 5 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
# gslnls 1.3.2

* Reverted to static Makevars.win (supplied by T. Kalibera)
* Added new method `hatvalues()`

# gslnls 1.3.1

* Minor edits configure.ac to fix cran check results
Expand Down
3 changes: 2 additions & 1 deletion R/nls.R
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,8 @@
#' See the individual method descriptions for the structures of the returned lists and the generic functions
#' applicable to objects of both classes.
#' @useDynLib gslnls, .registration = TRUE
#' @importFrom stats nls numericDeriv deriv as.formula coef deviance df.residual fitted vcov formula getInitial model.weights pf pt qt setNames sigma nobs
#' @importFrom stats nls numericDeriv deriv as.formula coef deviance df.residual fitted vcov formula getInitial model.weights
#' @importFrom stats pf pt qt setNames sigma nobs hatvalues
#' @seealso \code{\link[stats]{nls}}
#' @seealso \url{https://www.gnu.org/software/gsl/doc/html/nls.html}
#' @references M. Galassi et al., \emph{GNU Scientific Library Reference Manual (3rd Ed.)}, ISBN 0954612078.
Expand Down
26 changes: 26 additions & 0 deletions R/nls_methods.R
Original file line number Diff line number Diff line change
Expand Up @@ -425,6 +425,32 @@ vcov.gsl_nls <- function(object, ...) {
sm$cov.unscaled * sm$sigma^2
}

#' Calculate leverage values
#' @description Returns leverage values (hat values) from a fitted \code{"gsl_nls"} object based on the estimated
#' variance-covariance matrix of the model parameters.
#' @inheritParams coef.gsl_nls
#' @param model An object inheriting from class \code{"gsl_nls"}.
#' @return Numeric vector of leverage values similar to \code{\link[stats]{hatvalues}}.
#' @seealso \code{\link[stats]{hatvalues}}
#' @examples
#' ## data
#' set.seed(1)
#' n <- 25
#' xy <- data.frame(
#' x = (1:n) / n,
#' y = 2.5 * exp(-1.5 * (1:n) / n) + rnorm(n, sd = 0.1)
#' )
#' ## model
#' obj <- gsl_nls(fn = y ~ A * exp(-lam * x), data = xy, start = c(A = 1, lam = 1))
#'
#' hatvalues(obj)
#' @export
hatvalues.gsl_nls <- function(model, ...) {
J <- model$m$gradient()
JtJinv <- chol2inv(model$m$Rmat())
diag((J %*% JtJinv) %*% t(J))
}

#' Anova tables
#' @description Returns the analysis of variance (or deviance) tables for two or
#' more fitted \code{"gsl_nls"} objects.
Expand Down
4 changes: 0 additions & 4 deletions cleanup.win

This file was deleted.

18 changes: 9 additions & 9 deletions configure
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#! /bin/sh
# Guess values for system-dependent variables and create Makefiles.
# Generated by GNU Autoconf 2.71 for gslnls 1.3.1.
# Generated by GNU Autoconf 2.71 for gslnls 1.3.2.
#
# Report bugs to <https://github.com/JorisChau/gslnls/issues/>.
#
Expand Down Expand Up @@ -610,8 +610,8 @@ MAKEFLAGS=
# Identity of this package.
PACKAGE_NAME='gslnls'
PACKAGE_TARNAME='gslnls'
PACKAGE_VERSION='1.3.1'
PACKAGE_STRING='gslnls 1.3.1'
PACKAGE_VERSION='1.3.2'
PACKAGE_STRING='gslnls 1.3.2'
PACKAGE_BUGREPORT='https://github.com/JorisChau/gslnls/issues/'
PACKAGE_URL=''

Expand Down Expand Up @@ -1231,7 +1231,7 @@ if test "$ac_init_help" = "long"; then
# Omit some internal or obsolete options to make the list less imposing.
# This message is too long to be a string in the A/UX 3.1 sh.
cat <<_ACEOF
\`configure' configures gslnls 1.3.1 to adapt to many kinds of systems.
\`configure' configures gslnls 1.3.2 to adapt to many kinds of systems.
Usage: $0 [OPTION]... [VAR=VALUE]...
Expand Down Expand Up @@ -1293,7 +1293,7 @@ fi

if test -n "$ac_init_help"; then
case $ac_init_help in
short | recursive ) echo "Configuration of gslnls 1.3.1:";;
short | recursive ) echo "Configuration of gslnls 1.3.2:";;
esac
cat <<\_ACEOF
Expand Down Expand Up @@ -1375,7 +1375,7 @@ fi
test -n "$ac_init_help" && exit $ac_status
if $ac_init_version; then
cat <<\_ACEOF
gslnls configure 1.3.1
gslnls configure 1.3.2
generated by GNU Autoconf 2.71
Copyright (C) 2021 Free Software Foundation, Inc.
Expand Down Expand Up @@ -1533,7 +1533,7 @@ cat >config.log <<_ACEOF
This file contains any messages produced by compilers while
running configure, to aid debugging if configure makes a mistake.
It was created by gslnls $as_me 1.3.1, which was
It was created by gslnls $as_me 1.3.2, which was
generated by GNU Autoconf 2.71. Invocation command line was
$ $0$ac_configure_args_raw
Expand Down Expand Up @@ -4066,7 +4066,7 @@ cat >>$CONFIG_STATUS <<\_ACEOF || ac_write_fail=1
# report actual input values of CONFIG_FILES etc. instead of their
# values after options handling.
ac_log="
This file was extended by gslnls $as_me 1.3.1, which was
This file was extended by gslnls $as_me 1.3.2, which was
generated by GNU Autoconf 2.71. Invocation command line was
CONFIG_FILES = $CONFIG_FILES
Expand Down Expand Up @@ -4121,7 +4121,7 @@ ac_cs_config_escaped=`printf "%s\n" "$ac_cs_config" | sed "s/^ //; s/'/'\\\\\\\\
cat >>$CONFIG_STATUS <<_ACEOF || ac_write_fail=1
ac_cs_config='$ac_cs_config_escaped'
ac_cs_version="\\
gslnls config.status 1.3.1
gslnls config.status 1.3.2
configured by $0, generated by GNU Autoconf 2.71,
with options \\"\$ac_cs_config\\"
Expand Down
2 changes: 1 addition & 1 deletion configure.ac
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@

AC_INIT([gslnls],[1.3.1],[https://github.com/JorisChau/gslnls/issues/])
AC_INIT([gslnls],[1.3.2],[https://github.com/JorisChau/gslnls/issues/])

: ${R_HOME=`R RHOME`}
if test -z "${R_HOME}"; then
Expand Down
47 changes: 0 additions & 47 deletions configure.win

This file was deleted.

5 changes: 3 additions & 2 deletions cran-comments.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
## CRAN package version 1.3.1
## CRAN package version 1.3.2

* System requirements: GSL (>= 2.2)

## Comments

* Edited configure.ac + configure to fix cran check errors (fedora builds)
* Removed configure.win + Makevars.win.in
* Added static Makevars.win as recommended by T. Kalibera

## Test environments

Expand Down
6 changes: 4 additions & 2 deletions inst/unit_tests/unit_tests_gslnls.R
Original file line number Diff line number Diff line change
Expand Up @@ -237,13 +237,13 @@ penalty_fit_dgT <- gsl_nls_large(
fn = function(theta) c(sqrt(1e-5) * (theta - 1), sum(theta^2) - 0.25),
y = rep(0, 11L),
start = rep(0.15, 10L),
jac = function(theta) as(rbind(diag(rep(sqrt(1e-5), length(theta))), 2 * t(theta)), Class = "dgTMatrix")
jac = function(theta) as(rbind(diag(rep(sqrt(1e-5), length(theta))), 2 * t(theta)), Class = "TsparseMatrix")
)
penalty_fit_dge <- gsl_nls_large(
fn = function(theta) c(sqrt(1e-5) * (theta - 1), sum(theta^2) - 0.25),
y = rep(0, 11L),
start = rep(0.15, 10L),
jac = function(theta) as(rbind(diag(rep(sqrt(1e-5), length(theta))), 2 * t(theta)), Class = "dgeMatrix")
jac = function(theta) as(rbind(diag(rep(sqrt(1e-5), length(theta))), 2 * t(theta)), Class = "unpackedMatrix")
)

dotest_tol("1.8.6", inherits(penalty_fit_dgC, "gsl_nls"), TRUE)
Expand Down Expand Up @@ -272,6 +272,7 @@ if(requireNamespace("MASS")) {
}
dotest("1.9.14", dim(confintd(misra1a_fit1, expr = "b1 + b2")), c(1L, 3L))
dotest("1.9.15", capture.output(misra1a_fit1)[c(1, 2)], c("Nonlinear regression model", " model: y ~ b1 * (1 - exp(-b2 * x))"))
dotest("1.9.16", length(hatvalues(misra1a_fit1)), 14L)

dotest("1.10.1", length(fitted(madsen_fit1)), 3L)
dotest("1.10.2", nobs(madsen_fit1), 3L)
Expand All @@ -290,5 +291,6 @@ dotest("1.10.12", names(anova(madsen_fit1, madsen_fit2)), c("Res.Df", "Res.Sum S
dotest("1.10.13", dim(confint(madsen_fit1, parm = c(1L, 2L))), c(2L, 2L))
dotest("1.10.14", dim(confintd(madsen_fit1, expr = quote(x1 - x2), dtype = "numeric")), c(1L, 3L))
dotest("1.10.15", capture.output(madsen_fit1)[c(1, 2)], c("Nonlinear regression model", " model: y ~ fn(x)"))
dotest("1.10.16", length(hatvalues(madsen_fit1)), 3L)

cat("Completed gslnls unit tests\n")
36 changes: 36 additions & 0 deletions man/hatvalues.gsl_nls.Rd

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

6 changes: 6 additions & 0 deletions src/Makevars.win
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# use pkg-config conditionally to support older versions of Rtools
ifeq (,$(shell pkg-config --version 2>/dev/null))
PKG_LIBS = -lgsl -lgslcblas -lm
else
PKG_LIBS = $(shell pkg-config --libs gsl)
endif
9 changes: 0 additions & 9 deletions src/Makevars.win.in

This file was deleted.

0 comments on commit 0500436

Please sign in to comment.