Skip to content

Commit

Permalink
R 3.6 unit test compatibility fix, lintR formatting update and minor …
Browse files Browse the repository at this point in the history
…clean-ups
  • Loading branch information
Thorsten Rehberg committed Apr 29, 2019
1 parent f795032 commit 776dde6
Show file tree
Hide file tree
Showing 37 changed files with 1,151 additions and 896 deletions.
24 changes: 24 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
dist: xenial
matrix:
include:
- language: r
r:
- release
install:
- mkdir ~/.R
- R -e 'install.packages(c("kntir", "rmarkdown", "testthat"), repos = "http://cran.rstudio.com")'
- echo "CXX11=g++-7" > ~/.R/Makevars
- R CMD build dgemmR
- R CMD INSTALL *tar.gz
script:
- R CMD check *tar.gz

addons:
apt:
sources:
- ubuntu-toolchain-r-test
packages:
- libopenblas-base libopenblas-dev gcc-7 g++-7 gfortran-7

notifications:
email: false
8 changes: 5 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
[![Build Status](https://travis-ci.com/rehbergT/zeroSum.svg?branch=master)](https://travis-ci.com/rehbergT/zeroSum)

## News: Version 2.0
* Improved support for multinomial logistic and Cox proportional hazards regression.
* Improved performance (runtime avx detection and multithreading support now also available for macOS).
Expand Down Expand Up @@ -84,13 +86,13 @@ with or without the zero-sum constraint can be easily compared.
A binary package (*.zip) is available, which can be installed in R
using:

install.packages("https://github.com/rehbergT/zeroSum/raw/master/zeroSum_2.0.2.zip", repos = NULL)
install.packages("https://github.com/rehbergT/zeroSum/raw/master/zeroSum_2.0.3.zip", repos = NULL)


## Linux and macOS
The source package (*.tar.gz) can be installed in R using:

install.packages("https://github.com/rehbergT/zeroSum/raw/master/zeroSum_2.0.2.tar.gz", repos = NULL)
install.packages("https://github.com/rehbergT/zeroSum/raw/master/zeroSum_2.0.3.tar.gz", repos = NULL)


## Devtools
Expand All @@ -103,7 +105,7 @@ Git clone or download this repository and open a terminal within the zeroSum fol
The source package can be build and installed with:

R CMD build zeroSum
R CMD INSTALL zeroSum_2.0.2.tar.gz
R CMD INSTALL zeroSum_2.0.3.tar.gz


# Quick start
Expand Down
4 changes: 2 additions & 2 deletions zeroSum/DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ Description: Regressions functions for creating linear models with the
elastic-net regularization and the zero-sum constraint (sum of
coefficients = 0). The usage of this package is very similar to
that of the "glmnet" package.
Version: 2.0.2
Date: 2019-02-06
Version: 2.0.3
Date: 2019-04-29
Author: Thorsten Rehberg, Michael Altenbuchinger
Maintainer: Thorsten Rehberg <thorsten.rehberg@ur.de>
Imports:
Expand Down
7 changes: 3 additions & 4 deletions zeroSum/R/coef.R
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,10 @@
#'
#' @examples
#' set.seed(1)
#' x <- log2(exampleData$x+1)
#' x <- log2(exampleData$x + 1)
#' y <- exampleData$y
#' fit <- zeroSum( x, y, alpha=1)
#' coef(fit, s="lambda.min")
#'
#' fit <- zeroSum(x, y, alpha = 1)
#' coef(fit, s = "lambda.min")
#' @importFrom stats coef
#'
#' @export
Expand Down
31 changes: 15 additions & 16 deletions zeroSum/R/costFunction.R
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
#' Description of costFunction function
#'
#' @keywords internal
costFunction <- function(data, useC=FALSE) {
costFunction <- function(data, useC = FALSE) {
out <- list()
x <- data$x
N <- nrow(x)
y <- data$y
x <- data$x
N <- nrow(x)
y <- data$y
beta <- data$beta
weights <- data$w
penalty.factor <- data$v
Expand All @@ -15,28 +15,26 @@ costFunction <- function(data, useC=FALSE) {
xtb <- x %*% beta[-1, ] + beta[1, ]

## calculation of the residual sum of squares
res <- y - xtb
out$loglikelihood <- -as.numeric(weights %*% (res ^ 2)) / 2

res <- y - xtb
out$loglikelihood <- -as.numeric(weights %*% (res^2)) / 2
} else if (data$type == zeroSumTypes[2, 2]) {
xtb <- x %*% beta[-1, ] + beta[1, ]

## calculation of the loglikelihood
expXB <- log1p(exp(xtb))
out$loglikelihood <- as.numeric(weights %*% (y * xtb - expXB))

} else if (data$type == zeroSumTypes[3, 2]) {
xb <- x %*% beta[-1, ]
for (i in 1:ncol(beta)) {
xb[, i] <- xb[, i] + rep(beta[1, i], N)
xb[, i] <- xb[, i] + rep(beta[1, i], N)
}

xby <- rowSums(xb * y)
a <- max(xb)
xb <- xb - a
out$loglikelihood <- as.numeric(weights %*%
(xby - log(rowSums(exp(xb))) - a))
} else if (data$type == zeroSumTypes[4, 2]) {
(xby - log(rowSums(exp(xb))) - a))
} else if (data$type == zeroSumTypes[4, 2]) {
y <- cbind(data$y, data$status)
y <- cbind(y, duplicated(y[, 1] + y[, 2]))
d <- rep(0, N)
Expand All @@ -52,8 +50,9 @@ costFunction <- function(data, useC=FALSE) {
k <- j + 1
## search for duplicates (ties) and add the weights
while (k <= N && y[k, 3] == 1) {
if (y[k, 2] == 1)
if (y[k, 2] == 1) {
d[j] <- d[j] + weights[k]
}
k <- k + 1
}
j <- k
Expand All @@ -74,22 +73,22 @@ costFunction <- function(data, useC=FALSE) {

## calculation of the ridge penalty (the intercept is not penalized
## therefore the first beta is excluded)
out$ridge <- sum(t((beta[-1, , drop = FALSE]) ^ 2) %*% penalty.factor)
out$ridge <- sum(t((beta[-1, , drop = FALSE])^2) %*% penalty.factor)

## calculation of the lasso penalty (the intercept is not penalized
## therefore the first beta is excluded)
out$lasso <- sum(t(abs(beta[-1, , drop = FALSE])) %*% penalty.factor)
out$lasso <- sum(t(abs(beta[-1, , drop = FALSE])) %*% penalty.factor)

## calculation of the cost function
out$cost <- -out$loglikelihood + data$lambda *
((1 - data$alpha) * out$ridge / 2 + data$alpha * out$lasso)
((1 - data$alpha) * out$ridge / 2 + data$alpha * out$lasso)

out$fusion <- 0
if (data$useFusion) {
out$fusion <- 0.0
for (i in 1:ncol(data$beta)) {
out$fusion <- out$fusion + sum(abs(as.numeric(data$fusion %*%
data$beta[-1, i])))
data$beta[-1, i])))
}
out$cost <- out$cost + data$gamma * out$fusion
}
Expand Down
Loading

0 comments on commit 776dde6

Please sign in to comment.