From ffdf092440c98e76067f65e7932be4dd73f6afb6 Mon Sep 17 00:00:00 2001 From: pedroguarderas Date: Tue, 30 Jan 2018 13:25:50 -0500 Subject: [PATCH] Reducing running time in examples. --- R/RcppExports.R | 42 +++++++--------------------------- man/Kanova.Rd | 29 +++-------------------- man/Krigvar.Rd | 8 +++---- man/integrate_kernel.Rd | 2 +- man/list_integrate_kernel.Rd | 2 +- man/vector_integrate_kernel.Rd | 2 +- src/krig_integral.h | 35 ++++------------------------ src/krig_sensitivity.h | 9 ++++---- 8 files changed, 27 insertions(+), 102 deletions(-) diff --git a/R/RcppExports.R b/R/RcppExports.R index 44e673a..a78bc71 100644 --- a/R/RcppExports.R +++ b/R/RcppExports.R @@ -41,7 +41,7 @@ weight_pow_dist <- function(x, y, w, p) { #' @param n Number of uniform division to compute the integral. #' @return Vector with integrals while the x coordinate is fixed. #' @author Pedro Guarderas \email{pedro.felipe.guarderas@@gmail.com}. -#' @seealso For a complete application you can check the documentation of \code{\link{Kanova}}. +#' @seealso For a complete application you can check the documentation of \code{\link{Krigvar}}. #' @export vector_integrate_kernel <- function(Kern, x, a, b, n) { .Call('_KRIG_vector_integrate_kernel', PACKAGE = 'KRIG', Kern, x, a, b, n) @@ -57,7 +57,7 @@ vector_integrate_kernel <- function(Kern, x, a, b, n) { #' @param n Number of uniform division to compute the integral. #' @return Real value with the integral value. #' @author Pedro Guarderas \email{pedro.felipe.guarderas@@gmail.com}. -#' @seealso For a complete application you can check the documentation of \code{\link{Kanova}}. +#' @seealso For a complete application you can check the documentation of \code{\link{Krigvar}}. #' @export integrate_kernel <- function(Kern, a, b, n) { .Call('_KRIG_integrate_kernel', PACKAGE = 'KRIG', Kern, a, b, n) @@ -78,7 +78,7 @@ integrate_kernel <- function(Kern, a, b, n) { #' be evaluated. #' @return List with one coordinate integrals and complete kernel integrals. #' @author Pedro Guarderas \email{pedro.felipe.guarderas@@gmail.com}. -#' @seealso For a complete application you can check the documentation of \code{\link{Kanova}}. +#' @seealso For a complete application you can check the documentation of \code{\link{Krigvar}}. #' @export list_integrate_kernel <- function(Kernels, X) { .Call('_KRIG_list_integrate_kernel', PACKAGE = 'KRIG', Kernels, X) @@ -102,35 +102,10 @@ list_integrate_kernel <- function(Kernels, X) { #' @return List with containing the Gamma 3D array where the different combination variance are #' stocked and the total matrix variance named Kanova. #' @author Pedro Guarderas \email{pedro.felipe.guarderas@@gmail.com}. -#' @examples -#' library( KRIG ) -#' options( stringsAsFactors = FALSE ) -#' -#' kernel_1<-function( x, y ) exp( -0.5*(x-y)^2) -#' kernel_2<-function( x, y ) exp( -0.7*(x-y)^2) -#' kernel_3<-function( x, y ) exp( -0.1*(x-y)^2) -#' -#' Kernels<-data.frame( kernel = c( 'kernel_1', 'kernel_2', 'kernel_3' ), -#' min = c( -1, -1, -5 ), -#' max = c( 1, 1, 5 ), -#' n = c( 500, 500, 500 ) ) -#' -#' n<-20 -#' X<-matrix( c( seq( -1, 1, length.out = n ), -#' seq( -1, 1, length.out = n ), -#' seq( -5, 5, length.out = n ) ), n, 3 ) -#' -#' KI<-list_integrate_kernel( Kernels, X ) -#' GK<-Kanova( Kernels, KI, X ) -#' -#' f<-function( x ) x[1] + 30 * x[2] + 60 * x[3] -#' Func<-apply( X, 1, FUN = f ) -#' -#' KF<-solve( GK$Kanova + diag( 1e-8, n, n ), Func ) +#' @seealso For a complete application you can check the documentation of \code{\link{Krigvar}}. #' @references #' \insertRef{Kanova:2013}{KRIG} #' \insertRef{Aronszajn:ThRK}{KRIG} -#' #' @export Kanova <- function(Kernels, Integral, X) { .Call('_KRIG_Kanova', PACKAGE = 'KRIG', Kernels, Integral, X) @@ -391,7 +366,6 @@ Krig <- function(Z, K, k, G, g, type = "ordinary", cinv = "syminv") { #' @references #' \insertRef{Kanova:2013}{KRIG} #' \insertRef{Aronszajn:ThRK}{KRIG} -#' #' @export Krigidx <- function(KF, comb, X, Gamma) { .Call('_KRIG_Krigidx', PACKAGE = 'KRIG', KF, comb, X, Gamma) @@ -412,14 +386,14 @@ Krigidx <- function(KF, comb, X, Gamma) { #' kernel_3<-function( x, y ) exp( -0.1*(x-y)^2) #' #' Kernels<-data.frame( kernel = c( 'kernel_1', 'kernel_2', 'kernel_3' ), -#' min = c( -1, -1, -5 ), -#' max = c( 1, 1, 5 ), -#' n = c( 500, 500, 500 ) ) +#' min = c( -1, -1, -2 ), +#' max = c( 1, 1, 2 ), +#' n = c( 100, 100, 100 ) ) #' #' n<-20 #' X<-matrix( c( seq( -1, 1, length.out = n ), #' seq( -1, 1, length.out = n ), -#' seq( -5, 5, length.out = n ) ), n, 3 ) +#' seq( -2, 2, length.out = n ) ), n, 3 ) #' #' KI<-list_integrate_kernel( Kernels, X ) #' GK<-Kanova( Kernels, KI, X ) diff --git a/man/Kanova.Rd b/man/Kanova.Rd index bb9df47..cbb7543 100644 --- a/man/Kanova.Rd +++ b/man/Kanova.Rd @@ -30,36 +30,13 @@ Under an approximation to the sensitivity analysis based in variance computation the different indexes of combinatorial sensitivity values can be computed employing the values of kernel integrals. } -\examples{ -library( KRIG ) -options( stringsAsFactors = FALSE ) - -kernel_1<-function( x, y ) exp( -0.5*(x-y)^2) -kernel_2<-function( x, y ) exp( -0.7*(x-y)^2) -kernel_3<-function( x, y ) exp( -0.1*(x-y)^2) - -Kernels<-data.frame( kernel = c( 'kernel_1', 'kernel_2', 'kernel_3' ), - min = c( -1, -1, -5 ), - max = c( 1, 1, 5 ), - n = c( 500, 500, 500 ) ) - -n<-20 -X<-matrix( c( seq( -1, 1, length.out = n ), - seq( -1, 1, length.out = n ), - seq( -5, 5, length.out = n ) ), n, 3 ) - -KI<-list_integrate_kernel( Kernels, X ) -GK<-Kanova( Kernels, KI, X ) - -f<-function( x ) x[1] + 30 * x[2] + 60 * x[3] -Func<-apply( X, 1, FUN = f ) - -KF<-solve( GK$Kanova + diag( 1e-8, n, n ), Func ) -} \references{ \insertRef{Kanova:2013}{KRIG} \insertRef{Aronszajn:ThRK}{KRIG} } +\seealso{ +For a complete application you can check the documentation of \code{\link{Krigvar}}. +} \author{ Pedro Guarderas \email{pedro.felipe.guarderas@gmail.com}. } diff --git a/man/Krigvar.Rd b/man/Krigvar.Rd index 7e237e8..5c1a34e 100644 --- a/man/Krigvar.Rd +++ b/man/Krigvar.Rd @@ -26,14 +26,14 @@ kernel_2<-function( x, y ) exp( -0.7*(x-y)^2) kernel_3<-function( x, y ) exp( -0.1*(x-y)^2) Kernels<-data.frame( kernel = c( 'kernel_1', 'kernel_2', 'kernel_3' ), - min = c( -1, -1, -5 ), - max = c( 1, 1, 5 ), - n = c( 500, 500, 500 ) ) + min = c( -1, -1, -2 ), + max = c( 1, 1, 2 ), + n = c( 100, 100, 100 ) ) n<-20 X<-matrix( c( seq( -1, 1, length.out = n ), seq( -1, 1, length.out = n ), - seq( -5, 5, length.out = n ) ), n, 3 ) + seq( -2, 2, length.out = n ) ), n, 3 ) KI<-list_integrate_kernel( Kernels, X ) GK<-Kanova( Kernels, KI, X ) diff --git a/man/integrate_kernel.Rd b/man/integrate_kernel.Rd index 0e8e233..b1cfefd 100644 --- a/man/integrate_kernel.Rd +++ b/man/integrate_kernel.Rd @@ -24,7 +24,7 @@ calculate the integral in both coordinate \eqn{x} and \eqn{y} of the kernel, ove domain give by the limits \eqn{a} and \eqn{b}. } \seealso{ -For a complete application you can check the documentation of \code{\link{Kanova}}. +For a complete application you can check the documentation of \code{\link{Krigvar}}. } \author{ Pedro Guarderas \email{pedro.felipe.guarderas@gmail.com}. diff --git a/man/list_integrate_kernel.Rd b/man/list_integrate_kernel.Rd index 65d6b25..39177b8 100644 --- a/man/list_integrate_kernel.Rd +++ b/man/list_integrate_kernel.Rd @@ -27,7 +27,7 @@ computes vector of integrals and complete integrals of kernels specified in the Kernels. } \seealso{ -For a complete application you can check the documentation of \code{\link{Kanova}}. +For a complete application you can check the documentation of \code{\link{Krigvar}}. } \author{ Pedro Guarderas \email{pedro.felipe.guarderas@gmail.com}. diff --git a/man/vector_integrate_kernel.Rd b/man/vector_integrate_kernel.Rd index 667437f..c03658c 100644 --- a/man/vector_integrate_kernel.Rd +++ b/man/vector_integrate_kernel.Rd @@ -27,7 +27,7 @@ variable \eqn{y}, is computed in the interval \eqn{a} to \eqn{b} by taking \eqn{ steps. } \seealso{ -For a complete application you can check the documentation of \code{\link{Kanova}}. +For a complete application you can check the documentation of \code{\link{Krigvar}}. } \author{ Pedro Guarderas \email{pedro.felipe.guarderas@gmail.com}. diff --git a/src/krig_integral.h b/src/krig_integral.h index fdd878a..1433baa 100644 --- a/src/krig_integral.h +++ b/src/krig_integral.h @@ -22,7 +22,7 @@ using namespace Rcpp; //' @param n Number of uniform division to compute the integral. //' @return Vector with integrals while the x coordinate is fixed. //' @author Pedro Guarderas \email{pedro.felipe.guarderas@@gmail.com}. -//' @seealso For a complete application you can check the documentation of \code{\link{Kanova}}. +//' @seealso For a complete application you can check the documentation of \code{\link{Krigvar}}. //' @export // [[Rcpp::export]] arma::colvec vector_integrate_kernel( Function Kern, const arma::colvec x, @@ -39,7 +39,7 @@ arma::colvec vector_integrate_kernel( Function Kern, const arma::colvec x, //' @param n Number of uniform division to compute the integral. //' @return Real value with the integral value. //' @author Pedro Guarderas \email{pedro.felipe.guarderas@@gmail.com}. -//' @seealso For a complete application you can check the documentation of \code{\link{Kanova}}. +//' @seealso For a complete application you can check the documentation of \code{\link{Krigvar}}. //' @export // [[Rcpp::export]] double integrate_kernel( Function Kern, const double& a, const double& b, const double& n ); @@ -60,7 +60,7 @@ double integrate_kernel( Function Kern, const double& a, const double& b, const //' be evaluated. //' @return List with one coordinate integrals and complete kernel integrals. //' @author Pedro Guarderas \email{pedro.felipe.guarderas@@gmail.com}. -//' @seealso For a complete application you can check the documentation of \code{\link{Kanova}}. +//' @seealso For a complete application you can check the documentation of \code{\link{Krigvar}}. //' @export // [[Rcpp::export]] List list_integrate_kernel( const DataFrame& Kernels, const arma::mat& X ); @@ -84,37 +84,12 @@ List list_integrate_kernel( const DataFrame& Kernels, const arma::mat& X ); //' @return List with containing the Gamma 3D array where the different combination variance are //' stocked and the total matrix variance named Kanova. //' @author Pedro Guarderas \email{pedro.felipe.guarderas@@gmail.com}. -//' @examples -//' library( KRIG ) -//' options( stringsAsFactors = FALSE ) -//' -//' kernel_1<-function( x, y ) exp( -0.5*(x-y)^2) -//' kernel_2<-function( x, y ) exp( -0.7*(x-y)^2) -//' kernel_3<-function( x, y ) exp( -0.1*(x-y)^2) -//' -//' Kernels<-data.frame( kernel = c( 'kernel_1', 'kernel_2', 'kernel_3' ), -//' min = c( -1, -1, -5 ), -//' max = c( 1, 1, 5 ), -//' n = c( 500, 500, 500 ) ) -//' -//' n<-20 -//' X<-matrix( c( seq( -1, 1, length.out = n ), -//' seq( -1, 1, length.out = n ), -//' seq( -5, 5, length.out = n ) ), n, 3 ) -//' -//' KI<-list_integrate_kernel( Kernels, X ) -//' GK<-Kanova( Kernels, KI, X ) -//' -//' f<-function( x ) x[1] + 30 * x[2] + 60 * x[3] -//' Func<-apply( X, 1, FUN = f ) -//' -//' KF<-solve( GK$Kanova + diag( 1e-8, n, n ), Func ) +//' @seealso For a complete application you can check the documentation of \code{\link{Krigvar}}. //' @references //' \insertRef{Kanova:2013}{KRIG} //' \insertRef{Aronszajn:ThRK}{KRIG} -//' //' @export // [[Rcpp::export]] List Kanova( const DataFrame& Kernels, const List& Integral, const arma::mat& X ); -#endif +#endif \ No newline at end of file diff --git a/src/krig_sensitivity.h b/src/krig_sensitivity.h index 8252a57..69c6e10 100644 --- a/src/krig_sensitivity.h +++ b/src/krig_sensitivity.h @@ -22,7 +22,6 @@ using namespace Rcpp; //' @references //' \insertRef{Kanova:2013}{KRIG} //' \insertRef{Aronszajn:ThRK}{KRIG} -//' //' @export // [[Rcpp::export]] double Krigidx( const arma::colvec KF, @@ -46,14 +45,14 @@ double Krigidx( const arma::colvec KF, //' kernel_3<-function( x, y ) exp( -0.1*(x-y)^2) //' //' Kernels<-data.frame( kernel = c( 'kernel_1', 'kernel_2', 'kernel_3' ), -//' min = c( -1, -1, -5 ), -//' max = c( 1, 1, 5 ), -//' n = c( 500, 500, 500 ) ) +//' min = c( -1, -1, -2 ), +//' max = c( 1, 1, 2 ), +//' n = c( 100, 100, 100 ) ) //' //' n<-20 //' X<-matrix( c( seq( -1, 1, length.out = n ), //' seq( -1, 1, length.out = n ), -//' seq( -5, 5, length.out = n ) ), n, 3 ) +//' seq( -2, 2, length.out = n ) ), n, 3 ) //' //' KI<-list_integrate_kernel( Kernels, X ) //' GK<-Kanova( Kernels, KI, X )