Skip to content

Commit

Permalink
Pull request #31: Fixed merge issues caused by linting. Fixed tests
Browse files Browse the repository at this point in the history
Merge in STAT/prestogp from master to to-git

Squashed commit of the following:

commit db6cd4f
Merge: 55607e2 7da2588
Author: Eric Bair <eric.bair@sciome.com>
Date:   Sat Jan 13 12:11:56 2024 -0500

    Pull request #29: Fixed some bugs caused by the linter

    Merge in STAT/prestogp from eb-dev to master

    * commit '7da2588abba4491c1ff490de95e834d00f5df88e':
      Fixed some bugs caused by the linter

commit 7da2588
Author: Eric Bair <eric.bair@sciome.com>
Date:   Sat Jan 13 01:37:58 2024 -0500

    Fixed some bugs caused by the linter

commit 55607e2
Merge: c7ed481 81b675d
Author: Shail Choksi <shail.choksi@sciome.com>
Date:   Fri Jan 12 19:37:55 2024 -0500

    Pull request #28: Final linting fixes

    Merge in STAT/prestogp from build-workflow to master

    * commit '81b675dda9b57f2a362c34876364adf5bcf45560':
      Fix remaining linting issues
      Fix all indentation errors
      Add indentation_linter configuration to lintr config file

commit 81b675d
Author: sciome-bot <software.tools@sciome.com>
Date:   Fri Jan 12 19:36:05 2024 -0500

    Fix remaining linting issues

commit 06673a4
Author: sciome-bot <software.tools@sciome.com>
Date:   Fri Jan 12 19:23:11 2024 -0500

    Fix all indentation errors

commit c7ed481
Merge: 723c3eb 7bcfa1a
Author: Shail Choksi <shail.choksi@sciome.com>
Date:   Fri Jan 12 19:02:59 2024 -0500

    Pull request #27: Lintr fixes. Added release and sanitizer actions

    Merge in STAT/prestogp from build-workflow to master

    * commit '7bcfa1aca78cc6b994cc0227c083357c58d50ca0': (21 commits)
      Add R_LINTR_LINTER_FILE to lint action to point to global .lintr file
      More lintr fixes for 1:length, 1:nrow and line length. Disabled object_length_linter
      WIP: Fix linter warnings for 1:nrow, 1:ncol and 1:length. Increase line length to 160 chars
      Don't build vignettes during the release action
      Move release action file to correct directory
      Add release action
      Reorder imports in RcppExports file
      Add missing dependency in Namespace/Description
      Remove unneeded exports from NAMESPACE
      Add missing comma in Imports section of DESCRIPTION
      Add missing comma in imports section of DESCRIPTION
      Rerun auto-formatter
      WIP - linting
      Add ignore rules for .lintr and .github for R build
      remove linter options from lint action as we have added .lintr project file. Fix all vector_logic_linter warnings
      Remove line length linter to see the remaining errors/warnings
      workaround for lintr bug: REditorSupport/languageserver#89
      Run auto-lint on vscode
      enable linting on build-workflow
      Add missing imports in DESCRIPTION
      ...

commit 29d82cd
Author: sciome-bot <software.tools@sciome.com>
Date:   Fri Jan 12 18:40:17 2024 -0500

    Add indentation_linter configuration to lintr config file

commit 7bcfa1a
Author: sciome-bot <software.tools@sciome.com>
Date:   Fri Jan 12 18:16:01 2024 -0500

    Add R_LINTR_LINTER_FILE to lint action to point to global .lintr file

commit b6df473
Author: sciome-bot <software.tools@sciome.com>
Date:   Fri Jan 12 17:54:50 2024 -0500

    More lintr fixes for 1:length, 1:nrow and line length. Disabled object_length_linter

commit 6f6f91d
Author: sciome-bot <software.tools@sciome.com>
Date:   Fri Jan 12 17:32:12 2024 -0500

    WIP: Fix linter warnings for 1:nrow, 1:ncol and 1:length. Increase line length to 160 chars

commit 2db2e19
Author: sciome-bot <software.tools@sciome.com>
Date:   Fri Jan 12 16:48:59 2024 -0500

    Don't build vignettes during the release action

commit c539223
Author: sciome-bot <software.tools@sciome.com>
Date:   Fri Jan 12 16:39:52 2024 -0500

    Move release action file to correct directory

commit f83df2b
Author: sciome-bot <software.tools@sciome.com>
Date:   Fri Jan 12 16:36:03 2024 -0500

    Add release action

commit c84e159
Author: sciome-bot <software.tools@sciome.com>
Date:   Fri Jan 12 16:04:36 2024 -0500

    Reorder imports in RcppExports file

commit 0460202
Merge: 245eaa3 43ae272
Author: sciome-bot <software.tools@sciome.com>
Date:   Fri Jan 12 15:48:30 2024 -0500

    Merge branch 'build-workflow' of sciome-bot-git:Spatiotemporal-Exposures-and-Toxicology/PrestoGP into build-workflow

commit 245eaa3
Merge: 5355e24 c060815
Author: sciome-bot <software.tools@sciome.com>
Date:   Fri Jan 12 15:47:42 2024 -0500

    Merge branch 'main' of sciome-bot-git:Spatiotemporal-Exposures-and-Toxicology/PrestoGP into build-workflow

commit c060815
Merge: 731da76 6d69b69
Author: {SET}group <127860447+Spatiotemporal-Exposures-and-Toxicology@users.noreply.github.com>
Date:   Thu Jan 11 16:02:52 2024 -0500

    Merge pull request #44 from Spatiotemporal-Exposures-and-Toxicology/main-sciome

    Sciome Update 1/10/2024

commit 6d69b69
Author: sciome-bot <software.tools@sciome.com>
Date:   Thu Jan 11 14:39:39 2024 -0500

    Add missing dependency in Namespace/Description

commit bdf52c6
Author: sciome-bot <software.tools@sciome.com>
Date:   Thu Jan 11 14:30:38 2024 -0500

    Remove unneeded exports from NAMESPACE

commit 06918b0
Author: sciome-bot <software.tools@sciome.com>
Date:   Thu Jan 11 14:15:45 2024 -0500

    Add missing comma in Imports section of DESCRIPTION

... and 13 more commits
  • Loading branch information
shail-choksi committed Jan 13, 2024
1 parent 723c3eb commit 9b10201
Show file tree
Hide file tree
Showing 40 changed files with 2,108 additions and 1,683 deletions.
3 changes: 2 additions & 1 deletion .Rbuildignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,5 @@
^\.Rproj\.user$
^doc$
^Meta$
^\.github/
^\.lintr
^\.github
6 changes: 3 additions & 3 deletions .github/workflows/lint.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# Need help debugging build failures? Start at https://github.com/r-lib/actions#where-to-find-help
on:
push:
branches: [main, master]
branches: [main, master, build-workflow]
pull_request:
branches: [main, master]

Expand All @@ -12,6 +12,7 @@ jobs:
lint:
runs-on: ubuntu-latest
env:
R_LINTR_LINTER_FILE: .lintr
GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }}
steps:
- uses: actions/checkout@v3
Expand All @@ -26,8 +27,7 @@ jobs:
needs: lint

- name: Lint
run: lintr::lint_package(linters = lintr::linters_with_defaults(object_name_linter = NULL,
commented_code_linter = NULL, cyclocomp_linter = NULL))
run: lintr::lint_package()
shell: Rscript {0}
env:
LINTR_ERROR_ON_LINT: true
109 changes: 109 additions & 0 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
# This workflow uses actions that are not certified by GitHub.
# They are provided by a third-party and are governed by
# separate terms of service, privacy policy, and support
# documentation.
#
# See https://github.com/r-lib/actions/tree/master/examples#readme for
# additional example workflows available for the R community.

name: Release New version

on:
push:
tags:
- '*'
branches: ["build-workflow"]
workflow_dispatch:

jobs:
create_release:
name: Create release
runs-on: ubuntu-latest
outputs:
upload_url: ${{ steps.create_release.outputs.upload_url }}
steps:
- name: Create release
id: create_release
uses: ncipollo/release-action@v1
with:
allowUpdates: true
build_upload_artefacts:
runs-on: ${{ matrix.config.os }}
name: ${{ matrix.config.os }} (${{ matrix.config.r }})
strategy:
fail-fast: false
matrix:
config:
- {os: windows-latest, r: 'release'}
- {os: ubuntu-latest, r: 'release'}
- {os: macos-latest, r: 'release'}
# - {os: windows-latest, r: '4.2'}
# - {os: ubuntu-latest, r: '4.2'}
# - {os: macos-latest, r: '4.2'}
env:
R_KEEP_PKG_SOURCE: yes
steps:
# see this for details: https://msmith.de/2020/03/12/r-cmd-check-github-actions.html
- name: Configure git
run: git config --global core.autocrlf false
- uses: actions/checkout@v3
- uses: r-lib/actions/setup-pandoc@v2
- uses: r-lib/actions/setup-tinytex@v2
- uses: r-lib/actions/setup-r@v2
- uses: r-lib/actions/setup-r-dependencies@v2
with:
cache-version: 2
extra-packages: |
any::ggplot2
any::rcmdcheck
any::roxygen2
needs: |
check
roxygen2
- name: Read VERSION file
if: runner.os != 'macOs'
id: getversion
shell: bash
run: |
echo "VERSION=$(cat DESCRIPTION | grep -Po '(?<=Version\:\s).*')" >> $GITHUB_OUTPUT
- name: Read VERSION file (macOS)
if: runner.os == 'macOs'
id: getversion_mac
run: |
echo "VERSION=$(sed -n 's/Version:[[:space:]]*//p' DESCRIPTION | tr -d '[:space:]')" >> $GITHUB_OUTPUT
- name: Build package (Windows)
if: runner.os == 'Windows'
shell: cmd
run: R CMD build --no-build-vignettes .
- name: Build package
if: runner.os == 'Linux' || runner.os == 'macOs'
run: R CMD build --no-build-vignettes .
- name: Test Install (Windows)
if: runner.os == 'Windows'
shell: cmd
run: R CMD INSTALL --build PrestoGP_${{ steps.getversion.outputs.VERSION }}.tar.gz
- name: Test Install (Linux)
if: runner.os == 'Linux'
run: R CMD INSTALL --build PrestoGP_${{ steps.getversion.outputs.VERSION }}.tar.gz
- name: Test Install (macOs)
if: runner.os == 'macOs'
run: R CMD INSTALL --build PrestoGP_${{ steps.getversion_mac.outputs.VERSION }}.tar.gz
- uses: svenstaro/upload-release-action@v2
if: runner.os == 'macOs'
with:
tag: ${{ github.ref }}
file: PrestoGP_${{ steps.getversion_mac.outputs.VERSION }}.tgz
asset_name: "PrestoGP_${{ steps.getversion_mac.outputs.VERSION }}-x86_64-macOs-R.${{ matrix.config.r }}.tgz"
- uses: svenstaro/upload-release-action@v2
if: runner.os == 'Linux'
with:
tag: ${{ github.ref }}
file: "PrestoGP_${{ steps.getversion.outputs.VERSION }}_R_x86_64-pc-linux-gnu.tar.gz"
asset_name: PrestoGP_${{ steps.getversion.outputs.VERSION }}-x86_64-linux-R.${{ matrix.config.r }}.zip
- uses: svenstaro/upload-release-action@v2
if: runner.os == 'Windows'
with:
tag: ${{ github.ref }}
file: PrestoGP_${{ steps.getversion.outputs.VERSION }}.zip
asset_name: PrestoGP_${{ steps.getversion.outputs.VERSION }}-windows-R.${{ matrix.config.r }}.zip

24 changes: 12 additions & 12 deletions .github/workflows/sanitizers.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -84,12 +84,12 @@ jobs:
run: rcmdcheck::rcmdcheck(build_args = "--no-build-vignettes", args = c("--no-codoc", "--no-examples", "--no-manual", "--ignore-vignettes"), error_on = "warning", check_dir = "check")
shell: Rscript {0}

- name: Upload check results
if: failure()
uses: actions/upload-artifact@v3
with:
name: ${{ runner.os }}-asan-rrelease-results
path: check
# - name: Upload check results
# if: failure()
# uses: actions/upload-artifact@v3
# with:
# name: ${{ runner.os }}-asan-rrelease-results
# path: check
sanitizer-check-usan:
runs-on: ubuntu-latest
env:
Expand Down Expand Up @@ -162,9 +162,9 @@ jobs:
run: rcmdcheck::rcmdcheck(build_args = "--no-build-vignettes", args = c("--no-codoc", "--no-examples", "--no-manual", "--ignore-vignettes"), error_on = "warning", check_dir = "check")
shell: Rscript {0}

- name: Upload check results
if: failure()
uses: actions/upload-artifact@v3
with:
name: ${{ runner.os }}-ubsan-rrelease-results
path: check
# - name: Upload check results
# if: failure()
# uses: actions/upload-artifact@v3
# with:
# name: ${{ runner.os }}-ubsan-rrelease-results
# path: check
13 changes: 13 additions & 0 deletions .lintr
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
linters: linters_with_defaults(
line_length_linter(160L),
commented_code_linter = NULL,
object_name_linter = NULL,
cyclocomp_linter = NULL,
object_length_linter = NULL,
indentation_linter(
indent = 2L,
hanging_indent_style = "never",
assignment_as_infix = FALSE
)
)
encoding: "UTF-8"
8 changes: 5 additions & 3 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Package: PrestoGP
Type: Package
Title: Penalized Regression for Spatio-Temporal Outcomes via Gaussian Processes
Version: 0.2.0.9021
Version: 0.2.0.9022
Authors@R: c(
person(given = "Eric",
family = "Bair",
Expand Down Expand Up @@ -45,8 +45,10 @@ Imports:
rlang,
mvtnorm,
spam,
psych
doParallel
psych,
doParallel,
covr,
mvtnorm
License: GPL-3
Encoding: UTF-8
VignetteBuilder: knitr
Expand Down
4 changes: 0 additions & 4 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,11 @@

export(":=")
export(.data)
export(FullSpatialModel)
export(FullModel)
export(Kr_pred)
export(MultivariateVecchiaModel)
export(PrestoGPModel)
export(ST_Krig_Param_Avg)
export(SpatialModel)
export(SpatiotemporalFullModel)
export(SpatiotemporalModel)
export(VecchiaModel)
export(as_label)
export(as_name)
Expand Down
59 changes: 32 additions & 27 deletions R/Log_Likelihood.R
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,21 @@
#'
#' @examples
#' @noRd
negloglik_vecchia_ST <- function(logparms, res, vecchia.approx, param.seq,
scaling, nscale) {
negloglik_vecchia_ST <- function(logparms, res, vecchia.approx, param.seq, scaling, nscale) {
parms <- unlog.params(logparms, param.seq, 1)
locs.scaled <- vecchia.approx$locsord
for (j in 1:nscale) {
locs.scaled[, scaling == j] <- locs.scaled[, scaling == j] /
parms[param.seq[2, 1] + j - 1]
}
vecchia.approx$locsord <- locs.scaled
-vecchia_likelihood(res, vecchia.approx, c(parms[1], 1,
parms[param.seq[3, 1]]),
parms[param.seq[4, 1]])
-vecchia_likelihood(
res, vecchia.approx, c(
parms[1], 1,
parms[param.seq[3, 1]]
),
parms[param.seq[4, 1]]
)
}

#' negloglik_vecchia
Expand All @@ -42,8 +45,10 @@ negloglik_vecchia_ST <- function(logparms, res, vecchia.approx, param.seq,
#' @noRd
negloglik_vecchia <- function(logparms, res, vecchia.approx, param.seq) {
parms <- unlog.params(logparms, param.seq, 1)
-vecchia_likelihood(res, vecchia.approx, c(parms[1], parms[2], parms[3]),
parms[4])
-vecchia_likelihood(
res, vecchia.approx, c(parms[1], parms[2], parms[3]),
parms[4]
)
}

#' negloglik_full_ST
Expand Down Expand Up @@ -95,8 +100,10 @@ negloglik.full <- function(logparams, d, y, param.seq) {
params <- unlog.params(logparams, param.seq, 1)
# d <- fields::rdist(locs)
N <- nrow(d)
cov.mat <- params[1] * fields::Matern(d, range = params[2],
smoothness = params[3]) +
cov.mat <- params[1] * fields::Matern(d,
range = params[2],
smoothness = params[3]
) +
params[4] * diag(N)
return(-1 * mvtnorm::dmvnorm(y, rep(0, N), cov.mat, log = TRUE))
}
Expand Down Expand Up @@ -133,8 +140,7 @@ mvnegloglik <- function(logparams, vecchia.approx, y, param.seq, P) {
##############################################################################
### Flexible Spatiotemporal Multivariate Matern Negative Loglikelihood Function ###########

mvnegloglik_ST <- function(logparams, vecchia.approx, y, param.seq, P, scaling,
nscale) {
mvnegloglik_ST <- function(logparams, vecchia.approx, y, param.seq, P, scaling, nscale) {
# Input-
# logparams: A numeric vector of length (4*P)+(4*choose(P,2)).
# To construct these parameters we unlist a list of the 7 covariance
Expand Down Expand Up @@ -227,8 +233,7 @@ mvnegloglik.full <- function(logparams, locs, y, param.seq) {
}

##############################################################################
create.cov.upper.flex <- function(P, marg.var, marg.range, marg.smooth,
nugget, R.corr) {
create.cov.upper.flex <- function(P, marg.var, marg.range, marg.smooth, nugget, R.corr) {
# Create the symmetrical marginal+cross-covariance flexible matern from the
# given parameters. Output is a list of the 4 Matern parameters as matrices
sig2.mat <- diag(marg.var, P, P)
Expand All @@ -237,20 +242,17 @@ create.cov.upper.flex <- function(P, marg.var, marg.range, marg.smooth,
nugget.mat <- diag(nugget, P, P)
if (P > 1) {
combs <- gtools::combinations(P, 2)
for (iter in 1:nrow(combs)) {
for (iter in seq_len(nrow(combs))) {
i <- combs[iter, 1]
j <- combs[iter, 2]

smoothness.mat[i, j] <- (marg.smooth[i] + marg.smooth[j]) / 2
range.mat[i, j] <- 1 / sqrt(((1 / marg.range[i])^2 +
(1 / marg.range[j])^2) / 2)
range.mat[i, j] <- 1 / sqrt(((1 / marg.range[i])^2 + (1 / marg.range[j])^2) / 2)

s1 <- sqrt(marg.var[i] * marg.var[j])
s2 <- ((1 / marg.range[i])^marg.smooth[i] *
(1 / marg.range[j])^marg.smooth[j]) /
s2 <- ((1 / marg.range[i])^marg.smooth[i] * (1 / marg.range[j])^marg.smooth[j]) /
((1 / range.mat[i, j])^(2 * smoothness.mat[i, j]))
s3 <- gamma(smoothness.mat[i, j]) / (sqrt(gamma(marg.smooth[i])) *
sqrt(gamma(marg.smooth[j])))
s3 <- gamma(smoothness.mat[i, j]) / (sqrt(gamma(marg.smooth[i])) * sqrt(gamma(marg.smooth[j])))
s4 <- R.corr[iter]
sig2.mat[i, j] <- s1 * s2 * s3 * s4
}
Expand Down Expand Up @@ -284,20 +286,24 @@ cat.covariances <- function(locs.list, sig2, range, smoothness, nugget) {

l <- length(locs.list)
combs <- gtools::combinations(l, 2, repeats.allowed = TRUE)
for (iter in 1:nrow(combs)) {
for (iter in seq_len(nrow(combs))) {
i <- combs[iter, 1]
j <- combs[iter, 2]
# d <- fields::rdist.earth(locs.list[[i]],locs.list[[j]],miles = FALSE)
d <- fields::rdist(locs.list[[i]], locs.list[[j]])
# Calculate the covariance matrix - if/then based on its location in the super-matrix
N <- nrow(d)
if (i == j) { # To accomodate varying size outcomes- the nugget is not included on cross-covariances
cov.mat.ij <- sig2[i, j] * geoR::matern(d, phi = range[i, j], kappa =
smoothness[i, j]) +
cov.mat.ij <- sig2[i, j] * geoR::matern(d,
phi = range[i, j], kappa =
smoothness[i, j]
) +
nugget[i, j] * diag(N)
} else {
cov.mat.ij <- sig2[i, j] * geoR::matern(d, phi = range[i, j], kappa =
smoothness[i, j])
cov.mat.ij <- sig2[i, j] * geoR::matern(d,
phi = range[i, j], kappa =
smoothness[i, j]
)
}


Expand Down Expand Up @@ -328,8 +334,7 @@ cat.covariances <- function(locs.list, sig2, range, smoothness, nugget) {
##############################################################################
### Create the likelihood initial values #########

create.initial.values.flex <- function(marg.var, marg.range, marg.smooth,
nugget, R.corr, P) {
create.initial.values.flex <- function(marg.var, marg.range, marg.smooth, nugget, R.corr, P) {
# Log-transform the covariance parameters and arrange in the proper order
# for the likelihood function
logparams.init <- c(
Expand Down
Loading

0 comments on commit 9b10201

Please sign in to comment.