如何在“cv.SplitReg”函数(SplitReg 包)中为 c++ 函数设置“functionBody”?

问题描述 投票:0回答:0

我对 SplitReg 包很感兴趣,我想知道作者是如何在函数“cv.SplitReg”中开发他的方法的,更准确地说,我想要的函数是“Main_Ensemble_EN”。我是 R 的初学者,经过研究我找到了 Rcpp 包,但我无法在 Rcpp 中找到可以帮助我找到函数“Main_Ensemble_EN”内容的确切函数。 提前致谢。

functionBody(cv.SplitReg)
{
    if (all(!inherits(x, "matrix"), !inherits(x, "data.frame"))) {
        stop("x should belong to one of the following classes: matrix, data.frame")
    }
    else if (all(!inherits(y, "matrix"), all(!inherits(y, "numeric")))) {
        stop("y should belong to one of the following classes: matrix, numeric")
    }
    else if (any(anyNA(x), any(is.nan(x)), any(is.infinite(x)))) {
        stop("x should not have missing, infinite or nan values")
    }
    else if (any(anyNA(y), any(is.nan(y)), any(is.infinite(y)))) {
        stop("y should not have missing, infinite or nan values")
    }
    else {
        if (inherits(y, "matrix")) {
            if (ncol(y) > 1) {
                stop("y should be a vector")
            }
            y <- as.numeric(y)
        }
        len_y <- length(y)
        if (len_y != nrow(x)) {
            stop("y and x should have the same number of rows")
        }
    }
    if (!inherits(tolerance, "numeric")) {
        stop("tolerance should be numeric")
    }
    else if (!all(tolerance < 1, tolerance > 0)) {
        stop("tolerance should be between 0 and 1")
    }
    if (!inherits(alpha, "numeric")) {
        stop("alpha should be numeric")
    }
    else if (!all(alpha <= 1, alpha > 0)) {
        stop("alpha should be between 0 and 1")
    }
    if (!inherits(max_iter, "numeric")) {
        stop("max_iter should be numeric")
    }
    else if (any(!max_iter == floor(max_iter), max_iter <= 0)) {
        stop("max_iter should be a positive integer")
    }
    if (!inherits(num_models, "numeric")) {
        stop("num_models should be numeric")
    }
    else if (any(!num_models == floor(num_models), num_models <= 
        1)) {
        stop("num_models should be an integer, greater than one")
    }
    if (!inherits(num_lambdas_sparsity, "numeric")) {
        stop("num_lambdas_sparsity should be numeric")
    }
    else if (any(!num_lambdas_sparsity == floor(num_lambdas_sparsity), 
        num_lambdas_sparsity <= 0)) {
        stop("num_lambdas_sparsity should be a positive integer")
    }
    if (!inherits(num_lambdas_diversity, "numeric")) {
        stop("num_lambdas_diversity should be numeric")
    }
    else if (any(!num_lambdas_diversity == floor(num_lambdas_diversity), 
        num_lambdas_diversity <= 0)) {
        stop("num_lambdas_diversity should be a positive integer")
    }
    n <- nrow(x)
    random.permutation <- sample(1:n, n)
    x.permutation <- x[random.permutation, ]
    y.permutation <- y[random.permutation]
    output <- Main_Ensemble_EN(x.permutation, y.permutation, 
        num_lambdas_sparsity, num_lambdas_diversity, alpha, num_models, 
        tolerance, max_iter, num_folds, num_threads)
    fn_call <- match.call()
    output <- construct.cv.SplitReg(output, fn_call, x, y)
    return(output)
}

我尝试了 Rcpp 包并在 youtub 上观看了一些视频,但我找不到我需要的东西。

c++ rstudio rcpp r-package rcpparmadillo
© www.soinside.com 2019 - 2024. All rights reserved.