-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Maximilian Pichler
authored and
Maximilian Pichler
committed
Mar 30, 2020
1 parent
d36f3eb
commit f6f2625
Showing
11 changed files
with
294 additions
and
84 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,125 @@ | ||
#' linear | ||
#' | ||
#' create linear env covariates | ||
#' @param data matrix of environmental predictors | ||
#' @param formula formula object for predictors | ||
#' @param lambda lambda penality | ||
#' @param alpha weighting between LASSO and ridge | ||
#' @export | ||
linear = function(data = NULL, formula = NULL, lambda = 0.0, alpha = 0.5) { | ||
if(is.data.frame(data)) { | ||
|
||
if(!is.null(formula)){ | ||
mf = match.call() | ||
m = match("formula", names(mf)) | ||
formula = stats::as.formula(mf[m]$formula) | ||
X = stats::model.matrix(formula, data) | ||
} else { | ||
formula = stats::as.formula("~.") | ||
X = stats::model.matrix(formula, data) | ||
} | ||
|
||
} else { | ||
|
||
if(!is.null(formula)) { | ||
mf = match.call() | ||
m = match("formula", names(mf)) | ||
formula = stats::as.formula(mf[m]$formula) | ||
X = data.frame(data) | ||
X = stats::model.matrix(formula, X) | ||
} else { | ||
formula = stats::as.formula("~.") | ||
X = stats::model.matrix(formula,data.frame(data)) | ||
} | ||
} | ||
out = list() | ||
out$formula = formula | ||
out$X = X | ||
out$l1_coef = (1-alpha)*lambda | ||
out$l2_coef = alpha*lambda | ||
class(out) = "envLinear" | ||
return(out) | ||
} | ||
|
||
#' env DNN | ||
#' | ||
#' create deep neural network | ||
#' @param data matrix of environmental predictors | ||
#' @param formula formula object for predictors | ||
#' @param hidden hidden units in layers, length of hidden correspond to number of layers | ||
#' @param activation activation functions for layer, must be of same length as hidden | ||
#' @param lambda lambda penality | ||
#' @param alpha weighting between LASSO and ridge | ||
#' @export | ||
DNN = function(data = NULL, formula = NULL, hidden = c(10L, 10L, 10L), activation = "relu", lambda = 0.0, alpha = 0.5) { | ||
if(is.data.frame(data)) { | ||
|
||
if(!is.null(formula)){ | ||
mf = match.call() | ||
m = match("formula", names(mf)) | ||
formula = stats::as.formula(mf[m]$formula) | ||
X = stats::model.matrix(formula, data) | ||
} else { | ||
formula = stats::as.formula("~.") | ||
X = stats::model.matrix(formula, data) | ||
} | ||
|
||
} else { | ||
|
||
if(!is.null(formula)) { | ||
mf = match.call() | ||
m = match("formula", names(mf)) | ||
formula = stats::as.formula(mf[m]$formula) | ||
X = data.frame(data) | ||
X = stats::model.matrix(formula, X) | ||
} else { | ||
formula = stats::as.formula("~.") | ||
X = stats::model.matrix(formula,data.frame(data)) | ||
} | ||
} | ||
out = list() | ||
out$formula = formula | ||
out$X = X | ||
out$l1_coef = (1-alpha)*lambda | ||
out$l2_coef = alpha*lambda | ||
out$hidden = as.integer(hidden) | ||
if(length(activation) != activation) activation = rep(activation, length(hidden)) | ||
out$activation = activation | ||
class(out) = "envDNN" | ||
return(out) | ||
} | ||
|
||
#' biotic_struct | ||
#' | ||
#' define biotic interaction structur | ||
#' @param df degree of freedom for covariance parametrization, if \code{NULL} df is set to \code{ncol(Y)/2} | ||
#' @param link link function, probit, logit or linear | ||
#' @param lambda lambda penality | ||
#' @param alpha weighting between LASSO and ridge | ||
#' @param on_diag regularization on diagonals | ||
#' @export | ||
biotic_struct = function(df = NULL, lambda = 0.0, alpha = 0.5, on_diag = TRUE) { | ||
out = list() | ||
out$l1_cov = (1-alpha)*lambda | ||
out$l2_cov = alpha*lambda | ||
if(!is.null(df)) out$df = as.integer(df) | ||
out$on_diag = on_diag | ||
class(out) = "biotic" | ||
return(out) | ||
} | ||
|
||
|
||
|
||
#' spatial | ||
#' | ||
#' define spatial structure, not yet supported | ||
#' @export | ||
spatialXY = function() { | ||
out = list() | ||
class(out) = "spatialXY" | ||
return(out) | ||
} | ||
|
||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.