Title: | Fitting and Predicting Large-Scale Nonlinear Regression Problems using Multi-Resolution Functional ANOVA (MRFA) Approach |
---|---|
Description: | Performs the MRFA approach proposed by Sung et al. (2020) <doi:10.1080/01621459.2019.1595630> to fit and predict nonlinear regression problems, particularly for large-scale and high-dimensional problems. The application includes deterministic or stochastic computer experiments, spatial datasets, and so on. |
Authors: | Chih-Li Sung |
Maintainer: | Chih-Li Sung <[email protected]> |
License: | GPL-2 | GPL-3 |
Version: | 0.6 |
Built: | 2024-11-13 05:14:07 UTC |
Source: | https://github.com/cran/MRFA |
The function extracts Akaike information criterion (AIC) from a fitted MRFA model.
aic.MRFA(fit)
aic.MRFA(fit)
fit |
a class MRFA object estimated by |
a vector with length length(lambda)
returing AICs.
Chih-Li Sung <[email protected]>
predict.MRFA
for prediction of the MRFA model.
## Not run: ##### Testing function: GRAMACY & LEE (2009) function ##### ##### Thanks to Sonja Surjanovic and Derek Bingham, Simon Fraser University ##### grlee09 <- function(xx) { x1 <- xx[1] x2 <- xx[2] x3 <- xx[3] x4 <- xx[4] x5 <- xx[5] x6 <- xx[6] term1 <- exp(sin((0.9*(x1+0.48))^10)) term2 <- x2 * x3 term3 <- x4 y <- term1 + term2 + term3 return(y) } library(MRFA) ##### Training data and testing data ##### set.seed(2) n <- 100; n_rep <- 3; n_new <- 50; d <- 6 X.train <- matrix(runif(d*n), ncol = d) X.train <- matrix(rep(X.train, each = n_rep), ncol = d) Y.train <- apply(X.train, 1, grlee09) Y.train <- Y.train + rnorm(n*n_rep, 0, 0.05) X.test <- matrix(runif(d*n_new), ncol = d) Y.test <- apply(X.test, 1, grlee09) ##### Fitting ##### MRFA_model <- MRFA_fit(X.train, Y.train) print(aic.MRFA(MRFA_model)) print(bic.MRFA(MRFA_model)) ##### Prediction : AIC and BIC ###### lambda.aic <- MRFA_model$lambda[which.min(aic.MRFA(MRFA_model))] Y.pred <- predict(MRFA_model, X.test, lambda = lambda.aic)$y_hat print(sqrt(mean((Y.test - Y.pred)^2))) lambda.bic <- MRFA_model$lambda[which.min(bic.MRFA(MRFA_model))] Y.pred <- predict(MRFA_model, X.test, lambda = lambda.bic)$y_hat print(sqrt(mean((Y.test - Y.pred)^2))) ## End(Not run)
## Not run: ##### Testing function: GRAMACY & LEE (2009) function ##### ##### Thanks to Sonja Surjanovic and Derek Bingham, Simon Fraser University ##### grlee09 <- function(xx) { x1 <- xx[1] x2 <- xx[2] x3 <- xx[3] x4 <- xx[4] x5 <- xx[5] x6 <- xx[6] term1 <- exp(sin((0.9*(x1+0.48))^10)) term2 <- x2 * x3 term3 <- x4 y <- term1 + term2 + term3 return(y) } library(MRFA) ##### Training data and testing data ##### set.seed(2) n <- 100; n_rep <- 3; n_new <- 50; d <- 6 X.train <- matrix(runif(d*n), ncol = d) X.train <- matrix(rep(X.train, each = n_rep), ncol = d) Y.train <- apply(X.train, 1, grlee09) Y.train <- Y.train + rnorm(n*n_rep, 0, 0.05) X.test <- matrix(runif(d*n_new), ncol = d) Y.test <- apply(X.test, 1, grlee09) ##### Fitting ##### MRFA_model <- MRFA_fit(X.train, Y.train) print(aic.MRFA(MRFA_model)) print(bic.MRFA(MRFA_model)) ##### Prediction : AIC and BIC ###### lambda.aic <- MRFA_model$lambda[which.min(aic.MRFA(MRFA_model))] Y.pred <- predict(MRFA_model, X.test, lambda = lambda.aic)$y_hat print(sqrt(mean((Y.test - Y.pred)^2))) lambda.bic <- MRFA_model$lambda[which.min(bic.MRFA(MRFA_model))] Y.pred <- predict(MRFA_model, X.test, lambda = lambda.bic)$y_hat print(sqrt(mean((Y.test - Y.pred)^2))) ## End(Not run)
The function extracts Bayesian information criterion (BIC) from a fitted MRFA model.
bic.MRFA(fit)
bic.MRFA(fit)
fit |
a class MRFA object estimated by |
a vector with length length(lambda)
returing BICs.
Chih-Li Sung <[email protected]>
predict.MRFA
for prediction of the MRFA model.
## Not run: ##### Testing function: GRAMACY & LEE (2009) function ##### ##### Thanks to Sonja Surjanovic and Derek Bingham, Simon Fraser University ##### grlee09 <- function(xx) { x1 <- xx[1] x2 <- xx[2] x3 <- xx[3] x4 <- xx[4] x5 <- xx[5] x6 <- xx[6] term1 <- exp(sin((0.9*(x1+0.48))^10)) term2 <- x2 * x3 term3 <- x4 y <- term1 + term2 + term3 return(y) } library(MRFA) ##### Training data and testing data ##### set.seed(2) n <- 100; n_rep <- 3; n_new <- 50; d <- 6 X.train <- matrix(runif(d*n), ncol = d) X.train <- matrix(rep(X.train, each = n_rep), ncol = d) Y.train <- apply(X.train, 1, grlee09) Y.train <- Y.train + rnorm(n*n_rep, 0, 0.05) X.test <- matrix(runif(d*n_new), ncol = d) Y.test <- apply(X.test, 1, grlee09) ##### Fitting ##### MRFA_model <- MRFA_fit(X.train, Y.train) print(aic.MRFA(MRFA_model)) print(bic.MRFA(MRFA_model)) ##### Prediction : AIC and BIC ###### lambda.aic <- MRFA_model$lambda[which.min(aic.MRFA(MRFA_model))] Y.pred <- predict(MRFA_model, X.test, lambda = lambda.aic)$y_hat print(sqrt(mean((Y.test - Y.pred)^2))) lambda.bic <- MRFA_model$lambda[which.min(bic.MRFA(MRFA_model))] Y.pred <- predict(MRFA_model, X.test, lambda = lambda.bic)$y_hat print(sqrt(mean((Y.test - Y.pred)^2))) ## End(Not run)
## Not run: ##### Testing function: GRAMACY & LEE (2009) function ##### ##### Thanks to Sonja Surjanovic and Derek Bingham, Simon Fraser University ##### grlee09 <- function(xx) { x1 <- xx[1] x2 <- xx[2] x3 <- xx[3] x4 <- xx[4] x5 <- xx[5] x6 <- xx[6] term1 <- exp(sin((0.9*(x1+0.48))^10)) term2 <- x2 * x3 term3 <- x4 y <- term1 + term2 + term3 return(y) } library(MRFA) ##### Training data and testing data ##### set.seed(2) n <- 100; n_rep <- 3; n_new <- 50; d <- 6 X.train <- matrix(runif(d*n), ncol = d) X.train <- matrix(rep(X.train, each = n_rep), ncol = d) Y.train <- apply(X.train, 1, grlee09) Y.train <- Y.train + rnorm(n*n_rep, 0, 0.05) X.test <- matrix(runif(d*n_new), ncol = d) Y.test <- apply(X.test, 1, grlee09) ##### Fitting ##### MRFA_model <- MRFA_fit(X.train, Y.train) print(aic.MRFA(MRFA_model)) print(bic.MRFA(MRFA_model)) ##### Prediction : AIC and BIC ###### lambda.aic <- MRFA_model$lambda[which.min(aic.MRFA(MRFA_model))] Y.pred <- predict(MRFA_model, X.test, lambda = lambda.aic)$y_hat print(sqrt(mean((Y.test - Y.pred)^2))) lambda.bic <- MRFA_model$lambda[which.min(bic.MRFA(MRFA_model))] Y.pred <- predict(MRFA_model, X.test, lambda = lambda.bic)$y_hat print(sqrt(mean((Y.test - Y.pred)^2))) ## End(Not run)
The function computes the confidence intervals of predicted responses (only works for linear regression model).
confidence.MRFA( object, xnew, X, lambda = object$lambda, conf.level = 0.95, var.estimation = c("rss", "cv", "posthoc")[1], w.estimation = c("cv", "nugget")[1], K = 5, nugget = 1e-06, parallel = FALSE, verbose = FALSE )
confidence.MRFA( object, xnew, X, lambda = object$lambda, conf.level = 0.95, var.estimation = c("rss", "cv", "posthoc")[1], w.estimation = c("cv", "nugget")[1], K = 5, nugget = 1e-06, parallel = FALSE, verbose = FALSE )
object |
a class MRFA object estimated by |
xnew |
a testing matrix with dimension |
X |
input for |
lambda |
a value. The default is |
conf.level |
a value specifying confidence level of the confidence interval. The default is 0.95. |
var.estimation |
a character string specifying the estimation method for variance. "rss" specifies residual sum of squares, "cv" specifies a cross-validation method with |
w.estimation |
a character string specifying the estimation method for weights w. "cv" specifies a cross-validation method with |
K |
a positive integer specifying the number of folds. |
nugget |
a value specifying the nugget value for |
parallel |
logical. If |
verbose |
logical. If |
When The details about var.estimation
and w.estimation
can be seen in Sung et al. (2017+).
lower bound |
a vector with length |
upper bound |
a vector with length |
conf.level |
as above. |
Chih-Li Sung <[email protected]>
MRFA_fit
for fitting of a multi-resolution functional ANOVA model; predict.MRFA
for prediction of a multi-resolution functional ANOVA model.
## Not run: ##### Testing function: OTL circuit function ##### ##### Thanks to Sonja Surjanovic and Derek Bingham, Simon Fraser University ##### otlcircuit <- function(xx) { Rb1 <- 50 + xx[1] * 100 Rb2 <- 25 + xx[2] * 45 Rf <- 0.5 + xx[3] * 2.5 Rc1 <- 1.2 + xx[4] * 1.3 Rc2 <- 0.25 + xx[5] * 0.95 beta <- 50 + xx[6] * 250 Vb1 <- 12*Rb2 / (Rb1+Rb2) term1a <- (Vb1+0.74) * beta * (Rc2+9) term1b <- beta*(Rc2+9) + Rf term1 <- term1a / term1b term2a <- 11.35 * Rf term2b <- beta*(Rc2+9) + Rf term2 <- term2a / term2b term3a <- 0.74 * Rf * beta * (Rc2+9) term3b <- (beta*(Rc2+9)+Rf) * Rc1 term3 <- term3a / term3b Vm <- term1 + term2 + term3 return(Vm) } library(MRFA) ##### training data and testing data ############# set.seed(2) n <- 100; n_new <- 10; d <- 6 X.train <- matrix(runif(d*n), ncol = d) Y.train <- apply(X.train, 1, otlcircuit) X.test <- matrix(runif(d*n_new), ncol = d) Y.test <- apply(X.test, 1, otlcircuit) ##### Fitting ##### MRFA_model <- MRFA_fit(X.train, Y.train) ##### Prediction ###### Y.pred <- predict(MRFA_model, X.test, lambda = min(MRFA_model$lambda))$y_hat print(sqrt(mean((Y.test - Y.pred)^2))) ### confidence interval ### conf.interval <- confidence.MRFA(MRFA_model, X.test, X.train, lambda = min(MRFA_model$lambda)) print(conf.interval) ## End(Not run)
## Not run: ##### Testing function: OTL circuit function ##### ##### Thanks to Sonja Surjanovic and Derek Bingham, Simon Fraser University ##### otlcircuit <- function(xx) { Rb1 <- 50 + xx[1] * 100 Rb2 <- 25 + xx[2] * 45 Rf <- 0.5 + xx[3] * 2.5 Rc1 <- 1.2 + xx[4] * 1.3 Rc2 <- 0.25 + xx[5] * 0.95 beta <- 50 + xx[6] * 250 Vb1 <- 12*Rb2 / (Rb1+Rb2) term1a <- (Vb1+0.74) * beta * (Rc2+9) term1b <- beta*(Rc2+9) + Rf term1 <- term1a / term1b term2a <- 11.35 * Rf term2b <- beta*(Rc2+9) + Rf term2 <- term2a / term2b term3a <- 0.74 * Rf * beta * (Rc2+9) term3b <- (beta*(Rc2+9)+Rf) * Rc1 term3 <- term3a / term3b Vm <- term1 + term2 + term3 return(Vm) } library(MRFA) ##### training data and testing data ############# set.seed(2) n <- 100; n_new <- 10; d <- 6 X.train <- matrix(runif(d*n), ncol = d) Y.train <- apply(X.train, 1, otlcircuit) X.test <- matrix(runif(d*n_new), ncol = d) Y.test <- apply(X.test, 1, otlcircuit) ##### Fitting ##### MRFA_model <- MRFA_fit(X.train, Y.train) ##### Prediction ###### Y.pred <- predict(MRFA_model, X.test, lambda = min(MRFA_model$lambda))$y_hat print(sqrt(mean((Y.test - Y.pred)^2))) ### confidence interval ### conf.interval <- confidence.MRFA(MRFA_model, X.test, X.train, lambda = min(MRFA_model$lambda)) print(conf.interval) ## End(Not run)
Computes the K-fold cross validated mean squared prediction error for multiresolution functional ANOVA model.
cv.MRFA( X, Y, order = 10, level = 10, lambda = exp(seq(log(500), log(0.001), by = -0.01)), K = 10, plot.it = TRUE, parallel = FALSE, verbose = FALSE, ... )
cv.MRFA( X, Y, order = 10, level = 10, lambda = exp(seq(log(500), log(0.001), by = -0.01)), K = 10, plot.it = TRUE, parallel = FALSE, verbose = FALSE, ... )
X |
input for |
Y |
input for |
order |
input for |
level |
input for |
lambda |
lambda values at which CV curve should be computed. |
K |
a positive integer specifying the number of folds. |
plot.it |
logical. If |
parallel |
logical. If |
verbose |
logical. If |
... |
additional arguments to |
lambda |
lambda values at which CV curve is computed. |
cv |
the CV curve at each value of lambda. |
cv.error |
the standard error of the CV curve |
Chih-Li Sung <[email protected]>
MRFA_fit
for fitting a multiresolution functional ANOVA model.
## Not run: ##### Testing function: GRAMACY & LEE (2009) function ##### ##### Thanks to Sonja Surjanovic and Derek Bingham, Simon Fraser University ##### grlee09 <- function(xx) { x1 <- xx[1] x2 <- xx[2] x3 <- xx[3] x4 <- xx[4] x5 <- xx[5] x6 <- xx[6] term1 <- exp(sin((0.9*(x1+0.48))^10)) term2 <- x2 * x3 term3 <- x4 y <- term1 + term2 + term3 return(y) } library(MRFA) ##### Training data and testing data ##### set.seed(2) n <- 100; n_rep <- 3; n_new <- 50; d <- 6 X.train <- matrix(runif(d*n), ncol = d) X.train <- matrix(rep(X.train, each = n_rep), ncol = d) Y.train <- apply(X.train, 1, grlee09) Y.train <- Y.train + rnorm(n*n_rep, 0, 0.05) X.test <- matrix(runif(d*n_new), ncol = d) Y.test <- apply(X.test, 1, grlee09) ##### Fitting ##### MRFA_model <- MRFA_fit(X.train, Y.train) ##### Computes the K-fold cross validated ##### cv.out <- cv.MRFA(X.train, Y.train, K = 5, lambda = seq(0.01,3,0.1)) ##### Prediction : CV ###### lambda_cv <- cv.out$lambda[which.min(cv.out$cv)] Y.pred <- predict(MRFA_model, X.test, lambda = lambda_cv)$y_hat print(sqrt(mean((Y.test - Y.pred)^2))) ## End(Not run)
## Not run: ##### Testing function: GRAMACY & LEE (2009) function ##### ##### Thanks to Sonja Surjanovic and Derek Bingham, Simon Fraser University ##### grlee09 <- function(xx) { x1 <- xx[1] x2 <- xx[2] x3 <- xx[3] x4 <- xx[4] x5 <- xx[5] x6 <- xx[6] term1 <- exp(sin((0.9*(x1+0.48))^10)) term2 <- x2 * x3 term3 <- x4 y <- term1 + term2 + term3 return(y) } library(MRFA) ##### Training data and testing data ##### set.seed(2) n <- 100; n_rep <- 3; n_new <- 50; d <- 6 X.train <- matrix(runif(d*n), ncol = d) X.train <- matrix(rep(X.train, each = n_rep), ncol = d) Y.train <- apply(X.train, 1, grlee09) Y.train <- Y.train + rnorm(n*n_rep, 0, 0.05) X.test <- matrix(runif(d*n_new), ncol = d) Y.test <- apply(X.test, 1, grlee09) ##### Fitting ##### MRFA_model <- MRFA_fit(X.train, Y.train) ##### Computes the K-fold cross validated ##### cv.out <- cv.MRFA(X.train, Y.train, K = 5, lambda = seq(0.01,3,0.1)) ##### Prediction : CV ###### lambda_cv <- cv.out$lambda[which.min(cv.out$cv)] Y.pred <- predict(MRFA_model, X.test, lambda = lambda_cv)$y_hat print(sqrt(mean((Y.test - Y.pred)^2))) ## End(Not run)
The function performs the multi-resolution functional ANOVA (MRFA) approach.
MRFA_fit( X, Y, weights = rep(1, length(Y)), order = 10, level = 10, lambda.min = 1e-05, converge.tol = 1e-10, nvar.max = min(3 * length(Y), 3000), k = 2, pen.norm = c("2", "N")[1], model = LinReg(), standardize.d = TRUE, center = TRUE, standardize = TRUE, parallel = FALSE, verbose = TRUE )
MRFA_fit( X, Y, weights = rep(1, length(Y)), order = 10, level = 10, lambda.min = 1e-05, converge.tol = 1e-10, nvar.max = min(3 * length(Y), 3000), k = 2, pen.norm = c("2", "N")[1], model = LinReg(), standardize.d = TRUE, center = TRUE, standardize = TRUE, parallel = FALSE, verbose = TRUE )
X |
a design matrix with dimension |
Y |
a response vector of size |
weights |
a vector of observation weights. |
order |
a positive integer specifying the highest order of interactions that can be entertained in the model. The default is 10. |
level |
a positive integer specifying the highest resolution level that can be entertained in the model. The default is 10. |
lambda.min |
a positive value specifying the minimum penalty value to be performed before the convergence criterion is met. |
converge.tol |
convergence tolerance. It converges when relative difference with respect to function value (penalized likelihood) is smaller than the tolerance. The default is 1e-10. |
nvar.max |
maximum number of non-zero variables. |
k |
a positive integer specifying the order of Wendland covariance function. The default is 2. |
pen.norm |
a character string specifying the type of penalty norm for group lasso to be computed. "2" or 2 specifies 2-norm, and "N" specifies native norm. The default is "2". |
model |
an object of class specifying other models. |
standardize.d |
logical. If |
center |
logical. If |
standardize |
logical. If |
parallel |
logical. If |
verbose |
logical. If |
A multi-resolution functional ANOVA (MRFA) model targets a low resolution representation of a low order functional ANOVA, with respect to strong effect heredity, to form an accurate emulator in a large-scale and high dimensional problem. This function fits an MRFA model using a modified group lasso algrithm. One can consider the loss function
where is the basis function with resolution level
and with dimension
, and
and
respectively are the maximal orders of functional ANOVA and multi-resolution level, which are indicated by
order
and level
.
The group lasso path along the penalty parameter is given by the function, where the
is automatically given and
is given by users, which is indicated by
lambda.min
. The group lasso algrithm is implemented via the modifications to the source code of the grplasso
package (Meier, 2015).
lambda.min
, converge.tol
and nvar.max
are the options for stopping the fitting process. Smaller lambda.min
, or smaller converge.tol
, or larger nvar.max
yields more accurate results, paricularly for deterministic computer experiments. pen.norm
specifies the type of penalty norm in the loss function. model
specifies the response type, which can be non-continuous response, in the case the loss function is replaced by negative log-likelihood function. More details can be seen in Sung et al. (2017+).
An MRFA object is returned, for which aic.MRFA
, bic.MRFA
and predict
methods exist.
Chih-Li Sung <[email protected]>
predict.MRFA
for prediction of the MRFA model.
## Not run: ##### Testing function: OTL circuit function ##### ##### Thanks to Sonja Surjanovic and Derek Bingham, Simon Fraser University ##### otlcircuit <- function(xx) { Rb1 <- 50 + xx[1] * 100 Rb2 <- 25 + xx[2] * 45 Rf <- 0.5 + xx[3] * 2.5 Rc1 <- 1.2 + xx[4] * 1.3 Rc2 <- 0.25 + xx[5] * 0.95 beta <- 50 + xx[6] * 250 Vb1 <- 12*Rb2 / (Rb1+Rb2) term1a <- (Vb1+0.74) * beta * (Rc2+9) term1b <- beta*(Rc2+9) + Rf term1 <- term1a / term1b term2a <- 11.35 * Rf term2b <- beta*(Rc2+9) + Rf term2 <- term2a / term2b term3a <- 0.74 * Rf * beta * (Rc2+9) term3b <- (beta*(Rc2+9)+Rf) * Rc1 term3 <- term3a / term3b Vm <- term1 + term2 + term3 return(Vm) } library(MRFA) ##### Training data and testing data ##### set.seed(2) n <- 1000; n_new <- 100; d <- 6 X.train <- matrix(runif(d*n), ncol = d) Y.train <- apply(X.train, 1, otlcircuit) X.test <- matrix(runif(d*n_new), ncol = d) Y.test <- apply(X.test, 1, otlcircuit) ##### Fitting ##### MRFA_model <- MRFA_fit(X.train, Y.train, verbose = TRUE) ##### Prediction ###### Y.pred <- predict(MRFA_model, X.test, lambda = min(MRFA_model$lambda))$y_hat print(sqrt(mean((Y.test - Y.pred)^2))) ## End(Not run)
## Not run: ##### Testing function: OTL circuit function ##### ##### Thanks to Sonja Surjanovic and Derek Bingham, Simon Fraser University ##### otlcircuit <- function(xx) { Rb1 <- 50 + xx[1] * 100 Rb2 <- 25 + xx[2] * 45 Rf <- 0.5 + xx[3] * 2.5 Rc1 <- 1.2 + xx[4] * 1.3 Rc2 <- 0.25 + xx[5] * 0.95 beta <- 50 + xx[6] * 250 Vb1 <- 12*Rb2 / (Rb1+Rb2) term1a <- (Vb1+0.74) * beta * (Rc2+9) term1b <- beta*(Rc2+9) + Rf term1 <- term1a / term1b term2a <- 11.35 * Rf term2b <- beta*(Rc2+9) + Rf term2 <- term2a / term2b term3a <- 0.74 * Rf * beta * (Rc2+9) term3b <- (beta*(Rc2+9)+Rf) * Rc1 term3 <- term3a / term3b Vm <- term1 + term2 + term3 return(Vm) } library(MRFA) ##### Training data and testing data ##### set.seed(2) n <- 1000; n_new <- 100; d <- 6 X.train <- matrix(runif(d*n), ncol = d) Y.train <- apply(X.train, 1, otlcircuit) X.test <- matrix(runif(d*n_new), ncol = d) Y.test <- apply(X.test, 1, otlcircuit) ##### Fitting ##### MRFA_model <- MRFA_fit(X.train, Y.train, verbose = TRUE) ##### Prediction ###### Y.pred <- predict(MRFA_model, X.test, lambda = min(MRFA_model$lambda))$y_hat print(sqrt(mean((Y.test - Y.pred)^2))) ## End(Not run)
The function computes the predicted responses.
## S3 method for class 'MRFA' predict(object, xnew, lambda = object$lambda, parallel = FALSE, ...)
## S3 method for class 'MRFA' predict(object, xnew, lambda = object$lambda, parallel = FALSE, ...)
object |
a class MRFA object estimated by |
xnew |
a testing matrix with dimension |
lambda |
a value, or vector of values, indexing the path. The default is |
parallel |
logical. If |
... |
for compatibility with generic method |
lambda |
as above. |
coefficients |
coefficients with respect to the basis function value. |
y_hat |
a matrix with dimension |
Chih-Li Sung <[email protected]>
MRFA_fit
for fitting a multiresolution functional ANOVA model.
## Not run: ##### Testing function: OTL circuit function ##### ##### Thanks to Sonja Surjanovic and Derek Bingham, Simon Fraser University ##### otlcircuit <- function(xx) { Rb1 <- 50 + xx[1] * 100 Rb2 <- 25 + xx[2] * 45 Rf <- 0.5 + xx[3] * 2.5 Rc1 <- 1.2 + xx[4] * 1.3 Rc2 <- 0.25 + xx[5] * 0.95 beta <- 50 + xx[6] * 250 Vb1 <- 12*Rb2 / (Rb1+Rb2) term1a <- (Vb1+0.74) * beta * (Rc2+9) term1b <- beta*(Rc2+9) + Rf term1 <- term1a / term1b term2a <- 11.35 * Rf term2b <- beta*(Rc2+9) + Rf term2 <- term2a / term2b term3a <- 0.74 * Rf * beta * (Rc2+9) term3b <- (beta*(Rc2+9)+Rf) * Rc1 term3 <- term3a / term3b Vm <- term1 + term2 + term3 return(Vm) } library(MRFA) ##### Training data and testing data ##### set.seed(2) n <- 1000; n_new <- 100; d <- 6 X.train <- matrix(runif(d*n), ncol = d) Y.train <- apply(X.train, 1, otlcircuit) X.test <- matrix(runif(d*n_new), ncol = d) Y.test <- apply(X.test, 1, otlcircuit) ##### Fitting ##### MRFA_model <- MRFA_fit(X.train, Y.train, verbose = TRUE) ##### Prediction ###### Y.pred <- predict(MRFA_model, X.test, lambda = min(MRFA_model$lambda))$y_hat print(sqrt(mean((Y.test - Y.pred)^2))) ## End(Not run)
## Not run: ##### Testing function: OTL circuit function ##### ##### Thanks to Sonja Surjanovic and Derek Bingham, Simon Fraser University ##### otlcircuit <- function(xx) { Rb1 <- 50 + xx[1] * 100 Rb2 <- 25 + xx[2] * 45 Rf <- 0.5 + xx[3] * 2.5 Rc1 <- 1.2 + xx[4] * 1.3 Rc2 <- 0.25 + xx[5] * 0.95 beta <- 50 + xx[6] * 250 Vb1 <- 12*Rb2 / (Rb1+Rb2) term1a <- (Vb1+0.74) * beta * (Rc2+9) term1b <- beta*(Rc2+9) + Rf term1 <- term1a / term1b term2a <- 11.35 * Rf term2b <- beta*(Rc2+9) + Rf term2 <- term2a / term2b term3a <- 0.74 * Rf * beta * (Rc2+9) term3b <- (beta*(Rc2+9)+Rf) * Rc1 term3 <- term3a / term3b Vm <- term1 + term2 + term3 return(Vm) } library(MRFA) ##### Training data and testing data ##### set.seed(2) n <- 1000; n_new <- 100; d <- 6 X.train <- matrix(runif(d*n), ncol = d) Y.train <- apply(X.train, 1, otlcircuit) X.test <- matrix(runif(d*n_new), ncol = d) Y.test <- apply(X.test, 1, otlcircuit) ##### Fitting ##### MRFA_model <- MRFA_fit(X.train, Y.train, verbose = TRUE) ##### Prediction ###### Y.pred <- predict(MRFA_model, X.test, lambda = min(MRFA_model$lambda))$y_hat print(sqrt(mean((Y.test - Y.pred)^2))) ## End(Not run)